mirror of
https://github.com/amix/vimrc
synced 2025-06-16 01:25:00 +08:00
Added vim-commentary and updarted the plugins.
commentary: 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.
This commit is contained in:
1
sources_non_forked/vim-commentary/.gitignore
vendored
Normal file
1
sources_non_forked/vim-commentary/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/doc/tags
|
62
sources_non_forked/vim-commentary/README.markdown
Normal file
62
sources_non_forked/vim-commentary/README.markdown
Normal file
@ -0,0 +1,62 @@
|
||||
commentary.vim
|
||||
==============
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
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).
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
If you don't have a preferred installation method, I recommend
|
||||
installing [pathogen.vim](https://github.com/tpope/vim-pathogen), and
|
||||
then simply copy and paste:
|
||||
|
||||
cd ~/.vim/bundle
|
||||
git clone git://github.com/tpope/vim-commentary.git
|
||||
|
||||
Once help tags have been generated, you can view the manual with
|
||||
`:help commentary`.
|
||||
|
||||
FAQ
|
||||
---
|
||||
|
||||
> My favorite file type isn't supported!
|
||||
|
||||
Relax! You just have to adjust `'commentstring'`:
|
||||
|
||||
autocmd FileType apache set commentstring=#\ %s
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
See the contribution guidelines for
|
||||
[pathogen.vim](https://github.com/tpope/vim-pathogen#readme).
|
||||
|
||||
Self-Promotion
|
||||
--------------
|
||||
|
||||
Like commentary.vim? Follow the repository on
|
||||
[GitHub](https://github.com/tpope/vim-commentary) and vote for it on
|
||||
[vim.org](http://www.vim.org/scripts/script.php?script_id=3695). And if
|
||||
you're feeling especially charitable, follow [tpope](http://tpo.pe/) on
|
||||
[Twitter](http://twitter.com/tpope) and
|
||||
[GitHub](https://github.com/tpope).
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
Copyright (c) Tim Pope. Distributed under the same terms as Vim itself.
|
||||
See `:help license`.
|
28
sources_non_forked/vim-commentary/doc/commentary.txt
Normal file
28
sources_non_forked/vim-commentary/doc/commentary.txt
Normal file
@ -0,0 +1,28 @@
|
||||
*commentary.txt* Comment stuff out
|
||||
|
||||
Author: Tim Pope <http://tpo.pe/>
|
||||
License: Same terms as Vim itself (see |license|)
|
||||
|
||||
Comment stuff out. Then uncomment it later. Relies on 'commentstring' to be
|
||||
correctly set.
|
||||
|
||||
The gc mappings are preferred, while the \\ mappings are provided for
|
||||
backwards compatibility.
|
||||
|
||||
*gc* *\\*
|
||||
gc{motion} Comment or uncomment lines that {motion} moves over.
|
||||
\\{motion}
|
||||
|
||||
*gcc* *\\\*
|
||||
gcc Comment or uncomment [count] lines.
|
||||
\\\
|
||||
|
||||
*v_gc* *v_\\*
|
||||
{Visual}gc Comment or uncomment the highlighted lines.
|
||||
{Visual}\\
|
||||
|
||||
*gcu* *\\u*
|
||||
gcu Uncomment the current and adjacent commented lines.
|
||||
\\u
|
||||
|
||||
vim:tw=78:et:ft=help:norl:
|
75
sources_non_forked/vim-commentary/plugin/commentary.vim
Normal file
75
sources_non_forked/vim-commentary/plugin/commentary.vim
Normal file
@ -0,0 +1,75 @@
|
||||
" commentary.vim - Comment stuff out
|
||||
" Maintainer: Tim Pope <http://tpo.pe/>
|
||||
" Version: 1.1
|
||||
" GetLatestVimScripts: 3695 1 :AutoInstall: commentary.vim
|
||||
|
||||
if exists("g:loaded_commentary") || &cp || v:version < 700
|
||||
finish
|
||||
endif
|
||||
let g:loaded_commentary = 1
|
||||
|
||||
function! s:go(type,...) abort
|
||||
if a:0
|
||||
let [lnum1, lnum2] = [a:type, a:1]
|
||||
else
|
||||
let [lnum1, lnum2] = [line("'["), line("']")]
|
||||
endif
|
||||
|
||||
let [l, r] = split(substitute(substitute(&commentstring,'\S\zs%s',' %s',''),'%s\ze\S','%s ',''),'%s',1)
|
||||
let uncomment = 2
|
||||
for lnum in range(lnum1,lnum2)
|
||||
let line = matchstr(getline(lnum),'\S.*\s\@<!')
|
||||
if line != '' && (stridx(line,l) || line[strlen(line)-strlen(r) : -1] != r)
|
||||
let uncomment = 0
|
||||
endif
|
||||
endfor
|
||||
|
||||
for lnum in range(lnum1,lnum2)
|
||||
let line = getline(lnum)
|
||||
if strlen(r) > 2 && l.r !~# '\\'
|
||||
let line = substitute(line,
|
||||
\'\M'.r[0:-2].'\zs\d\*\ze'.r[-1:-1].'\|'.l[0].'\zs\d\*\ze'.l[1:-1],
|
||||
\'\=substitute(submatch(0)+1-uncomment,"^0$\\|^-\\d*$","","")','g')
|
||||
endif
|
||||
if uncomment
|
||||
let line = substitute(line,'\S.*\s\@<!','\=submatch(0)[strlen(l):-strlen(r)-1]','')
|
||||
else
|
||||
let line = substitute(line,'^\%('.matchstr(getline(lnum1),'^\s*').'\|\s*\)\zs.*\S\@<=','\=l.submatch(0).r','')
|
||||
endif
|
||||
call setline(lnum,line)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:undo()
|
||||
let [l, r] = split(substitute(substitute(&commentstring,'\S\zs%s',' %s',''),'%s\ze\S','%s ',''),'%s',1)
|
||||
let lnums = [line('.')+1, line('.')-2]
|
||||
for [index, dir, bound, line] in [[0, -1, 1, ''], [1, 1, line('$'), '']]
|
||||
while lnums[index] != bound && line ==# '' || !(stridx(line,l) || line[strlen(line)-strlen(r) : -1] != r)
|
||||
let lnums[index] += dir
|
||||
let line = matchstr(getline(lnums[index]+dir),'\S.*\s\@<!')
|
||||
endwhile
|
||||
endfor
|
||||
call s:go(lnums[0], lnums[1])
|
||||
silent! call repeat#set("\<Plug>CommentaryUndo")
|
||||
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>
|
||||
|
||||
if !hasmapto('<Plug>Commentary') || maparg('gc','n') ==# ''
|
||||
xmap gc <Plug>Commentary
|
||||
nmap gc <Plug>Commentary
|
||||
nmap gcc <Plug>CommentaryLine
|
||||
nmap gcu <Plug>CommentaryUndo
|
||||
endif
|
||||
|
||||
if maparg('\\','n') ==# '' && maparg('\','n') ==# ''
|
||||
xmap \\ <Plug>Commentary
|
||||
nmap \\ <Plug>Commentary
|
||||
nmap \\\ <Plug>CommentaryLine
|
||||
nmap \\u <Plug>CommentaryUndo
|
||||
endif
|
||||
|
||||
" vim:set et sw=2:
|
Reference in New Issue
Block a user