Skip to content

Instantly share code, notes, and snippets.

@suewonjp
Created December 25, 2017 06:03
Show Gist options
  • Save suewonjp/b0d78451c3af320fe61901e5d868970d to your computer and use it in GitHub Desktop.
Save suewonjp/b0d78451c3af320fe61901e5d868970d to your computer and use it in GitHub Desktop.
Simple Vim function to block comment multiple lines of code
" Block comment multiple lines of code.
" Intended for Visual mode only
function! BlockComment(tn, bn)
let l:ltop = line("'<")
let l:lbottom = line("'>")
let l:indc = indent(l:ltop)
let l:ind = ''
let l:i = 0
while l:i < l:indc
let l:ind .= ' '
let l:i = l:i + 1
endwhile
call append(l:ltop-1, l:ind . a:tn)
call append(l:lbottom+1, l:ind . a:bn)
endfunction
" The following mapping can be used to block comment multiple lines of C/C++/Java/JS code
vnoremap <silent> <leader>' :<C-u>call BlockComment('/*', '*/')<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment