mirror of
https://github.com/amix/vimrc
synced 2025-06-16 01:25:00 +08:00
Updated plugins
This commit is contained in:
@ -2,8 +2,8 @@
|
||||
|
||||
Comment stuff out. Use `gcc` to comment out a line (takes a count),
|
||||
`gc` to comment out the target of a motion (for example, `gcap` to
|
||||
comment out a paragraph), and `gc` in visual mode to comment out the
|
||||
selection. That's it.
|
||||
comment out a paragraph), `gc` in visual mode to comment out the selection,
|
||||
and `gc` in operator pending mode to target a comment. That's it.
|
||||
|
||||
I wrote this because 5 years after Vim added support for mapping an
|
||||
operator, I still couldn't find a commenting plugin that leveraged that
|
||||
@ -11,10 +11,8 @@ feature (I overlooked
|
||||
[tcomment.vim](https://github.com/tomtom/tcomment_vim)). Striving for
|
||||
minimalism, it weighs in at under 100 lines of code.
|
||||
|
||||
Oh, and it uncomments, too. The above maps actually toggle, and `gcu`
|
||||
uncomments a set of adjacent commented lines. Install
|
||||
[repeat.vim](https://github.com/tpope/vim-repeat) to enable
|
||||
repeating `gcu` with `.`. (The other maps are repeatable without it.)
|
||||
Oh, and it uncomments, too. The above maps actually toggle, and `gcgc`
|
||||
uncomments a set of adjacent commented lines.
|
||||
|
||||
## Installation
|
||||
|
||||
|
@ -9,21 +9,22 @@ correctly set, or uses b:commentary_format if it is set.
|
||||
The gc mappings are preferred, while the \\ mappings are provided for
|
||||
backwards compatibility.
|
||||
|
||||
*gc* *\\*
|
||||
*gc*
|
||||
gc{motion} Comment or uncomment lines that {motion} moves over.
|
||||
\\{motion}
|
||||
|
||||
*gcc* *\\\*
|
||||
*gcc*
|
||||
gcc Comment or uncomment [count] lines.
|
||||
\\\
|
||||
|
||||
*v_gc* *v_\\*
|
||||
*v_gc*
|
||||
{Visual}gc Comment or uncomment the highlighted lines.
|
||||
{Visual}\\
|
||||
|
||||
*gcu* *\\u*
|
||||
gcu Uncomment the current and adjacent commented lines.
|
||||
\\u
|
||||
*o_gc*
|
||||
gc Text object for a comment (operator pending mode
|
||||
only.)
|
||||
|
||||
*gcgc* *gcu*
|
||||
gcgc Uncomment the current and adjacent commented lines.
|
||||
gcu
|
||||
|
||||
The |User| CommentaryPost autocommand fires after a successful operation and
|
||||
can be used for advanced customization.
|
||||
|
@ -44,10 +44,16 @@ function! s:go(type,...) abort
|
||||
endif
|
||||
call setline(lnum,line)
|
||||
endfor
|
||||
silent doautocmd User CommentaryPost
|
||||
let modelines = &modelines
|
||||
try
|
||||
set modelines=0
|
||||
silent doautocmd User CommentaryPost
|
||||
finally
|
||||
let &modelines = modelines
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! s:undo() abort
|
||||
function! s:textobject(inner) abort
|
||||
let [l, r] = s:surroundings()
|
||||
let lnums = [line('.')+1, line('.')-2]
|
||||
for [index, dir, bound, line] in [[0, -1, 1, ''], [1, 1, line('$'), '']]
|
||||
@ -56,27 +62,38 @@ function! s:undo() abort
|
||||
let line = matchstr(getline(lnums[index]+dir),'\S.*\s\@<!')
|
||||
endwhile
|
||||
endfor
|
||||
call s:go(lnums[0], lnums[1])
|
||||
silent! call repeat#set("\<Plug>CommentaryUndo")
|
||||
while (a:inner || lnums[1] != line('$')) && empty(getline(lnums[0]))
|
||||
let lnums[0] += 1
|
||||
endwhile
|
||||
while a:inner && empty(getline(lnums[1]))
|
||||
let lnums[1] -= 1
|
||||
endwhile
|
||||
if lnums[0] <= lnums[1]
|
||||
execute 'normal! 'lnums[0].'GV'.lnums[1].'G'
|
||||
endif
|
||||
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>
|
||||
nnoremap <silent> <Plug>CommentaryUndo :<C-U>call <SID>undo()<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
|
||||
|
||||
if !hasmapto('<Plug>Commentary') || maparg('gc','n') ==# ''
|
||||
if 1 || !hasmapto('<Plug>Commentary') || maparg('gc','n') ==# ''
|
||||
xmap gc <Plug>Commentary
|
||||
nmap gc <Plug>Commentary
|
||||
omap gc <Plug>Commentary
|
||||
nmap gcc <Plug>CommentaryLine
|
||||
nmap gcu <Plug>CommentaryUndo
|
||||
nmap cgc <Plug>ChangeCommentary
|
||||
nmap gcu <Plug>Commentary<Plug>Commentary
|
||||
endif
|
||||
|
||||
if maparg('\\','n') ==# '' && maparg('\','n') ==# '' && get(g:, 'commentary_map_backslash', 1)
|
||||
xmap \\ <Plug>Commentary
|
||||
nmap \\ <Plug>Commentary
|
||||
nmap \\\ <Plug>CommentaryLine
|
||||
nmap \\u <Plug>CommentaryUndo
|
||||
xmap \\ <Plug>Commentary:echomsg '\\ is deprecated. Use gc'<CR>
|
||||
nmap \\ :echomsg '\\ is deprecated. Use gc'<CR><Plug>Commentary
|
||||
nmap \\\ <Plug>CommentaryLine:echomsg '\\ is deprecated. Use gc'<CR>
|
||||
nmap \\u <Plug>CommentaryUndo:echomsg '\\ is deprecated. Use gc'<CR>
|
||||
endif
|
||||
|
||||
" vim:set et sw=2:
|
||||
|
Reference in New Issue
Block a user