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
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
9 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
2 answers
940 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
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
1 answer
347 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
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,312
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
246 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
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
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 is on strike'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
  • 227
6 votes
2 answers
390 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
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.9k
5 votes
2 answers
666 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
4 votes
2 answers
781 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
1 answer
384 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,706
4 votes
2 answers
215 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
2 answers
284 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
3 votes
1 answer
408 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
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,365
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
110 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
747 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,172
2 votes
1 answer
548 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
  • 877
2 votes
1 answer
834 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,397
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,107
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
  • 673
2 votes
1 answer
272 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
188 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
786 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
187 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
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
  • 983
1 vote
2 answers
406 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. br's user avatar
  • 19
0 votes
1 answer
159 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
0 votes
3 answers
88 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,172
116 votes
9 answers
251k 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,263
52 votes
7 answers
10k 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
34 votes
1 answer
19k 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,081
28 votes
2 answers
20k 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,119
21 votes
1 answer
585 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,448
20 votes
1 answer
20k 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,957
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
11k views

Is there a command to enter Visual Block mode?

I've set up a bunch of key mappings that would cause many Vim users to cringe. Now I am unable to get into Visual Block mode using Ctrl-V (Ctrl-Q isn't mapped, but it doesn't work). Is there any ...
Dan's user avatar
  • 485
13 votes
2 answers
18k 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
1 answer
11k 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
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
11 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
11 votes
2 answers
3k 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,092