-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 726a74e
Showing
18 changed files
with
2,366 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
MIT License | ||
|
||
Copyright (c) 2015 haya14busa | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR | ||
THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
:flashlight: vim-operator-flashy: Highlight yanked area | ||
======================================================= | ||
|
||
[](https://github.com/haya14busa/vim-operator-flashy/releases) | ||
[](https://github.com/haya14busa/vim-operator-flashy/issues) | ||
[](LICENSE) | ||
[](doc/operator-flashy.txt) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
:flashlight: Introduction :flashlight: | ||
-------------------------------------- | ||
|
||
Flush yanked area :flashlight: | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
TODO: gif | ||
|
||
You can confirm that text is yanked correctly and see yanked text by highlighting. | ||
|
||
|
||
:tada: Usage :tada: | ||
------------------- | ||
|
||
```vim | ||
map y <Plug>(operator-flashy) | ||
nmap Y <Plug>(operator-flashy)$ | ||
``` | ||
|
||
:bird: Author :bird: | ||
-------------------- | ||
haya14busa (https://github.com/haya14busa) | ||
|
||
:orange_book: Documentation :orange_book: | ||
----------------------------------------- | ||
|
||
[**:h operator-flashy.txt**](./doc/operator-flashy.txt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
"============================================================================= | ||
" FILE: autoload/operator/flashy.vim | ||
" AUTHOR: haya14busa | ||
" License: MIT license | ||
"============================================================================= | ||
scriptencoding utf-8 | ||
let s:save_cpo = &cpo | ||
set cpo&vim | ||
|
||
let s:V = vital#of('operator_flashy') | ||
let s:Highlight = s:V.import('Coaster.Highlight') | ||
let s:Search = s:V.import('Coaster.Search') | ||
|
||
let g:operator#flashy#group = get(g:, 'operator#flashy#group', 'Flashy') | ||
let g:operator#flashy#flash_time = get(g:, 'operator#flashy#flash_time', 100) | ||
|
||
function! s:init_hl() abort | ||
highlight Flashy term=bold ctermbg=0 guibg=#13354A | ||
endfunction | ||
|
||
call s:init_hl() | ||
|
||
augroup plugin-flashy-highlight | ||
autocmd! | ||
autocmd ColorScheme * call s:init_hl() | ||
augroup END | ||
|
||
" operator#flashy#do() yanks text with flash in normal mode. | ||
" It doesn't provie mapping for visual mode and doesn't support 'block' wise. | ||
" @param {'char'|'line'|'block'} wise | ||
function! operator#flashy#do(wise) abort | ||
if s:is_empty_region() | ||
return | ||
endif | ||
|
||
" Save cursor position for linewise motion like 'yj'. | ||
if a:wise is# 'line' | ||
let w = winsaveview() | ||
endif | ||
|
||
let visual_command = operator#user#visual_command_from_wise_name(a:wise) | ||
let pattern = s:Search.pattern_by_range(visual_command, getpos("'[")[1:], getpos("']")[1:]) | ||
call s:flash(pattern) | ||
call s:yank(visual_command) | ||
|
||
" Restore cursor position for linewise motion like 'yj'. | ||
if a:wise is# 'line' | ||
call winrestview(w) | ||
endif | ||
endfunction | ||
|
||
" o_y() keeps cursor position for linewise motion like 'yy'. | ||
" Example: | ||
" onoremap <expr> y operator#flashy#o_y() | ||
function! operator#flashy#o_y() abort | ||
let save_cursor = getcurpos() | ||
let rest_cursor = ":call setpos('.'," . string(save_cursor) . ")\<CR>" | ||
return "\<Esc>\"" . operator#user#register() . v:count . 'g@g@' . rest_cursor | ||
endfunction | ||
|
||
function! s:flash(pattern) abort | ||
call s:Highlight.highlight('YankRegion', g:operator#flashy#group, a:pattern, 10) | ||
redraw | ||
call s:sleep(g:operator#flashy#flash_time) | ||
call s:clear() | ||
endfunction | ||
|
||
function! s:sleep(ms) abort | ||
execute 'sleep' g:operator#flashy#flash_time . 'ms' | ||
endfunction | ||
|
||
function! s:clear() abort | ||
call s:Highlight.clear('YankRegion') | ||
endfunction | ||
|
||
function! s:yank(visual_command) abort | ||
let original_selection = &g:selection | ||
let &g:selection = 'inclusive' | ||
let reg = operator#user#register() | ||
execute 'normal!' '`[' . a:visual_command . '`]"' . reg . 'y' | ||
let &g:selection = original_selection | ||
endfunction | ||
|
||
" :h cpo-E | ||
function! s:is_empty_region() abort | ||
return line("'[") is# line("']") + 1 | ||
endfunction | ||
|
||
let &cpo = s:save_cpo | ||
unlet s:save_cpo | ||
" __END__ | ||
" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function! vital#of(name) abort | ||
let files = globpath(&runtimepath, 'autoload/vital/' . a:name . '.vital') | ||
let file = split(files, "\n") | ||
if empty(file) | ||
throw 'vital: version file not found: ' . a:name | ||
endif | ||
let ver = readfile(file[0], 'b') | ||
if empty(ver) | ||
throw 'vital: invalid version file: ' . a:name | ||
endif | ||
return vital#_{substitute(ver[0], '\W', '', 'g')}#new() | ||
endfunction |
Oops, something went wrong.
operator-flashy?