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
8 votes
2 answers
4k views

key mapping best practices

I found that I frequently needed a command in INSERT mode to open a line above the cursor (what O does in NORMAL mode) I put this in my .vimrc inoremap ao <esc>O It works well. I chose the ...
sudo bangbang's user avatar
8 votes
1 answer
1k views

I cannot unmap a key combination `y<C-G>`

When i check my mappings with :verb nmap y i get: n y<C-G> *@:call setreg(v:register, <SNR>104_recall())<CR> Last set from ~/.vim/bundle/vim-fugitive-2.2/plugin/...
Alexey's user avatar
  • 511
8 votes
2 answers
1k views

Repeat n time a mapping starting with a count

I have created the following mapping: :map <F8> 3w When I pressed 2<F8>, I thought it would move six words (2*3w), but it moves 23 words. (This has been mentioned in help section of vim ...
SibiCoder's user avatar
  • 3,212
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
8 votes
2 answers
908 views

How can I increase floating number with ctrl-a without deleting zeros?

When I'm trying to increase numbers with CtrlA it removes the leading and the trailing zeros. For example: 1.009500 1.09500 1.0009500 Results after pressing CtrlA: 1.009500 -> 1.9501 1.09500 ...
whitesiroi's user avatar
7 votes
1 answer
3k views

Separate C-m and Enter

I am using zsh, urxvt, tmux and in there vim. I am not 100% sure who causes the effect but I would like to bind something to ctrl and m but not to carriage return in vim. Does somebody how this is ...
baxbear's user avatar
  • 314
7 votes
0 answers
245 views

Shift+F8 changes letter case for 2 letters; how to unmap this? [duplicate]

setcolors.vim of vim's Wikia defines these keybindings: " F8 next scheme " Shift-F8 previous scheme " Alt-F8 random scheme but when I use Shift+F8 (the other ...
Konstantinos's user avatar
6 votes
2 answers
3k views

Jump to Next Number

Is there a command in Vim to move the cursor to the next number? I know I can do f2 to find the number 2 in the same line, but I'm looking for a more general number-jumping command.
jpyams's user avatar
  • 217
6 votes
2 answers
4k views

Creating a Vim function mapping that takes a count

I'm trying to create a function mapping that takes a count, in this case the number of lines to yank to the system clipboard. func! Clipboard() echo 'Clipboard function called' if v:count is 0 ...
math hates me's user avatar
6 votes
2 answers
375 views

Umlaut accented keys won't work for text objects

I have mapped [] and {} on my German keyboard with: nmap Ö { nmap Ä } nmap ö [ nmap ä ] but if I try, for example, to delete inside {} with di} it won't delete. It also fails with f and t (for ...
ffabi's user avatar
  • 63
6 votes
2 answers
6k views

Usage of timeoutlen and ttimeoutlen

I was trying to set a timeout length to apply to: Key combination presses (for example, pressing gh in netrw); and Exiting modes (for example, zero delay when exiting visual mode). Here is a portion ...
David542's user avatar
  • 2,147
6 votes
1 answer
1k views

Why can't I type certain non-ASCII letters?

I recently had a need to type the letters æ, ø, and å. For context, these are available on my physical keyboard, and work fine in other programs. It's also a Norwegian keyboard (+ layout), if that's ...
Zoe stands with Ukraine'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
4 votes
2 answers
206 views

Mappings with @="^E" result in @="" and do nothing

It seems that mappings with @="^E" or @="<c-e>" result in @="" and do nothing. For example if I use nnoremap ^N @="^E"^M then press ctrl-n I will get a @="" message and nothing happens. ...
Eric's user avatar
  • 318
4 votes
1 answer
359 views

How to autocomplete tag names containing a colon?

Sometimes I want to autocomplete a tag name containing a colon, for example g:netrw_gx. I've added to the 'tags' option the location of the tags file of the main documentation (which on my machine ...
saginaw's user avatar
  • 6,626
4 votes
2 answers
257 views

Do not delay mapped keys with common prefix

What I want to do is have two mappings. One mapped to <s-k>, and one mapped to <s-k><s-k>. What happens right now is that if I press <s-k> vim delays for timeoutlenms, and if ...
Max Coplan's user avatar
4 votes
2 answers
757 views

How to insert line in normal mode and stay at the same position

