Disable encryption with: X in vim

I find that I press :X when I intend to type :X

Is there a way to disable :X as encryption to dial :X in vim failed?

I assume there is a command that can be placed in a .vimrc file?

+6
source share
4 answers

There are several standard ways to use cnoreabbrev / cnoremap for this: before replacing X with X check if it is the only character on the command line:

 cnoremap <expr> X (getcmdtype() is# ':' && empty(getcmdline())) ? 'x' : 'X' 

or

 cnoreabbrev <expr> X (getcmdtype() is# ':' && getcmdline() is# 'X') ? 'x' : 'X' 

. The difference is that at first you won’t type :Xfoo (translate to :Xfoo ), there won’t be a second one, but don’t allow input :X! (translates to :X! which really makes sense, unlike :X! ).

There are definitely no differences for the search ( /X is fine), input() prompt, etc., and no difference if the typed X not the first.

+9
source

Use :cnoreabbrev to override :X with the same functionality as :X :

 cnoreabbrev X x 

:cnoreabbrev preferable :cabbrev , because :X can already be reassigned to something else.

Note that using cabbrev will generally affect all one letter X words on the command line, for example. :XX will be translated into :XX , perhaps not what is intended. See @ZyX's answer for a fix.

+5
source

You can use :cmap to match X to x, but there are side effects such as the inability to use the letter X anywhere

 :cmap X x 

For a slightly less intrusive version

 :cmap X^M x^M 

which will only display X in x when you hit Enter immediately.

+1
source

cmdalias.vim - create aliases for Vim commands The plugin provides a more reliable implementation of the ZyX response. If you do not mind installing the plugin, you will get a convenient and extensible way to determine abbreviations:

 :Alias X x 
+1
source

Source: https://habr.com/ru/post/950003/


All Articles