Permalink
Browse files

commentary.vim 1.0

  • Loading branch information...
0 parents commit 7dc081455d802fa95e4e08b8745763befaf366bc @tpope committed Aug 20, 2011
Showing with 134 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +68 −0 README.markdown
  3. +18 −0 doc/commentator.txt
  4. +47 −0 plugin/commentary.vim
@@ -0,0 +1 @@
+/doc/tags
@@ -0,0 +1,68 @@
+commentary.vim
+==============
+
+Comment stuff out. Use `\\\` to comment out a line (takes a count),
+`\\` to comment out the target of a motion (for example, `\\ap` to
+comment out a paragraph), and `\\` in visual mode to comment out the
+selection. That's it.
+
+Install [repeat.vim](https://github.com/tpope/vim-repeat) to enable
+repeating with `.` the line commenting map `\\\`.
+
+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. Striving for minimalism, the first version weighed in at just
+35 lines of code.
+
+Oh, and it uncomments, too.
+
+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
+
+> What if I want custom maps?
+
+Fly by the seat of your pants and map directly to the `\` maps:
+
+ xmap ,, \\
+ nmap ,, \\
+ nmap ,,, \\\
+
+Contributing
+------------
+
+See the contribution guidelines for
+[pathogen.vim](https://github.com/tpope/vim-pathogen#readme).
+
+Self-Promotion
+--------------
+
+Like rails.vim? Follow the repository on
@xaizek

xaizek Aug 20, 2011

Like rails.vim?
Apparently you forgot to change this to commentary.vim.

@tpope

tpope Aug 20, 2011

Owner

Thanks!

+[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
+-------
+
+Distributable under the same terms as Vim itself. See `:help license`.
@@ -0,0 +1,18 @@
+*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.
+
+ *\\*
+\\{motion} Comment or uncomment lines that {motion} moves over.
+
+ *\\\*
+\\\ Comment or uncomment [count] lines.
+
+ *v_\\*
+{Visual}\\ Comment or uncomment the highlighted lines.
+
+ vim:tw=78:et:ft=help:norl:
@@ -0,0 +1,47 @@
+" commentary.vim - Comment stuff out
+" Maintainer: Tim Pope <http://tpo.pe/>
+" Version: 1.0
+" 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)
+ if a:type =~ '^\d\+$'
+ let [lnum1, lnum2] = [line("."), line(".") + a:type - 1]
+ elseif a:type =~ '^.$'
+ let [lnum1, lnum2] = [line("'<"), line("'>")]
+ else
+ let [lnum1, lnum2] = [line("'["), line("']")]
+ endif
+
+ let [before, after] = split(&commentstring,"%s",1)
+ let uncomment = 1
+ for lnum in range(lnum1,lnum2)
+ let line = matchstr(getline(lnum),'\S.*\s\@<!')
+ if line != '' && (stridx(line,before) || line[strlen(line)-strlen(after) : -1] != after)
+ let uncomment = 0
+ endif
+ endfor
+
+ for lnum in range(lnum1,lnum2)
+ if uncomment
+ let line = substitute(getline(lnum),'\S.*\s\@<!','\=submatch(0)[strlen(before):-strlen(after)-1]','')
+ else
+ let line = substitute(getline(lnum),'\S.*\s\@<!','\=printf(&commentstring,submatch(0))','')
+ endif
+ call setline(lnum,line)
+ endfor
+
+ if a:type =~ '^\d\+$'
+ silent! call repeat#set('\\\',a:type)
+ endif
+endfunction
+
+xnoremap <silent> \\ :<C-U>call <SID>go(visualmode())<CR>
+nnoremap <silent> \\ :<C-U>set opfunc=<SID>go<CR>g@
+nnoremap <silent> \\\ :<C-U>call <SID>go(v:count1)<CR>
+
+" vim:set sw=2 sts=2:

0 comments on commit 7dc0814

Please sign in to comment.