Vim:双击后删除注释字符 [英] Vim: Remove comment character after double enter

查看:25
本文介绍了Vim:双击后删除注释字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Vim 中,我喜欢允许您在启动注释块后自动插入注释的功能.您将如何使它在换行符后获得注释字符,但是在获得第二个换行符时,该注释被删除,并且您开始一个没有注释字符的换行符.如果您正在处理评论块并且之后不想再发表评论,这将很有帮助(在我的情况下,我也想将相同的内容应用于降价列表,将 */- 视为评论字符).

例如

//输入注释//(点击一次回车后光标在这里)

//输入注释(按两次输入后光标在此处)

解决方案

此映射检查当前行是否只包含注释前导,然后再决定它是 还是 :

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:双击后删除注释字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