文章目录
-
- [vim 实现 linux 多行快速标准注释](#vim 实现 linux 多行快速标准注释)
vim 实现 linux 多行快速标准注释
不多说了,直接上动图:
上代码:
powershell
function! CommentBlock()
" 获取Visual模式选中的起始和结束行号
let old_start_line = line("'<")
let old_end_line = line("'>")
call append(old_end_line, '')
call append(old_start_line - 1, '')
let start_line = old_start_line
let end_line = old_end_line + 2
execute "normal! " . start_line . "GV" . end_line . "G"
" 变量i用于循环
let i = start_line
" 循环处理每一行
while i <= end_line
" 如果是第一行
if i == start_line
execute i . 's/^/\/\*/'
" 如果是最后一行
elseif i == end_line
execute i . 's/^/\ *\//'
" 其他行
else
execute i . 's/^/\ * /'
endif
let i += 1
endwhile
endfunction
function! CallFunctionsAB()
""call AddLinesBeforeAndAfter()
""call AddLinesAndReselect()
call CommentBlock()
endfunction
"" 在Visual模式下,把 'gcm' 映射到上面定义的函数
vnoremap gcn :<C-u>call CallFunctionsAB()<CR>