As of May 31, 2023, we have updated our Code of Conduct.

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
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
6 votes
2 answers
405 views

imap beginning with <C-o> interferes with omnicomplete

I added the following key mappings: inoremap <silent> <Up> <C-o>gk inoremap <silent> <Down> <C-o>gj The goal was that j/k would still work the way that I was ...
Drew's user avatar
  • 565
7 votes
3 answers
4k views

How do I trigger an autocommand when user enters/leaves command mode

I'm using a really clever plugin that changes the line number style (relative/normal) contextually. Basically when you enter insert mode you have normal line numbers and when you leave insert mode it ...
Sukima's user avatar
  • 1,172
6 votes
2 answers
865 views

How to write a file automatically after every change?

Something that helps in text editing and proofreading is that for Insert mode, I have set an IMAP: :imap zz ^[:w^M and when I type zz I return to command mode and also write the current buffer. This ...
Konstantinos's user avatar
10 votes
2 answers
321 views

Context sensitive insert mode mapping or abbreviation

I'm planning to implement some utility mappings for my LaTeX plugin to simplify typing of mathematics. For instance, I want to create abbreviations similar to `a : \alpha `b : \beta -> : \to => ...
Karl Yngve Lervåg's user avatar
90 votes
3 answers
29k 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
1 vote
1 answer
198 views

`filetype plugin on` and square brackets

With this .vimrc: nnoremap [ :lp^M nnoremap ] :lne^M filetype plugin on vim becomes sluggish when switching between "errors" of location list with square brackets. As opposed to using lprevious/...
x-yuri's user avatar
  • 349
12 votes
2 answers
2k views

Using vim and Caffeine on the same machine

Background I work at a research laboratory and use three different OS's daily. On the Windows and Mac machines I make use of Caffeine to keep those machines from enabling the screensaver while I work ...
Jonathan E. Landrum's user avatar
4 votes
1 answer
52 views

How to make many definitions available as some kind of mode?

I've written a Vim script that inserts Unicode mathematical notation into what I'm editing. It's basically a few hundred lines of code that look like :map! \bbq ℚ. Sometimes I want to enable all of ...
Dan Piponi's user avatar
10 votes
4 answers
1k views

Can I use "gf" (or similar) to open a file and jump to a search term?

Is there a way to get vim's gf command (or something similar) to recognize a +{cmd} argument for file-paths? One can start vim and go directly to a search term by doing: $ vim +/coding_effort ~/...
Oliver Taylor's user avatar
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
3 votes
1 answer
484 views

Why does <Leader>l open my folds?

Despite there being no mention on the keystroke <Leader>l in my .vimrc, this combination opens the current fold on my installation of vim and gvim. It's not mentioned under :map. Is it a ...
LondonRob's user avatar
  • 287
6 votes
2 answers
218 views

Put current mappings into a buffer

To take a look at the mappings in my current session I fired: :map to list all current mappings. The output opens in some sort of read only awkward window. It's only possible to scroll. It's not ...
mxlian's user avatar
  • 545
8 votes
1 answer
338 views

Run a cmap only when searching

I have the following mapping: cnoremap <silent> <CR> <CR>:echo 'Enter pressed'<CR> This works as expected; the :echo command runs every time I press <CR> in the command ...
Martin Tournoij's user avatar
1 vote
1 answer
458 views

Special control keys in windows 7 don't work with the 'extended english keyboard (UK)' layout

Using gvim on Microsoft Windows, I find myself unable to use some control keys. For example I cannot navigate the :help topics using Control+]. Likewise, I cannot escape insert mode using Control+[. ...
M'vy's user avatar
  • 113
3 votes
1 answer
2k views

How to setup AG (the silver searcher) in Vim?

I am using AG to simplifying and improve the search in my Vim. I remapped K to search for the current selected word as follows: if executable('ag') set grepprg=ag\ --nogroup\ --nocolor command -...
Giuseppe Pes's user avatar
5 votes
2 answers
1k views

Override a mapping with leader key

I am trying to create a mapping that has 2 functions: On 1st use: redefine itself to be used After: execute the newly saved mapping The workflow could be : <leader>r -> map <leader>r ...
nobe4's user avatar
  • 15.7k
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
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
51 votes
6 answers
9k views

Can I delete an entire line, except the line break?

A fairly common operation for me in vim, since I am compulsive-obsessive and like to keep my files free of whitespace, is to delete the contents of an entire line, but not the line itself (i.e. not ...
Andrew Ferrier's user avatar
3 votes
1 answer
174 views

Complete multiple lines

I want to complete multiple lines at once. For instance, in a buffer (may be hidden): ... using std::cout; using std::cin; using std::endl; ... In the current buffer I can complete a whole line ...
bolov's user avatar
  • 179
10 votes
4 answers
7k views

How can I bind Ctrl-Space to be Esc when not in insert mode, and to switch to insert mode otherwise?

I dislike to have to reach up to the Escape key all the time. For a while I used the program xcape under Linux to map Caps lock to be both Control and Escape. However, I am currently working more and ...
Küstengold's user avatar
10 votes
3 answers
379 views

Like Ctrl-A and Ctrl-X but modify only the first digit

Is there a way to increase/decrease first digit after/under cursor, not the whole number. I know it's not how vim works, but is there a plugin that does that? I was unable to find it. It is very ...
firedev's user avatar
  • 2,312
2 votes
1 answer
91 views

How to jump to the location which [I points to?

I've installed node plugin, which give possibility to display all lines that contain the keyword under the cursor using [I hotkey. It looks like this: Is there possibility to jump to them?
Alexander Myshov's user avatar
6 votes
1 answer
965 views

What is wrong with this mapping expression in my .vimrc?

I'm trying to make Vim play nice with wrapped lines and I'm running into some problems. The following line xnoremap <expr> k ((v:count == 0) || (mode() !=# "V") ? 'gk' : 'k') gives me the ...
Chad Paradis's user avatar
1 vote
1 answer
133 views

How can I clear normal mode command count in mappings?

I have a mapping like this: noremap <expr> zj FindNext() FindNext will calculate which line to go, and return something like 10G. This works without a count, but with a count the line number ...
infmagic2047's user avatar
0 votes
2 answers
246 views

y<C-G> not yanking commit SHA in fugitive?

I'm having some trouble getting the yC-G command in normal mode to yank the current commit SHA. Currently it only yanks the file name. From :h fugitive: ["x]y<C-G>     Yank ...
amphetamachine's user avatar
1 vote
1 answer
804 views

Vim printing strange characters when hit "home", "end" stc

Why vim keep printing strange characters when I hit non-characters key? Insert prints [2~ Delete prints [3~ Page Up prints [5~ Page Down prints [6~ Home prints OH End prints OF Arrow Up prints OA ...
Mas Bagol's user avatar
  • 507
8 votes
1 answer
4k views

How to change the value of timeout for one key command?

What I want To temporarily change the timeout value for certain key commands Where I've looked From :help 'timeout' I have : The timeout only happens when the 'timeout' and 'ttimeout' options tell so. ...
baxx's user avatar
  • 935
6 votes
1 answer
362 views

Disable vim-surround in a netrw buffer

Is there a way to disable a plugin (or a set of keymaps) on a specific filetype? vim-surround causes a delay in netrw when pressing d to create a new directory. I'm thinking that this might be ...
user avatar
6 votes
1 answer
2k views

Triggering UltiSnips with enter

Is there any possible way to do expand trigger in UltiSnips with enter? I've tried <Enter>, <Return>, and <CR>. It works to trigger but doesn't work for new line. And I've tried to &...
Mas Bagol's user avatar
  • 507
7 votes
2 answers
3k views

What does [count]<leader> mean?

I found a command in NERDCommenter like this: [count]<leader>cc |NERDComComment| I have installed the plugin. But, I don't know how to make it work. So what's the meaning of that command? How ...
Mas Bagol's user avatar
  • 507
4 votes
2 answers
984 views

How to force quit if input was stdin?

I have q mapped to :qenter Q mapped to <esc>:qa!enter which means quit, unless something needs to be saved just quit My meanings for these keys clashes with vim's idea that stdin needs to be ...
jalanb's user avatar
  • 656
10 votes
2 answers
2k views

Create mappings that only apply to diff mode

In my vimrc I have <C-H>, <C-J>, <C-K> and <C-L> mapped to navigate between split windows in normal mode. When I use diff mode I only ever have windows in vertical splits, so ...
Pak's user avatar
  • 1,050
131 votes
8 answers
178k views

How can I easily move a line?

What is the command (or shortcut) to move a line up or down in vim? My current workflow is to yank (copy) the line and than delete that line and than to put (paste) that line.
Vader's user avatar
  • 1,555
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.4k
1 vote
1 answer
42 views

Cycle between keyword & user defined completion with C-N

I use the following mapping to initiate keyword completion, followed by user defined completion: inoremap <expr> <c-n> pumvisible() ? "\<c-x>\<c-o>" : "\<c-n>" How can ...
user avatar
19 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.4k
3 votes
2 answers
3k views

How to remap “ctrl+w+shift+f” to “gf” in vim to go to line of file under cursor in split window?

In a compilation log file whenever I get error it shows full path from root directory and line number. After opening file in vim say following is the content of file, .. .. Dir1/Dir2/src/ipv4.c 1223 ...
ypp174's user avatar
  • 31
5 votes
1 answer
82 views

Is it possible to use registers in Operator-pending mode? If not, why?

In Normal and Visual modes you can execute a motion or other operation using the contents of a register with @. This @ key does not work however in Operator-pending mode. Is there another way to use ...
Alexey's user avatar
  • 511
2 votes
1 answer
130 views

Where to find the time interval for a key combination to work?

the key combination dw is to delete a word. I've also defined my own key combination, e.g. <leader>j to move to a window below. My question is how much time is left between the first and second ...
Aaron Shen's user avatar
  • 2,439
4 votes
1 answer
1k views

remap not working; <NL> in appears in other binding

I'm trying to remap Control + [hjkl] to navigate among splits, by setting this in my rc file: " splits navigation nnoremap <C-h> <C-w>h nnoremap <C-j> <C-w>j nnoremap <C-k&...
alxndr's user avatar
  • 1,356
3 votes
2 answers
149 views

How to increase the 2nd number on a line

One thing I need to do frequently is to increment the 2nd number on a line. Increasing the first is very comfortable by just pressing Control-a, but I just can't find a nice way to increase the 2nd. ...
PhilippFrank's user avatar
  • 1,225
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,569
3 votes
3 answers
169 views

How to map CMD+Alt alone to the command?

I am trying to map Cmd+Alt to start searching in vim (/). The only question is: how would I do this? I know to map Alt in vimscript is by typing <A> but I do not know how to do Cmd. I also want ...
iProgram's user avatar
  • 1,569
4 votes
0 answers
590 views

j and k keys not working like they should [duplicate]

I'm using gVim on my Windows 8.1 computer with a standard QWERTY keyboard, and neither the j and k keys, nor the Up and Down arrow keys let me move up and down in my text field while in normal mode. h ...
Dante2's user avatar
  • 41
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,813
78 votes
8 answers
80k 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
  • 17.7k
26 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
9 votes
2 answers
678 views

How can I create a pseudo insert mode with a different keymap?

I am in the slightly unusual position of using two different keyboard layouts on a regular basis (Programmers-Dvorak and Turkish-F). These layouts are quite different from each-other and I am only ...
Caleb's user avatar
  • 2,215