Skip to content

Commit

Permalink
Fixed issue with v:register usage.
Browse files Browse the repository at this point in the history
Turns out that `v:register` needs to be evaluated further upstream.
  • Loading branch information
jeetsukumaran committed Mar 13, 2015
1 parent d55706a commit 0b7474c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions plugin/commentary.vim
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,35 @@ function! s:textobject(inner) abort
endif
endfunction

function! s:setcommentaryreg(reg)
let s:targetreg = a:reg
endfunction
function! s:yankandcomment(type,...)
" only linewise operations make sense (to me, at least)
" so I am ignoring `type`
if a:0
let [mark1, mark2] = [a:type, a:1]
let reg = a:2
else
let [mark1, mark2] = ["'[", "']"]
let reg = get(s:, "targetreg", '"')
endif
execute 'normal! ' . mark1 . '"' . v:register . 'y' . mark2 . ']'
execute 'normal! ' . mark1 . '"' . reg . 'y' . mark2 . ']'
call <SID>go(line(mark1),line(mark2))
execute 'normal! ' . mark1
endfunction

xnoremap <silent> <Plug>Commentary :<C-U>call <SID>go(line("'<"),line("'>"))<CR>
nnoremap <silent> <Plug>Commentary :<C-U>set opfunc=<SID>go<CR>g@
nnoremap <silent> <Plug>CommentaryLine :<C-U>set opfunc=<SID>go<Bar>exe 'norm! 'v:count1.'g@_'<CR>
onoremap <silent> <Plug>Commentary :<C-U>call <SID>textobject(0)<CR>
nnoremap <silent> <Plug>ChangeCommentary c:<C-U>call <SID>textobject(1)<CR>
nmap <silent> <Plug>CommentaryUndo <Plug>Commentary<Plug>Commentary
command! -range -bar Commentary call s:go(<line1>,<line2>)

xnoremap <silent> <Plug>CommentaryYank :<C-U>call<SID>yankandcomment("'<", "'>")<CR>
nnoremap <silent> <Plug>CommentaryYank :<C-U>set opfunc=<SID>yankandcomment<CR>g@
nnoremap <silent> <Plug>CommentaryYankLine :<C-U>set opfunc=<SID>yankandcomment<Bar>exe 'norm! 'v:count1.'g@_'<CR>
xnoremap <silent> <Plug>CommentaryYank :<C-U>call<SID>yankandcomment("'<", "'>", v:register)<CR>
nnoremap <silent> <Plug>CommentaryYank :<C-U>call <SID>setcommentaryreg(v:register)<CR>:set opfunc=<SID>yankandcomment<CR>g@
nnoremap <silent> <Plug>CommentaryYankLine :<C-U>call <SID>setcommentaryreg(v:register)<CR>:set opfunc=<SID>yankandcomment<Bar>exe 'norm! 'v:count1.'g@_'<CR>
xnoremap <silent> <Plug>Commentary :<C-U>call <SID>go(line("'<"),line("'>"))<CR>
if !hasmapto('<Plug>Commentary') || maparg('gc','n') ==# ''
Expand Down

0 comments on commit 0b7474c

Please sign in to comment.