Created
December 25, 2017 06:03
-
-
Save suewonjp/b0d78451c3af320fe61901e5d868970d to your computer and use it in GitHub Desktop.
Simple Vim function to block comment multiple lines of code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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