Skip to content

Instantly share code, notes, and snippets.

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

richo commented May 6, 2011

Any ideas how to do a pull request..?

@ConradIrwin
Copy link
Author

Not sure if it's possible on a gist — I've made it a real repository at https://github.com/ConradIrwin/vim-comment-object

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