I tried to bind the following to insert a line after the line I'm currently on. Here it is: nnoremap <CR> o<ESC>k But this works weird. After inserting a new line cursor is at the ...
user3663882's user avatar
4 votes
2 answers
549 views

Creating a repeatable mapping in Vim

I find myself often aligning certain code blocks by inserting one or more spaces, like in the following situation: case something of Just a▉-> ... Nothing -> ... Here ▉ is the position ...
Severi Jääskeläinen's user avatar
3 votes
1 answer
2k views

Set mappings depending on file type

I'd like to set some file-type dependent mappings to quickly run files. For example, I have some mappings like these: nnoremap <silent><leader>z :w<CR> :!clear; gcc %; ./a.out<cr&...
domi91c's user avatar
  • 469
3 votes
1 answer
688 views

Some function keys switch cases of letters under and after the cursor

Foreword I use UltiSnips and have the following definitions in my .vimrc file let g:UltiSnipsExpandTrigger="<F8>" let g:UltiSnipsJumpForwardTrigger="<F8>" let g:...
Enlico's user avatar
  • 2,054
3 votes
1 answer
68 views

Proper way to enter in commands/lines in vimrc [duplicate]

Perhaps this is a trivial question, but I have seen both of the following ways to enter in lines into the vimrc file: :imap <leader>I <C-O>v <C-O>g And imap <leader>I <C-...
David542's user avatar
  • 2,147
3 votes
1 answer
109 views

How do I loop over a list of files from a visual selection?

Code in .vimrc which starts graphical Neovim on a filename when pressing gff % http://unix.stackexchange.com/q/277918/16920 :nnoremap gff :silent! exec "!gnvim " shellescape('<cfile>') <bar&...
Léo Léopold Hertz 준영's user avatar
3 votes
1 answer
392 views

How can a mapping have behavior dependent on the presence of a count?

I have this mapping to move by visible line when wrap is enabled nnoremap <silent> j gj nnoremap <silent> k gk But when I use a count (like 10 j), I expect to move by actual lines How ...
srghma's user avatar
  • 155
2 votes
1 answer
1k views

shortcut to open definition of variable in a vertical split

I use the vertical split command a lot :vsplit, and I also have click on ctrl] to look at the definition of a variable (after generating the Ctags). I would like to do a keyboard shortcut that does ...
abbood's user avatar
  • 603
2 votes
1 answer
2k views

Swap two shortcuts

I'm very new to vim and found bindings Ctrl-F for page down and Ctrl-B for page up kind of inconvenient. I intuitively try to page up with Ctrl-F and page down with Ctrl-B because F is higher than B. ...
St.Antario's user avatar
  • 1,087
2 votes
6 answers
1k views

How to delete a pair of parenthesis with backspace

I'm using vim to code C++ and I want to handle the parenthesis more easily. I knew that there was a plugin named Surround, which can help us but it is not what I expected. I set some shortcuts as ...
Yves's user avatar
  • 943
2 votes
1 answer
680 views

How to use the result of a function in a Vim keymap?

I have a function in Vim script that returns a string. " Return first directory with ".git" folder, if none is found " return the current directory function! s:project_root() for vcs in ['.git']...
Foobar's user avatar
  • 273
2 votes
1 answer
245 views

How can I give a keyboard shortcut (c-tab, c-s-tab) back to the terminal?

I am a long time user of git bash and its included vim and mintty. I updated from an older package including vim 8.1 to one with 8.2, and I have a new problem with just two mintty shortcuts. I haven't ...
Jack's user avatar
  • 23
2 votes
1 answer
170 views

Mapping <C-m> also creates a mapping for <CR>

I have a custom function and mapping: nmap <C-m> :MyMake<CR> This works as intendeded, the correct function is called etc. But it creates another mapping, running :nmap shows that CR is ...
flukus's user avatar
  • 275
2 votes
1 answer
165 views

How to make abbrev ignore my custom keybindings?

For example, I've mapped inoremap ( (), and if I do iabbrev if if(then it will expand to if(then) instead of if()then (the inoremap is executed after the iabbrev). Is it possible to make iabbrev ...
tga's user avatar
  • 409
2 votes
1 answer
516 views

How do you undefine existing functions and key maps?

