Skip to content

Instantly share code, notes, and snippets.

@richo
Forked from ConradIrwin/.vimrc
Created May 6, 2011 04:08
Show Gist options
  • Save richo/958436 to your computer and use it in GitHub Desktop.
Save richo/958436 to your computer and use it in GitHub Desktop.

Revisions

  1. Rich Healey revised this gist May 6, 2011. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions .vimrc
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,22 @@
    function! SelectComment()
    let curindent = indent(".")
    let commstr = &commentstring[0]

    " bail if not a comment
    if getline(".")[curindent] != "#"
    if getline(".")[curindent] != commstr
    return
    endif

    " find the first commented line
    while line(".") - 1 && indent(line(".") - 1) == curindent && getline(line(".") - 1)[curindent] == "#"
    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] == "#"
    while line(".") < line("$") && indent(line(".") + 1) == curindent && getline(line(".") + 1)[curindent] == commstr
    normal j
    endwhile
    endfunction
  2. @ConradIrwin ConradIrwin created this gist May 6, 2011.
    24 changes: 24 additions & 0 deletions .vimrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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>