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
9 votes
1 answer
349 views

Why does `<Bar>` behave like `|` in the `:command` command in Vim?

Here is the list of experiments I performed that shows that <Bar> is treated as literal <Bar> in some commands but it is treated as | in the :command command. I am trying to understand why ...
Lone Learner's user avatar
9 votes
3 answers
3k views

Why do I get a missing quote error when using the following in a mapping using execute and normal?

The command is nnoremap <leader>; :execute "normal! mqA;\<esc>`q" If you then press <leader>;, you will E114: Missing quote: "normal! mqA;\ followed by E15: Invalid expression: "...
Alice Ryhl's user avatar
9 votes
1 answer
415 views

Ctrl-A and Ctrl-X seemed to be switched sometimes!

Occasionally, I will press Ctrl-x and Ctrl-a to increment/decrement the highlighted number, and the opposite operation will happen. This usually happens when I'm working with with registers (q). ...
user1717828'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
9 votes
1 answer
622 views

Is it possible to execute a :normal command ignoring user-defined maps?

Let us suppose that a user maps - to <nop>. How can I, as a script writer, execute a :normal command that correctly uses the default behaviour of -?
ninrod's user avatar
  • 219
8 votes
1 answer
3k views

Percent key ( % ) matching behavior for angle brackets ( < > )

In vi it's very helpful to be able to place the cursor on a '(' or '{' or '[' character, press the '%' key, and move to the matching ')', '}', or ']'. But this does not work for me with angle ...
Clovis_Sangrail's user avatar
8 votes
1 answer
239 views

Why is the previously inserted text reset after using an arrow key?

From help :help i_ctrl-a: CTRL-A Insert previously inserted text. {not in Vi} Let's say I have an empty buffer and I'm in normal mode. I type i to go in insert mode. I type (), then move the ...
saginaw's user avatar
  • 6,626
8 votes
1 answer
16k views

