本文介绍了vim change:x函数删除缓冲区而不是保存&辞职的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在vim gui模式下将:x设置为delete buffer,因为我总是杀死整个gvim,这很烦人.我知道我可以专门设置if has("gui running")的gui问题,但不知道如何重新映射:x

I want to set :x in vim gui-mode to delete buffer because I always kill the whole gvim, which is kind of annoying. I know i can specifically set gui problems with if has("gui running") but don't know how to remap :x

预先感谢

ps .:也许标签/术语remap是错误的,但我不知道正确的术语,这就是Google根本不提供任何帮助的原因.

ps.: maybe the tag/term remap is wrong but I don't know the correct term, that's why google didn't provide any help at all.

推荐答案

我发现最安全的选择是使用表达式缩写:

I find the safest alternative is to use an expression abbreviation:

cnoreabbrev <expr> x getcmdtype() == ":" && getcmdline() == 'x' ? 'bd' : 'x'

这将确保在使用:x时将缩写仅扩展为bd,否则将其扩展为x.

This will ensure the abbreviation will only be expanded to bd when :x is used otherwise just expand to x.

更多帮助:

:h map-<expr>
:h getcmdtype()
:h getcmdline()

经进一步检查,似乎有一个插件可以由Hari Krishna Dara完全执行此操作,名为 cmdalias.vim. .它使用了上面技术的一种变体.

Upon further inspection there appears to be a plugin that does exactly this by Hari Krishna Dara called cmdalias.vim. It uses a variation of the technique above.

这篇关于vim change:x函数删除缓冲区而不是保存&amp;辞职的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 06:01