vim 从 q! 映射到 Q!

vim 从 q! 映射到 Q!

我试图在 .vimrc 中将 'q!' 映射到 'Q!'?我尝试了以下操作,但没有成功。:command Q! q! 请提供任何建议来缓解此问题。谢谢。

答案1

你只需要给予

:command Q q

类似地,你可以对其他命令执行类似操作,

:command WQ wq
:command W w

答案2

这对我来说非常有效:

:command-bang Q q<bang>

来自 vim 的帮助(:h command-bang):

Special cases                           :command-bang :command-bar
                                        :command-register :command-buffer
There are some special cases as well:

        -bang       The command can take a ! modifier (like :q or :w)

Replacement text

The replacement text for a user defined command is scanned for special escape
sequences, using <...> notation.  Escape sequences are replaced with values
from the entered command line, and all other text is copied unchanged.  The
resulting string is executed as an Ex command. [...]

The valid escape sequences are
        [...]
        <bang>  (See the '-bang' attribute) Expands to a ! if the
                command was executed with a ! modifier, otherwise
                expands to nothing.
        [...]

答案3

尝试一下:

:cmap Q! q!

Q!在命令模式下映射到q!

相关内容