How to enter tilde (~), back tick (`) and special chars with a non-US keyboard?

I usually use Vim with an Italian keyboard (I'm from Italy), (mainly in an Ubuntu Linux Virtualbox guest from a Windows host). I have problems when I have to enter some frequently used characters (...
Giorgio Robino's user avatar
7 votes
1 answer
976 views

why can't I map <Space> to <C>?

I found that it's really hard for me to hit Control and other keys simultaneously, and I discovered that the space key is rarely used, so I decided to map it to Control . Thus, when I want to hit ...
Alex's user avatar
  • 1,075
7 votes
1 answer
2k views

Mapping Ctrl-Z in insert mode?

I often Ctrl-Z to the command line. Is there a way to do that in response to hitting Ctrl-Z in insert mode? The iabbrev command does not seem to work.
Yossi Gil's user avatar
  • 745
7 votes
4 answers
1k views

Prevent the cursor from moving to the start of the yanked text?

Vim help's change.txt states that Note that after a characterwise yank command, Vim leaves the cursor on the first yanked character that is closest to the start of the buffer. This means that "...
Vitor Eiji's user avatar
7 votes
1 answer
553 views

Create mappings/macros with keydown?

Is it possible to create mappings or macros based on keydown and keyup events? For example, if you press i you enter insert mode, and if you press esc you leave insert mode and enter normal mode. ...
Tyler Durden's user avatar
  • 2,041
7 votes
1 answer
1k views

How can I prevent plugins from overwriting my key mappings?

In my vimrc I have: nnoremap <F4> :SyntasticToggleMode<CR> And this works. But I also have the unicode.vim plugin installed, which overrides this mapping: if !hasmapto('<Plug>(...
Martin Tournoij's user avatar
7 votes
2 answers
4k views

How to remap "i" in netrw?

I remapped my hjkl keys to ijkl, but in netrw, "i" switches view styles. How to change this? Is it possible to change this?
Peret Finctor's user avatar
6 votes
1 answer
1k views

Map 'Jump to mark line' to 'Jump to mark position'

Let's say I've set a mark a via ma. Then 'a will bring me to the first non whitespace character of the line. However `a will bring me to the exact position of the mark a. I prefer the second ...
user avatar
6 votes
2 answers
4k views

What is the difference between unmap and mapping to <Nop>?

My version is : NVIM v0.3.0-dev I'm trying to replace mappings with w mappings. Initially I came up with nnoremap <leader>w <c-w> nnoremap <leader>wb <c-w>s nnoremap <...
3N4N's user avatar
  • 5,269
6 votes
1 answer
1k views

Pressing Shift-Backspace in insert mode types '^?' instead of backspacing

When I mess up typing an uppercase letter, I usually hold Shift while pressing the Backspace. Instead of backspacing, it types ^? (to my frustration). Google tells me that ^? is the "delete" ...
PoorProgrammer's user avatar
6 votes
1 answer
195 views

Swap two keys in such a way that works with both `f` and macros

I have swapped my number keys with their symbols, because the symbols occur much more frequently than numbers in many programming languages, like C or Haskell. You can see my key-swap function in my ....
Shahbaz's user avatar
  • 549
6 votes
1 answer
728 views

Insert a newline after punctuations

I'm writing a report in LaTeX that I keep in a Git repository. In order to make the most out of Git, I would like to keep each sentence on its own line. I.e. for each dot, exclamation mark and ...
lklun's user avatar
  • 63
6 votes
2 answers
607 views

Sticky shift - or getting <shift> with letter combinations

I use the shift keys a lot and it is an unnecessary strain on the pinky. The enter and backspace functionalities are conveniently located under a dominant finger (ctrl-m and ctrl-h). Similarly: Is ...
Emre's user avatar
  • 217
6 votes
1 answer
366 views

How to move the cursor to the next reference, option, heading in man pages?

If we load the built-in man.vim filetype plugin by writing in our vimrc: runtime ftplugin/man.vim We can read a man page inside a Vim buffer, using the :Man command described in :h :Man: MAN ...
user9433424's user avatar
  • 6,068
6 votes
1 answer
2k views

How to use <Leader> in a normal command?

In the command-line mode or in a vimscript I can use the following to duplicate a line: normal! Yp Now let's says that I map my leader key to do that: nnoremap <Leader>a Yp. If I use this key ...
statox's user avatar
  • 48.5k
6 votes
1 answer
2k views

Cycle through autocomplete menu using tab

I am activating my autocomplete menu in vim using: inoremap <C-@> <C-n> and after it opened and only when it opened I would like to use the "tab" key to cycle through the menu. But when ...
Silence and I's user avatar
5 votes
1 answer
1k views

Visual block editing: map i

How to map i to start editing on visual block mode? I want the same behavior for <shift>-i and i.
adelarsq's user avatar
  • 584
5 votes
1 answer
2k views

How can I map Alt-< or Alt->?

I try to create a mapping for Alt < and Alt >: inoremap <M-<> foo-bar-baz inoremap <M->> baz-bar-foo This doesn't work, most probably because < and > are themselves ...
René Nyffenegger's user avatar
5 votes
1 answer
754 views

Understanding :help set-termcap

I would like to define some mappings involving key combinations like <S-F1> or <A-d>. For example something like this: nnoremap <A-d> :echo "hello world!"<cr> However, on my ...
saginaw's user avatar
  • 6,626
5 votes
1 answer
296 views

Changing -- INSERT (lang) --

When keymap is set and iminsert is 1, it says -- INSERT (lang) -- at the bottom of the screen. Is there an easy way to change this string (or just the lang string)?
Toothrot's user avatar
  • 3,099
5 votes
2 answers
2k views

How to add accent to letters in normal mode?

I want to edit words that need accents (á) were they are missing. It's no problem to write down accents in insert mode: it is just "' + letter", so I can easily write á, é, í, ó, ú. How do get ...
nilon's user avatar
  • 197
5 votes
1 answer
70 views

Yanking results displayed in status line

After pressing <C-g> in normal mode, prints useful information in the status line. How can I yank this text?
Zach Wiebesiek's user avatar
5 votes
5 answers
1k views

Delete text between two $ symbols in gvim

I understand that we can use da{ to delete a whole {} block in vim. I am wondering if there is a corresponding version with { replaced by $ (similarly for di{) as this would be very useful for people ...
weirdo's user avatar
  • 153
4 votes
1 answer
337 views

Modify `iskeyword` for keyword-local completion only

Context Some time ago, I added the following line to ~/.vim/after/ftplugin/sh.vim to make working with parameter expansions easier: setlocal iskeyword+=$ This is nice to be able to e.g. ysiw" via ...
D. Ben Knoble's user avatar
  • 24k
4 votes
3 answers
4k views

How to map Ctrl-(? [duplicate]

I am trying to map Ctrl( in insert mode. However, Vim does not recognize the key binding. This is what I currently have: " Insert a pair of brackets using Ctrl-( inoremap <C-(> ()<left> ...
Flux's user avatar
  • 941
4 votes
0 answers
448 views

How to remap <C-[> on linux [duplicate]

I have the same vimrc file for both Windows and Ubuntu environments. It works fine on both platforms, except for one difference. The line: nmap <C-[> <C-t> is working fine on Windows, ...
user avatar
4 votes
1 answer
858 views

How to remove the mapping from Ctrl-[ to Escape? [duplicate]

If you have an American English keyboard, pressing Ctrl-[ (control plus left square bracket) is equivalent to pressing Esc. This provides an easy way to exit from insert mode. source: https://vim....
Steven Roose's user avatar
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
4 votes
1 answer
117 views

How to map "q" to "<cr>" for the hit-enter prompt?

I regularly press q to exit the -- more -- prompt in Vim. I often mistakenly use this same key to exit the hit-enter prompt, which then starts recording a macro after a subsequent key is typed. I'd ...
dannyadam's user avatar
  • 472
4 votes
1 answer
2k views

Having issues maping <C-j> and <C-h> in vim [duplicate]

I tried to remap my split navigation like explained here. Moving to the top or right split works but ther other two just do nothing. I tried the same without a .vimrc which led to the same result. ...
Benjamin Zinschitz's user avatar
4 votes
2 answers
575 views

How to trigger <tab> auto completion in a key mapping?

I'd like to map Leader+e in normal mode to showing the auto completions of files to edit. I tried nnoremap <leader>e :e<space><tab>, but it shows :e ^I, where the tab gets rendered ...
danijar's user avatar
  • 391
4 votes
3 answers
1k views

Unmap all combinations starting with certain key

I am experimenting with default key mappings and am considering remapping the g key entirely. But first I would like to turn off all the existing mappings that g has. For now I am using this kind of ...
Karolis Koncevičius's user avatar
4 votes
2 answers
930 views

mapping to map <return>

I'm trying to create a mapping to create a mapping such that pressing <C-return> presents me with :nnoremap <return> : to which I can then add a custom command. The following does not work ...
Octaviour's user avatar
  • 932
4 votes
2 answers
773 views

Open markdown filename under cursor like gf, and jump to the section?

I have the file /path/a.md which has many sections as follows: # abc this this the content of section abc # def this this the content of section abc ## defg this this the content of subsection defg ...
Lerner Zhang's user avatar
3 votes
1 answer
1k views

How can I map Ctrl-Alt-<letter> mappings in vim?

My keybindings are consistent and work across different operating systems, terminal emulators, browsers, tmux, etc. There are no clashes, but this sometimes means remapping things in some instances. ...
paradroid's user avatar
  • 239
3 votes
2 answers
230 views

How to automatically break down the description of a command?

I found the following description of a command which sets up which items must appear in the status line, here: set statusline=%F%m%r%h%w[%L][%{&ff}]%y[%p%%][%04l,%04v] " | | | | | | ...
user9433424's user avatar
  • 6,068
3 votes
2 answers
3k views

Getting Shift-Tab to work in VIM Insert mode

I've been trying to get Shift+Tab or <S-Tab> to work in VIM and I can't figure it out. I read this document, but the remap solution only works for normal mode (because if I press Shift+Tab, VIM ...
Luke Davis's user avatar
  • 1,327
3 votes
1 answer
101 views

Skip to next batch of search results (or find next non-match)?

So you search /needle, and end up trapped in a haystack of result lines. Is there a quick way to skip to the first non-matching line (and then the next batch of results)? E.g. I'm viewing the results ...
usretc's user avatar
  • 345
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
3 votes
1 answer
371 views

Remap keys conflicting with plugin

I want to remap Ctrl+y(scroll up) to up. However, I also have yankring mapped to Ctrl+y, and I wish to keep yankring's mapping. Now if I have this in .vimrc: map <Up> <C-y>, pressing up ...
noobcat's user avatar
  • 55
3 votes
1 answer
357 views

How to toggle syntax with a single key

To turn on syntax we normally use: :syntax on and to turn it off we do: :syntax off. I would like to define a single key, maybe using <expr> to toggle syntax. My problem is how to get the ...
SergioAraujo's user avatar
  • 1,097
3 votes
1 answer
291 views

How to jump to a next or previous specific character ignoring linebreaks and not destroying highlight or overwriting my registry?

I have not found much use for ()[]{}, and so I want to map them so it does a find command, jumping to the previous instance of that particular character. Thus, ) will jump forward to the next ), ...
Anon's user avatar
  • 835
3 votes
1 answer
100 views

custom mapping to make dge consistent with dw, de, and db?

Situation Recently I was investigating the behaviour of word motions in vim and to me it seems like ge is grossly inconsistent with the other 3. Here is an example with ^ showing the cursor: word1 ...
Karolis Koncevičius's user avatar