Skip to content

Instantly share code, notes, and snippets.

@richo
Forked from ConradIrwin/.vimrc
Created May 6, 2011 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richo/958436 to your computer and use it in GitHub Desktop.
Save richo/958436 to your computer and use it in GitHub Desktop.
# Comment vim text-object
function! SelectComment()
let curindent = indent(".")
let commstr = &commentstring[0]
" bail if not a comment
if getline(".")[curindent] != commstr
return
endif
" find the first commented line
while line(".") - 1 && indent(line(".") - 1) == curindent && getline(line(".") - 1)[curindent] == commstr
normal k
endwhile
" start selecting
normal V
" find the last commented line
while line(".") < line("$") && indent(line(".") + 1) == curindent && getline(line(".") + 1)[curindent] == commstr
normal j
endwhile
endfunction
vnoremap ic :<C-U>silent! call SelectComment()<CR>
omap ic :normal vic<CR>
@richo
Copy link
Author

richo commented May 6, 2011

14:04 < bairui> if you use the :options browser, you can easily find these sorts of things -
search for /comment

Todo note, shouldn't be too hard ot make work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment