Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
haya14busa committed Dec 30, 2015
0 parents commit 726a74e
Show file tree
Hide file tree
Showing 18 changed files with 2,366 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LICENSE
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.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
:flashlight: vim-operator-flashy: Highlight yanked area
=======================================================

[![](http://img.shields.io/github/tag/haya14busa/vim-operator-flashy.svg)](https://github.com/haya14busa/vim-operator-flashy/releases)
[![](http://img.shields.io/github/issues/haya14busa/vim-operator-flashy.svg)](https://github.com/haya14busa/vim-operator-flashy/issues)
[![](http://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![](http://img.shields.io/badge/doc-%3Ah%20incsearch.txt-red.svg)](doc/operator-flashy.txt)

This comment has been minimized.

Copy link
@syngan

syngan Dec 31, 2015

operator-flashy?

This comment has been minimized.

Copy link
@haya14busa

haya14busa Dec 31, 2015

Author Owner

Thanks!!! 👍


:flashlight: Introduction :flashlight:
--------------------------------------

Flush yanked area :flashlight:

This comment has been minimized.

Copy link
@syngan

syngan Dec 31, 2015

Flash?


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)
92 changes: 92 additions & 0 deletions autoload/operator/flashy.vim
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
12 changes: 12 additions & 0 deletions autoload/vital.vim
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
Loading

0 comments on commit 726a74e

Please sign in to comment.