Skip to content

Instantly share code, notes, and snippets.

@wellle
Last active May 10, 2023 02:36

Revisions

  1. wellle revised this gist Jan 26, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion yank.vim
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ function! MarkYankAndJump()
    endfunction

    function! YankAndJumpBack(type, ...)
    if a:0 " Invoked from Visual mode, use '< and '> marks.
    if a:0
    silent exe "normal! `<" . a:type . "`>y"
    elseif a:type == 'line'
    silent exe "normal! '[V']y"
  2. wellle revised this gist Jan 26, 2014. 1 changed file with 22 additions and 20 deletions.
    42 changes: 22 additions & 20 deletions yank.vim
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,25 @@
    nmap <silent> <F4> :set opfunc=CountSpaces<CR>g@
    vmap <silent> <F4> :<C-U>call CountSpaces(visualmode(), 1)<CR>
    nnoremap <silent> y :<C-U>call MarkAndSetOpfunc()<CR>g@
    vnoremap <silent> y :<C-U>call MarkYankAndJump()<CR>
    function! CountSpaces(type, ...)
    let sel_save = &selection
    let &selection = "inclusive"
    let reg_save = @@
    function! MarkAndSetOpfunc()
    let g:save_cursor = getpos(".")
    set opfunc=YankAndJumpBack
    endfunction

    if a:0
    silent exe "normal! `<" . a:type . "`>y"
    elseif a:type == 'line'
    silent exe "normal! '[V']y"
    elseif a:type == 'block'
    silent exe "normal! `[\<C-V>`]y"
    else
    silent exe "normal! `[v`]y"
    endif
    function! MarkYankAndJump()
    let g:save_cursor = getpos(".")
    call YankAndJumpBack(visualmode(), 1)
    endfunction

    echomsg strlen(substitute(@@, '[^ ]', '', 'g'))

    let &selection = sel_save
    let @@ = reg_save
    endfunction
    function! YankAndJumpBack(type, ...)
    if a:0 " Invoked from Visual mode, use '< and '> marks.
    silent exe "normal! `<" . a:type . "`>y"
    elseif a:type == 'line'
    silent exe "normal! '[V']y"
    elseif a:type == 'block'
    silent exe "normal! `[\<C-V>`]y"
    else
    silent exe "normal! `[v`]y"
    endif
    call setpos('.', g:save_cursor)
    endfunction
  3. wellle revised this gist Jan 26, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion yank.vim
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    let &selection = "inclusive"
    let reg_save = @@

    if a:0 " Invoked from Visual mode, use '< and '> marks.
    if a:0
    silent exe "normal! `<" . a:type . "`>y"
    elseif a:type == 'line'
    silent exe "normal! '[V']y"
  4. wellle created this gist Jan 26, 2014.
    23 changes: 23 additions & 0 deletions yank.vim
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    nmap <silent> <F4> :set opfunc=CountSpaces<CR>g@
    vmap <silent> <F4> :<C-U>call CountSpaces(visualmode(), 1)<CR>
    function! CountSpaces(type, ...)
    let sel_save = &selection
    let &selection = "inclusive"
    let reg_save = @@

    if a:0 " Invoked from Visual mode, use '< and '> marks.
    silent exe "normal! `<" . a:type . "`>y"
    elseif a:type == 'line'
    silent exe "normal! '[V']y"
    elseif a:type == 'block'
    silent exe "normal! `[\<C-V>`]y"
    else
    silent exe "normal! `[v`]y"
    endif

    echomsg strlen(substitute(@@, '[^ ]', '', 'g'))

    let &selection = sel_save
    let @@ = reg_save
    endfunction