vim 更改 :x 函数以删除缓冲区而不是保存 &退出 [英] vim change :x function to delete buffer instead of save & quit
问题描述
我想在vim gui-mode 中设置: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
是错误的,但我不知道正确的术语,这就是为什么谷歌根本没有提供任何帮助.
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 更改 :x 函数以删除缓冲区而不是保存 &退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!