Hot answers tagged

79

A common binding you'll see is jj, because it works well for QWERTY layouts if you use home row positioning. inoremap jj <ESC> In that case, to type a literal jj - you should wait for 1 sec (by default) between typing the second character. (see :help 'timeout' for details) There is also c-o which will take you out of insert, letting you do one ...


52

Beside the built-in alternatives <C-[> and <C-c> to <Esc> key cited by others, another popular solution is to remap <CapsLock> as an additional Escape. This both on a Qwerty and Dvorak keyboard. This way you can press Esc very easily with the left little finger, without removing hands from the HomeRow (incidentally, Escape was just ...


36

The mappings that I use are: inoremap jk <esc> inoremap kj <esc> This way, you can simply hit j and k at the same time, without having to worry about which one you press first.


20

<C-[> and <C-c> are two native alternatives to <Esc>. See :help i_<esc> and :help i_ctrl-c which explains the difference between <C-c> and <Esc>.


15

Vim sends during startup some special terminal codes (that usually contain the <esc> key) to determine several things (colors, bs,...) If you mapped <esc> this will most likely confuse the parser of the return codes and weird things can happen. Therefore, use your above map only after everything has been setup correctly (e.g. via a VimEnter ...


15

There are two kinds of delay when you press <esc> in insert mode: mapping delay If you create some improper mapping that starts with <esc> : inoremap <esc>x <esc>:echom "balabala"<cr> When you press <esc>, vim will wait :h 'timeoutlen' milliseconds to see if next key is x. You should avoid this kind of mapping in all ...


13

The Linux terminal uses ANSI escape sequences (i.e. strings of characters starting with <Esc>) to send special keys to Vim, and as part of the communication protocol with which the application queries for its capabilities. Your mapping interferes with that, and thereby leads to these "strange" behaviors. Therefore, don't map <Esc>. Use another ...


11

I found this map works for Ctrl-Space : :nnoremap <C-@> i :inoremap <C-@> <Esc>


10

You can paste Vim's builtin termcap database in the current buffer with the following command: put =execute('set termcap') In it, you should find the text t_ku <Up> ^[OA, which means that when you press Up, the terminal will send Esc O A. Or you could just execute :echo &t_ku, to get the value of the terminal option 't_ku' (see :h t_ku). It ...


10

When you use ! or :! Vim builds the invoking command based on whatever is specified in the various 'shell...' settings (i.e. 'shell', 'shellcmdflag', 'shellquote', to name three). On Unix systems the defaults for the first two are usually the default shell ($SHELL) and -c so if I'm using Bash and I do :!foo bar the call Vim makes will look like: /bin/bash -c ...


9

You can do so with <lt> (see :h <lt>) : nnoremap <leader>x a<lt>CR> Will enter <CR> literaly, whereas : nnoremap <leader>x a<CR> Will execute <CR>


9

You don't need to escape them: you could use a different separator for the search pattern and the replace part: %s;mvn;/opt/maven/bin/mvn;g But, if you really want to escape them, you can use a backslash (\): %s/mvn/\/opt\/maven\/bin\/mvn/g (much harder to read, IMO)


7

I don't think that's possible, the problem is that <Esc> is the same as <C-[> as in the key codes that vim receives when you type it is exactly the same. You can reproduce this and validate it in insert mode by hitting <C-v> first and then <Esc> and <C-[> respectively and you'll see it sends the same key code to vim. Hence VIM ...


7

Vim is a terminal based program and has its key handling from the terminal. Also the GUI variants still act like this (with a few extensions). In a terminal Ctrl-A is ASCII 0x01, Ctrl-B is ASCII 0x02 and so on. Ctrl-Z is 0x1A and Ctrl-[ is 0x1B. And 0x1B is also the ASCII code for ESC. Vim can't differentiate between ESC and Ctrl-[, because it gets the ...


6

I would suggest using my plugin vim-easyescape. Plug "zhou13/vim-easyescape" let g:easyescape_chars = { "j": 1, "k": 1 } let g:easyescape_timeout = 100 cnoremap jk <ESC> cnoremap kj <ESC> The problem with a simple map sequence inoremap jj <ESC> is that Vim will pause whenever you type j or k in insert mode (it is waiting for the next key ...


6

You can map Caps Lock to Control without using any external program: In Mac OS X visit System Preferences > Keyboard -> Modifier Keys In Linux execute: setxkbmap -option caps:ctrl_modifier In Windows edit your registry. This brings Control onto the home row, making it easier to press all Control modified strokes, including Ctrl-[ and Ctrl-C which both exit ...


6

If you use Linux (though not an exact answer), I recommend that you map Caps Lock to Ctrl and then use xcape to adjust Caps Lock behavior as follows: when pressed by itself, Caps Lock behaves like Esc; when combined with another key, Caps Lock behaves like Ctrl. So you can press both Esc and a Ctrl combination more easily than any other solution. To remap ...


6

From vim --help: Arguments: -- Only file names after this ... So this works on the command line: vim -- +models/File.m From inside Vim you need to escape the +: :e \+models/File.m


6

The codes which keys produce varies wildly by terminal. vim tries to guess which escape sequences corresponds to which keycodes (<f1> etc) based on the $TERM variable and terminfo. The shifted f-keys are not standardized and they do not have termcap/terminfo entries. In this case, vim falls back to the xterm ones. Note, wherever ^[ is written, this ...


6

Is there a way to see exactly what shell command is being called out? To see what exactly is run, :echo getpid() will show vim's PID, e.g. 1234, with which you can then in another terminal run: sudo strace -fe trace=execve -p 1234 then in vim you can use any shell-invoking command like: :!echo foo and in the terminal running strace see something like: [...


5

nnoremap <C-Space> i inoremap <C-Space> <Esc>


5

The options 'timeout' and 'timeoutlen' control how Vim will treat typed characters when they are part of a mapping. By default 'timeout' is enabled and 'timeoutlen''s value is 1000 (ms). It means that by default when you hit a character that is part of a mapping, Vim will wait 1s before deciding whether you are typing the {lhs} of your mapping or if it's ...


5

In insert mode, you can type Ctrl-v Esc and Ctrl-v Ctrl[. You will see the literal interpretation of those key sequences according to vim. (See :h i_CTRL_V) Most importantly, you'll notice that they are the same (at least for me in both vim in xterm and gvim). So you cannot disable one and not the other. In general, I'd say it's a bad idea to remap Esc, as ...


5

I'm not sure of the solution (or if there is one) but I can explain roughly what's causing the problem to occur. When you press an arrow key on your keyboard, what your terminal actually passes to Vim is a ANSI escape code, which is, literally, an <Esc> character followed by a sequence of other characters. The sequences for the arrow keys are: up: ...


5

As stated on the question, :h map-bar suggests escaping the pipe with with \|. However, grep apparently understands that as a literal bar, thus the backslash needs to be escaped as well. This should work for grep: :grep -E 'foo\\|baz' *.c NOTE: there's no need to escape the backslash with vimgrep (:h :vimgrep). The following seems to give the same results ...


5

You could try set noesckeys. Here are its docs: Function keys that start with an <Esc> are recognized in Insert mode. When this option is off, the cursor and function keys cannot be used in Insert mode if they start with an <Esc>. The advantage of this is that the single <Esc> is recognized immediately, instead of after one second. ...


5

At first they might do the same but internally they are interpreted differently. In layman's terms they mean something like this: Esc: "OK I am done (with whatever I was doing)." CTRLC: "Stop that as fast as possible!" It is not clearly documented (as far as I can see) but there are some indications: i_<esc> says "End ... mode" whereas i_CTRL-C ...


5

Characters displayed by ^ followed by a capital letter (or a small number of other symbols, such as ^[) are the usual notation for the ASCII character produced by pressing that letter while holding the Control key. Vim will typically show these in a distinct color or highlight (to indicate it's displaying a Control-sequence and not two separate characters, ...


5

The command you are trying to use is the following: %s/\/\//\//g % The range: All lines in buffer s the substitution command / / / the separators of the substitution command \/\/ in the matching pattern you need to escape both slashes \/ you also need to escape the slash in the replacement string ...


4

If you have an US English keyboard, pressing Ctrl-[ is equivalent for pressing Esc. This provides an easy way to exit from insert mode. Alternatively use Ctrl-c. If you've vim in easy mode (-y), then you've to press Ctrl-l (Control-L) to exit insert mode. There is also Ctrl+o which will only temporary exit insert mode just to execute one command and return ...


Only top voted, non community-wiki answers of a minimum length are eligible