Questions tagged [key-bindings]

Doing an action when pressing a key. These are also called key mappings or mappings. For questions about default key bindings, as well as creating or redefining key bindings.

Filter by
Sorted by
Tagged with
109 votes
1 answer
30k views

How to debug a mapping?

I see a lot of questions on here where a user has a mapping which doesn't work and most of the time the reasons are pretty similar. I suggest to make this question a reference for this kind of ...
statox's user avatar
  • 49k
12 votes
1 answer
3k views

How do I use a variable or return value in option, command, or mapping?

I have a variable foo with let foo='value', and a function F like function F() return 'value' endfunction and I want to use them in an option: :set option=foo, :set option=F(); or in a command: :...
D. Ben Knoble's user avatar
  • 24.7k
82 votes
8 answers
85k views

How to map Alt key?

I'm trying to map Alt key in the following way: :map <A-j> j :map <A-k> k but it doesn't work (bell is rang on Alt + j/Alt + k). What am I missing? I'm using Terminal on OSX, the same ...
kenorb's user avatar
  • 18k
26 votes
1 answer
7k views

Can I map a Ctrl + upper-case letter separately from Ctrl + lower-case letter?

I am trying to figure out how to navigate windows little quicker, so I would like to map the following: :nmap <silent> <C-F> :wincmd f<CR> The problem is this remaps the ^f (lower-...
user1135541's user avatar
  • 1,083
14 votes
1 answer
5k views

Mapping Ctrl with equal sign

I am trying to map my Ctrl and plus sign together. This is what I am trying in my vimrc: nnoremap <C-=> : echo "Hello" <CR> However it seems like the mapping is not being triggered. ...
James Franco's user avatar
  • 1,061
28 votes
1 answer
4k views

Disable <Esc> but keep <C-[>

For switching back from Insert mode I'm used to <Esc>. Now I'm looking to retrain myself to <C-[> instead of <Esc>. For that i need to disable <Esc> to help with the ...
mxlian's user avatar
  • 545
17 votes
5 answers
2k views

Why does this <Esc> normal mode mapping affect startup?

I'm experiencing a weird problem with a normal mode mapping of Esc. If you create the file escmapvimrc with the contents: set nocompatible set showcmd " Doesn't affect the problem: just makes it ...
Rich's user avatar
  • 30.9k
12 votes
3 answers
4k views

Mapping Ctrl+s does not work

I am trying to map Ctrl+s to save my file however it does not work. My mappings: map <C-s> :w <CR> :echo "Saved" <CR> imap <C-s> <Esc> :w <CR> :echo "Saved" <...
iProgram's user avatar
  • 1,589
27 votes
3 answers
10k views

What does `<Bar>` mean?

In answering a question just now, I mentioned using a normal mode key mapping that can be found at the Vim Tips Wiki. In the middle of explaining the key mapping, I realized that I had no idea what &...
Christopher Bottoms's user avatar
8 votes
1 answer
2k views

Mapping control-H in insert mode doesn't work; it always works like backspace

I tried mapping control-H, J, K, and L respectively in insert mode to move around splits. inoremap <C-h> <ESC><C-W><C-h>i inoremap <C-l> <ESC><C-W><C-l&...
matts1's user avatar
  • 181
6 votes
3 answers
3k views

Strange behavior of <ctrl-j> remapping

I want ctrl-h, ctrl-j, ctrl-k and ctrl-l in insert mode to behave like the arrow keys. I have this (among other things) in my .vimrc: inoremap <C-j> <Down> inoremap <C-k> <Up&...
DJMcMayhem's user avatar
  • 17.3k
101 votes
2 answers
57k views

How can I find out what <Leader> is set to? And is it possible to remap <Leader>?

How can I figure out which key is set as my <Leader>, and how do I remap it?
krampstudio's user avatar
  • 1,185
5 votes
1 answer
2k views

How to map shortcut to double square brackets?

When I type [[ or ]] in normal mode, cursor is jumping previous / next "class definition" during editing python (.py) file. I want to map these shortcuts to SHIFT + UP and SHIFT + DOWN. And I added ...
Umut Çağdaş Coşkun's user avatar
140 votes
17 answers
175k views

Other ways to exit Insert mode besides Escape

The primary reason I like vim over emacs is that my hand movement distance away from the home row is very low (even as a programmer). However, the one main time that I do this is leaving insert mode, ...
durron597's user avatar
  • 2,091
9 votes
2 answers
2k views

How to map <C-i> separate from <Tab>?

I want to remap <C-I> to print markdown * symbol around the previous word. For example: # user actions inside <...> some text typed in vim insert mode<cursor_position> <C-I> #...
avimehenwal's user avatar
4 votes
1 answer
969 views

recover default behavior of arrow keys rather than having them produce ABCD, when I map <esc>

My question is related to this post which for some reason was closed. Here's my .vimrc file set cpoptions=BceFs$ ":compatibility flags with /usr/ucb/vi set hlsearch hi Search ctermfg=white ...
Leo Simon's user avatar
  • 715
40 votes
2 answers
6k views

What is <Leader>?

I see <Leader> quite often in other people's vimrc files. Like this one. What is it? What does it do?
Frames Catherine White's user avatar
31 votes
3 answers
10k views

How can I redefine plugin key mappings?

I have installed a plugin that doesn't provide a mechanism to disable the key mappings it defines. I want to redefine one of the mappings (<leader>cc) defined by the plugin for my own pursope, I'...
toro2k's user avatar
  • 4,772
30 votes
1 answer
11k views

Understanding CTRL-U combination

In this answer I faced the CTRL-U used in function call after : and before the actual function name. :nnoremap <buffer> <cr> :<C-U>call append('.', repeat([''],v:count1))<cr> ...
user3663882's user avatar
25 votes
5 answers
17k views

How to find out what a key is mapped to?

I know that running :map commands without arguments should give me a list of user-defined mappings, but, for example, when I press Ctrl-W Ctrl-I something happens, yet I have no idea what function was ...
Mad Wombat's user avatar
18 votes
2 answers
4k views

How to repeat a mapping when keeping key pressed

I have in my .vimrc some simple mappings to resize split windows easily: noremap <Leader><UP> <C-w>+ noremap <Leader><DOWN> <C-w>- That works pretty fine but ...
statox's user avatar
  • 49k
12 votes
1 answer
6k views

Is it possible to map control forward-slash with vim

I'm wondering if it is possible to map control + forward-slash in vim. The mapping would be for normal mode if that makes a difference. I have tried <c-/> but that didn't work. I also tried ...
RobStallion's user avatar
7 votes
3 answers
4k views

How to format a mapping to an if statement?

I'm had some trouble defining a mapping in my .vimrc. I want <leader>sv to source my .vimrc, but first I want to write, if I'm currently editing it. Goal The intention of the code is this: if ...
Jacktose's user avatar
  • 833
42 votes
4 answers
28k views

How can I work with splits in Vim without Ctrl-W?

My terminal doesn't allow me to type Ctrl+W, because that's a shortcut for closing a terminal tab. I like working with splits, but I can't find any way to do so without using C-W. This forced me to ...
Mateon1's user avatar
  • 523
41 votes
8 answers
31k views

How to disable arrow keys in vim?

I want to teach myself to prefer hjkl more over the arrow keys in order to stay on the home row. (I am very aware that one should not use hjkl as the main navigation keys as there are more powerful ...
k0pernikus's user avatar
  • 2,937
39 votes
1 answer
14k views

What are the differences between the map, noremap, abbrev and noreabbrev commands?

These commands transform one set of keystrokes to another in some way, but I am somewhat fuzzy on which one is most appropriate for some situation. In addition, there are the ! variants of them as ...
muru's user avatar
  • 24.7k
24 votes
3 answers
2k views

How can I get ‘n’ to go forward even if I started searching with ‘?’ or ‘#’?

Vim has (at least) two sets of commands that search in opposite directions. Typing / and then a pattern will search forward through the document for the pattern; typing ? and then a pattern will ...
bdesham's user avatar
  • 2,873
20 votes
1 answer
3k views

How can I map d[count]d?

N.B. This is not a duplicate of How does the "d3fg" command work? Please read it before voting to close! I've come to a bit of an impasse in my quest to get small deletions work like big ...
Rich's user avatar
  • 30.9k
20 votes
4 answers
3k views

How can I use Readline shortcuts in the vim command line?

When I'm editing a Vim command, I would like to use the same shortcuts as in Bash and every other REPL: M-b to go back a word, M-Backspace to delete a previous word, M-u to convert the word to ...
Mihai's user avatar
  • 311
17 votes
1 answer
2k views

How to move the cursor to the correct indentation level without quiting insert mode?

For example I have this JavaScript code. The | character represents the cursor position and it is on an empty line. function a() { console.log("a"); function b() { console....
silviubogan's user avatar
15 votes
1 answer
2k views

Can't map German 'umlaut' keys in .vimrc

I'm trying to find a way to map German umlaut keys (Ä,ä,Ö,ö,Ü,ü). A simple shortcut like this won't work: inoremap <c-ö> <Esc> Nothing happens when I hit ctrl+ö. Does anyone know a ...
Rotareti's user avatar
  • 585
11 votes
2 answers
2k views

How does vimgolf record all keystrokes?

From time to time I like to engage in a round of vimgolf. It can be enlightening. How are they able to record all the keystrokes? That must be a vim feature. Anybody any idea how to do that. It could ...
mike's user avatar
  • 939
11 votes
1 answer
2k views

How does one include a trailing space in a mapping?

I'm currently trying to create the following mapping in my vimrc: nnoremap <Leader>s :split The :split is followed by a trailing space. This makes sense so I can enter the file name without ...
fvgs's user avatar
  • 233
10 votes
2 answers
754 views

Is there a way to alias `:w'` to `:w`, to avoid creating files named '?

Occasionally, my pinky will graze the ' key while reaching for enter, resulting in :w'<Enter>. I've tried: cabbrev w' :w cabbrev w\' :w cabbrev "w'" :w None of them work. Is there a way to ...
mwcz's user avatar
  • 245
10 votes
2 answers
806 views

What's the functional difference between the key notations "\<xxx>" and '<xxx>'?

I stumbled recently upon a mapping in the Vim Tips Wiki that uses an expr-quote: nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR> and realized it still worked ...
Antoine Cotten's user avatar
9 votes
1 answer
2k views

Why does remapping <Esc> make the cursor jump?

In .vimrc: inoremap ii <esc> " ii to go back into command mode The problem is, after ii, cursor jumps 35 columns right. The only other line which affects Esc: ...
user avatar
6 votes
1 answer
2k views

Using a no-op key in insert mode, can't use key after using no-op mapping

I have the following bindings in my ~/.vimrc to make it easier to "disengage" some of my insert-mode key-bindings. Here's an example. ` for <Nop> and `` to enter a literal `. inoremap ` <...
Greg Nisbet's user avatar
  • 1,785
5 votes
2 answers
689 views

Map CTRL-& in vimrc

I'm trying to re-map tagbar toggling with <C-&> that I get used to when working with IDEs. But setting execute "nnoremap <C-&> :TagbarToggle<CR>" does not have the ...
St.Antario's user avatar
  • 1,107
4 votes
1 answer
345 views

Vimrc tries to execute command defined on leader

I'm trying to have something like this in my .vimrc: nnoremap <leader>has :w | ! reset; runhaskell % <cr> How ever, now it prompts an error when loading .vimrc and tells me: :! reset; ...
Stephane Rolland's user avatar
91 votes
3 answers
31k views

Open filename under cursor like gf, but in a new tab (or split)?

The normal mode command gf go to a file with the path the cursor currently is at. But it does so in the current window, replacing the current text. That means you need to navigate back explicitly ...
Volker Siegel's user avatar
30 votes
4 answers
71k views

Remap Esc key in Vim

Is it possible to remap the Esc key to another key in Vim? When I'm using Vim in a full screen VMware vSphere web client console window and I press the Esc key to exit edit mode, it also takes me out ...
Beam Davis's user avatar
26 votes
4 answers
12k views

How to enter insert mode when entering neovim terminal pane?

I have the following mappings to make it easy to move out of a terminal pane in neovim: tnoremap <C-h> <C-\><C-n><C-w>h " Workaround since <C-h> isn't working in neovim ...
aharris88's user avatar
  • 1,827
26 votes
1 answer
4k views

What is the difference between "mapped key sequences" and "key codes"? (timeoutlen v ttimeoutlen)

The vim manual says we can use timeoutlen to specify the timeout length of mapped key sequences and can use ttimeoutlen to specify the timeout length of key codes: A useful setting would be :set ...
Niko Bellic's user avatar
  • 1,744
23 votes
4 answers
2k views

Clear a line faster than [0][d][$]

Is there a faster way to erase the text on a line than pressing 0 to jump to the start, then pressing d$ to delete until the end of the line? Also, what if I wanted to delete everything except the ...
Robbie Wxyz's user avatar
17 votes
3 answers
6k views

Fix arrow keys displaying A, B, C, D in vi (not in vim)

I know that in vim I can add set nocompatible in .vimrc to avoid that arrow keys display A, B, C, D in insert mode. But I'm using vi Version 4.0 (gritter) 12/25/06. How can I obtain the same ...
Ortomala Lokni's user avatar
15 votes
1 answer
340 views

Using <C-,> causes "<80>ü^D," to flash in the showcmd area?

I've mapped <C-,> as well as some other special keys (<C-Enter>, <C-S-Space>, ...) in my vimrc like, :set <F13>=^[[44;5u :map <F13> <C-,> :map! <F13> <C-...
ivan's user avatar
  • 1,420
12 votes
1 answer
2k views

How to map Enter to custom command EXCEPT in quick fix?

I've remapped <cr> (enter) to za so I can quickly open/close folds. However, now when I use the quickfix window and hit enter it no longer jumps to the line with the error (because it's trying ...
artfulrobot's user avatar
12 votes
2 answers
388 views

Quickly switch between fonts at runtime

While fonts can be manually selected in GVim from the menu, I have a few preferred fonts I would like to switch between depending on the task at hand (small bitmap, larger OTF... etc). Is there a way ...
ideasman42's user avatar
  • 3,673
11 votes
1 answer
632 views

Map a sequence of letters in insert mode

I can already map a key combination in insert mode: :inoremap abc <do stuff> However, this has a few drawbacks: When typing a partial version of the sequence, such as ab, the characters aren'...
Doorknob's user avatar
  • 14.8k
11 votes
4 answers
1k views

Bundling command sequences together for repeat (.)

Consider: apple pear Put your cursor on the first line and type Yp, producing: apple apple pear Put your cursor on the pear line and type . to repeat the last command. This repeats only the p (...
Jonah's user avatar
  • 743

1
2 3 4 5