I am looking at a scenario where in order to keep track of changes to my setup, rather than delete functions and keymaps defined in vimrc or other plugin I add commands which disable those functions ...
vfclists's user avatar
  • 867
2 votes
1 answer
787 views

How can I disable square-bracket-prefixed mappings, so I can then remap a single-press square bracket without having to wait for the "timeoutlen"?

I was looking through the default mappings for square brackets, and I really don't need most of that functionality. I would like to disable these mappings, then use nnoremap [ [[ and nnoremap ] ]] to ...
Luke Davis's user avatar
  • 1,327
1 vote
1 answer
91 views

Using VSCode key bindings inside Vim

Is there any way to use VS Code key bindings in Vim? I really like the VSCode linux key bindings, but would like to give a try to Vim without losing productivity.
S. zbr's user avatar
  • 19
0 votes
3 answers
85 views

Does a plugin exist which allows moving (across) the windows and split them without having to press Ctrl+w before each action?

I'm kind of fine with moving across windows using Ctrl+w followed by (sometimes a counter and) h, j, k, l, p, t, b, and I'm also fine with the similar key combinations to split the windows or to move ...
Enlico's user avatar
  • 2,054
0 votes
1 answer
155 views

Remapped keys won't work when combined

I have these lines in my .vimrc: " Remap movement nnoremap j h nnoremap k j ...
Adam Hunyadi's user avatar
109 votes
9 answers
238k views

What is the command for "Select All" in Vim and VsVim?

How do I select all the content of a file in Vim and VsVim? Like in other editors Ctrl-A does the job for select all.
Armaan's user avatar
  • 1,193
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
46 votes
8 answers
18k views

Why is using arrow keys in normal mode considered bad practice?

I have read it in many articles (e.g.) that it's a bad practice to use arrow keys in normal mode. Could somebody explain why is it considered a wrong practice, if at all?
Ankit Jain's user avatar
32 votes
1 answer
17k views

What does z stand for in vim?

I was looking up at tips on screen shifting and came across the following tips: zz = shift current line to middle of screen zt = shift current line to top of screen zb = shift current line to bottom ...
James Franco's user avatar
  • 1,031
28 votes
2 answers
19k views

File Type dependent key mapping

I'm trying to setup mappings for <C-]> that, depending on the buffer's file type, trigger different functions. For example, if I'm in a Javascript buffer, I want <C-]> to trigger :TernDef. ...
domi91c's user avatar
  • 469
22 votes
4 answers
5k views

What is the most convenient way to work with different keyboards in vim?

I sometimes need to write Greek words, but when I am using the Greek keyboard, hitting, say, <C-p> will be understood as <C-π> and not as the command I intend. This can be fixed with :map &...
Toothrot's user avatar
  • 3,099
20 votes
1 answer
463 views

Figure out which plugin is responsible for a key binding

I was about to answer a question but realized that my answer depends on a key binding provided by a plugin I have installed. Even worse, I don't know which plugin provides it. The only way I know to ...
Praxeolitic's user avatar
  • 2,388
19 votes
1 answer
19k views

What options are there to enter insert mode?

I used to enter insert mode by a never realizing that there is a system as to where the insert mode starts. I was sometimes annoyed that a would put the cursor after the first character of a line, ...
k0pernikus's user avatar
  • 2,857
18 votes
3 answers
3k views

Mapping with motion

I'm trying to understand how can I use operator with subsequent motion inside a mapping. For example: nmap /c c{here we pending for a motion}/<C-r>"<CR> The map should do the following: ...
Timur Fayzrakhmanov's user avatar
13 votes
2 answers
17k views

How to zoom to text in VIM via shortcut?

I want to zoom in VIM, like Sublime text or Atom, using CTRL + & CTRL - and CTRL 0 for reset to default font-size.
Fú sì dì nuò's user avatar
11 votes
2 answers
1k views

How to Insert a console.log for word under cursor in new line

Use case: In a JS file, I have an expression like: if (someVar === 'someValue') { statements; } and, for debugging purposes, I sometimes want to include a console.log in the line above: ...
Jordi Nebot's user avatar
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
10 votes
1 answer
10k views

What does CTRL-K do in insertion mode?

When I press ^K in my vim while I'm in insertion mode a '?' appears and then if I press a and then another character some strange characters appear the following are a few of the characters I could ...
yukashima huksay's user avatar
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
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