简体   繁体   English

如何在vim中重新映射“ q!”和“ q”

[英]how to remap “q!” and “q” in vim

I'm trying to remap q and q! 我正在尝试重新映射qq! . Here's what I'm trying: 这是我正在尝试的:

cnoremap q :call TabCloseLeft('q')
cnoremap q! :call TabCloseLeft('q!')

That properly remaps :q but doesn't capture :q! 可以正确地重映射:q但不能捕获:q! . I've read various help sections, but I'm obviously overlooking something. 我已经阅读了各个帮助部分,但显然我忽略了一些内容。

I see some problems: 我看到一些问题:

  • You are using a cnoremap dangerously eg /q 您正在危险地使用cnoremap例如/q
  • You are using trying to override vim's native :quit function 您正在尝试覆盖Vim的本机:quit函数
  • Looks like you are trying to force vim into a tab behavior 看起来您正在试图将Vim强制变为选项卡行为

cnoremap cnoremap

Do not use cnoremap to try and create commands, use :command . 不要使用cnoremap尝试和创建命令,使用:command If you want to override a command then use a clever cabbrev expression or plugin. 如果要覆盖命令,请使用聪明的cabbrev表达式或插件。 See vim change :x function to delete buffer instead of save & quit 查看vim change:x函数来删除缓冲区,而不是保存并退出

Native quit 本地戒烟

There are many ways for quiting a buffer in vim. 在vim中有很多退出缓冲区的方法。 Some do slightly different things. 有些做的事情略有不同。 As vimmers learn more commands they integrate them into their workflow. 随着Vimmer学习更多的命令,他们将它们集成到他们的工作流程中。 eg <cw>c to close a split/window and ZZ to update and quite the current buffer. 例如, <cw>c关闭拆分/窗口, ZZ更新并更新当前缓冲区。 If you go down this path you will be overriding many command or you will be disregarding useful commands. 如果您走这条路,将会覆盖许多命令,或者将忽略有用的命令。

Tabs 标签

Learn to use buffers effectively . 学习有效地使用缓冲区 Using tabs in Vim is great however they are not the only way and will certainly cause you pain down the road. 在Vim中使用制表符很不错,但是它们并不是唯一的方法,并且肯定会使您痛苦不已。 IMHO it is best to curtail these behaviors and encourage better habits. 恕我直言,最好是减少这些行为并鼓励更好的习惯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM