Hot answers tagged

63

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 ...


40

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 ...


29

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.


14

<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>.


11

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 ...


11

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 ...


9

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


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

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>


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

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 ...


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

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 ...


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

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 ...


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 ...


4

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


4

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 ...


4

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 ...


4

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 ...


4

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: ...


4

No, that is not true. Internally, \n will always match the line termination of a buffer regardless of whether the actual file uses <CR> or <NL> or <CR><NL> as line terminator (e.g. the 'fileformat') option does not matter. In a replace command however, the \r in the replace part will always produce an actual new line, since the \n ...


4

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 ...


3

If it is from statusline, then :h statusline is what you need. Vim has help for every single variable that you can set in .vimrc (at least the ones that come with pure Vim, plugins usually also have good docs), thus :h <variable name> should be your friend. This is from :h statusline: F S Full path to the file in the buffer. m F Modified flag, ...


3

More generally, you can start by specifying a directory name, so that the + (plus sign) appears in the middle of the file specification instead of at the beginning. Because all *nix operating systems, and others like MS-DOS / Windows that adopted Unix conventions, (just about any place you can run vim...,) refer to the current directory as . ("dot", "period"...


3

In terminal vi and Vim, alt + single-normal-mode-key will work for quick edits in most terminals. This works because most terminals send the alt modifier as the escape character. For example, when you type alt+k the terminal emulator sends two character to the running program: esc, k. Vi and Vim interpret this as you would expect; it leaves insert mode (...


3

FWIW I use: :map! ;l ^[ :vmap ;l ^[ It feels similar to hitting Return. I use ; as the leader for other Insert-mode mappings too. The only time I've needed to type ';' + letter is when code golfing; I've not had any conflicts otherwise.


3

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 ...


3

Vim has its own regex engine and it doesn't support {Cyrillic}. You probably want to read :h pattern-atoms and :h /character-classes to find out what you can use in your regexes. I think the best alternative you can find comes from :h /[] (especially the last example): \_[] A collection. This is a sequence of characters enclosed in brackets. It ...


3

The key syntax with brackets, such as <Esc>, is specific to Vim. In plain vi, you need to enter an actual ESC character in your mapping. You can do so by pressing Ctrl+V, followed by ESC, which will insert an actual ESC and will be displayed as ^[. The command will look like: :inoremap jj ^[ But note that the ^[ is a single ESC character and is ...


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