例如//输入注释//(点击一次回车后光标在这里)和//输入注释(按两次输入后光标在此处) 解决方案 此映射检查当前行是否只包含注释前导,然后再决定它是 还是 :inoremap <CR>getline(".") =~ '^\s*\(\*\|//\|#\|"\)\s*$' ? "\" : "\;"In Vim, I like the feature that allows you to auto insert comments after you have started a comment block. How would you make it so that you get a comment character(s) after a newline, but upon getting a second newline that comment is removed and you start a newline without a comment character. This would be helpful if you are working on a comment block and don't want to make anymore comments after that (in my case I also want to apply the same thing to markdown lists, treating */- as comment characters).For example// typing a comment// (cursor here after hitting enter once)And// typing a comment(cursor here after hitting enter twice) 解决方案 This mapping checks if the current line contains only comment leaders before deciding if it does <C-u> or <CR>:inoremap <expr> <CR> getline(".") =~ '^\s*\(\*\|//\|#\|"\)\s*$' ? "\<C-u>" : "\<CR>" 这篇关于Vim:双击后删除注释字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 15:00