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
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
10k views

Mapping with the meta key

I'd like to bind some combinations to Alt-_some-key_, but not quite sure about how to do it correctly. Here is one of my current setup (example): vnoremap <ESC>c "+y This is because my ...
Dmitrii Bundin's user avatar
3 votes
3 answers
244 views

Substitute an insert-mode input immediately

I would like to type begin! in insert mode and having it immediately replaced by: begin [cursor here] end I considered mappings: :inoremap begin! begin end<Left><Left><Left><...
Maëlan's user avatar
  • 263
3 votes
1 answer
165 views

Beep upon using a mapping

Well, I try to use the following convention. ± (as unused key) is used for increase search where / is used for regular search. The implementation: set noincsearch nmap ± <esc>:set ...
eyal karni's user avatar
  • 1,186
3 votes
2 answers
487 views

How do I swap key bindings without breaking plugins?

I'm thinking about exchanging some keys while in non insert-mode so that the bindings that I use most are easier to reach (i.e. on the home row). How can I swap two keys without breaking the ...
Julien__'s user avatar
  • 139
3 votes
1 answer
100 views

Auto replace special programming characters

Programming in Javascript and similar syntax languages we use a lot of {} and (), more so than [] and the 90. Therefore we end up using SHIFT a lot. Is there a way to make it so that when I type [ ...
user1894919's user avatar
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
36 views

How can I make $ in LaTeX insert \( and \) automatically? [duplicate]

I'm writing a lot of LaTeX recently, and am used to hitting the $ key for inline math, but have heard that \( and \) is better (apparently it confuses vim less, especially with $$, which I'm also not ...
D. Ben Knoble's user avatar
  • 24k
3 votes
1 answer
101 views

Maps literally read < and > instead of the actual character

Situation Entire .vimrc: inoremap a <CR> Action: user types ia to enter insert mode and type a Expected result: a carriage return is entered into the document Actual result: the characters &...
ei2's user avatar
  • 59
3 votes
2 answers
1k views

How to add a [count] to a binding

How do you create a binding that behaves like yy but doesn't yank the leading white spaces? nnoremap <leader>f ^v$y Yanks one line and the ^J. Which is what I want but how do I add a [count] ...
nunmap's user avatar
  • 45
2 votes
1 answer
246 views

Why doesn't this macro work? (expression register)

According to this: nnoremap Q @='n.'<CR>: The @ key tells Vim to execute a macro. Rather than using a named register we use the expression register, which lets us specify the contents in ...
WalksB's user avatar
  • 457
2 votes
1 answer
4k views

Vim tool to show keyboard shortcuts for typed commands?

I am learning Vim by typing some commands in full rather than using keyboard shortcuts. Is there a tool or plugin that can show me the equivalent shortcuts if they exist, whether they are built in ...
vfclists's user avatar
  • 867
2 votes
2 answers
161 views

Why would you use `nnoremap gf gf` as SpaceVim does?

While writing this answer about vim-rails on SpaceVim, I found out these mappings set by SpaceVim, such as this one: nnoremap gf gf SpaceVim also creates similar mappings for all of the other gX ...
filbranden's user avatar
  • 27.7k
2 votes
1 answer
6k views

Neovim: Select an autocomplete option with <tab> instead of <return>

In the example below, how do I use <tab> to select HttpResponse the item instead of <enter>? I'd like to make this change permanent. This is using Kite within vim in case it matters.
WickedJargon's user avatar
2 votes
1 answer
254 views

Mapping specific for diff mode and vimdiff

My idea is that whenever &diff is true for a buffer, I would like some mappings to be active when that buffer is the current buffer. The following attempt works for when I open a session in diff ...
Enlico's user avatar
  • 2,056
2 votes
1 answer
294 views

Conflict between system compose key and insert mode meta key mappings

I use the right alt key as a compose key on my system, to easily draw diacritics and accent characters. In Vim, I unlock alt key mappings with this (from stackoverflow): " Allow <alt> key ...
Biggybi's user avatar
  • 2,649
2 votes
1 answer
997 views

Is there Vim plugin that can show keystroke maps or abbreviations for command after it is used?

Is there a tool or plugin for a learner which can display the keyboard shortcuts or abbreviated versions for commands after they are typed in? If for instance I use : to get the command line and ...
vfclists's user avatar
  • 867
2 votes
1 answer
131 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
2 votes
1 answer
387 views

Mapping for expression register with langmap active

I am using Vim with a QWERTY/BÉPO langmap setting which allows me to use the French dvorak-like keymap for inputting text and the QWERTY commands for the normal and visual mode. Background: I am ...
Lionel Hamayon's user avatar
2 votes
1 answer
174 views

Tabbing between files

I am trying to add the following lines to my .vimrc nnoremap <C-Tab> <C-w>w nnoremap <C-S-Tab> <C-w>W As per Vim Tutorial However I can't seem to get these to work. Other ...
avrono's user avatar
  • 121
2 votes
1 answer
574 views

How to escape pipe (|) in mapped substitution?

I wanted to define a mapping for flipping the texts on both sides of a pipe (|) character. For example, substitute dům|Haus with Hause|dům The substitution command :s/\([^|]\+\)|\([^|]\+\)/\2|\1/ ...
Hermann Schachner's user avatar
2 votes
2 answers
178 views

How to disable auto insertion of comment header when pressing enter, but keep auto insertion of header when auto wrapping comment?

When editing c and cpp files, this is the behavior I want to achieve: When typing a comment line of the form // Line..., pressing <CR> should not add the comment header // in the next line. ...
Diggs's user avatar
  • 75
2 votes
1 answer
352 views

better copy-paste multiple lines in visual mode where vim pastes after that visual chunk of code

I want to select multiple lines in vim, copy them, and paste after that chunk of code (with cursor at the beginning). yp doesn't work because in visual chunk of code, vim pastes after the 1st line of ...
Mega Bang's user avatar
  • 121
2 votes
1 answer
195 views

Mappings that work in nvim not working in vim [duplicate]

I have these key mappings that I use a lot in nvim, but they don't work in vim: " Move lines with Alt+Shift+j/k nnoremap <A-S-j> :m .+1<CR>== ...
paradroid's user avatar
  • 239
2 votes
0 answers
878 views

How do you map the back tick character (`) with a modifier key like ctrl? [duplicate]

Is there a way I can map a digraph like ` , with modifier key like ctrl together in vim like this NERDTree bind. map <C-n> :NERDTreeToggle<CR> It seems to be a tad bit more ...
PrimRock's user avatar
  • 343
2 votes
2 answers
1k views

inoremap only works after source

So I want to disable the arrow keys in insert mode. So I added the following lines at the end of ~/.vimrc: inoremap <up> <nop> inoremap <down> <nop> inoremap <left> <...
Jakube's user avatar
  • 435
2 votes
1 answer
308 views

Is it possible to supply arguments to inoremap?

Currently, I have the following map for cpp files: inoremap ;;f for<Space>()<Space>{<Enter>}<Esc>kkf)i Which essentially allows me to quickly setup a c-style for loop. ...
Yadeses's user avatar
  • 123
2 votes
1 answer
67 views

Why does g+ sometimes skip a leaf of the undo tree?

I'm trying to understand how to move in the undo tree with the following default mappings: u, <C-R>, g- and g+ Here's my understanding of things, which is probably wrong or incomplete. Each ...
saginaw's user avatar
  • 6,626
2 votes
3 answers
385 views

How to get tpope/vim-rails gf command to work with SpaceVim

I am using SpaceVim as Ruby on Rails IDE and installed the tpope/vim-rails plugin. Commands such as :Econtroller, :Emodel and :find are working just fine, but the gf command provided by this plugin ...
Bipin Manandhar's user avatar
2 votes
1 answer
198 views

Why do arrow keys behave differently in insert mode than in other modes?

Background I would like to disable arrow keys in all modes. This is what I tried: "EDIT: added remap for <esc> as per the comments inoremap <esc> <nop> inoremap <up> <nop&...
Attilio's user avatar
  • 347
2 votes
1 answer
407 views

Operator pending mode remaps not working

I'm trying to build a vimscript can be used with the Dvorak Simplified Layout. I.e., given that the keys on the keyboard plugged into the computer are laid out in the Dovark Simplified Layout (and the ...
Sergey Nikolayvich's user avatar
2 votes
1 answer
931 views

Map <C-/> on linux and windows [duplicate]

I knew that map / is _ on linux, but it not work on windows. What should I do to map it?
Dark.Hades's user avatar
2 votes
1 answer
47 views

Mapping behaves differently than manually typing

If ddkP is typed in normal mode on the first line then nothing happens¹. If :nnoremap + ddkP is executed and then + is pressed, the line is deleted. Why? ¹(if file only has one line then a new empty ...
user avatar
1 vote
1 answer
139 views

Vim - edit last action before using (.)

Related to but not duplicate¹ of Bundling command sequences together for repeat (.). The point (.) command is really useful to redo the last action (insertion, replacement, etc.). Sometimes I find ...
Gabriel Devillers's user avatar
1 vote
0 answers
49 views

mapleader & <Nop>: strange timeout behavior [duplicate]

I use <Space> as my leader key, with a short timeoutlen: let mapleader = ' ' set timeout timeoutlen=300 ttimeoutlen=5 Sometimes in normal mode, I hit <Space> then hesitate (maybe I ...
ivan's user avatar
  • 1,420
1 vote
1 answer
669 views

Display human readable meta/alt-(key) mappings

In :imap, I see mappings like: i © *@<C-R>=AutoPairsMoveCharacter(')')<CR> i ¨ *@<C-R>=AutoPairsMoveCharacter('(')<CR> i î *@<Esc>:call ...
Tom Hale's user avatar
  • 2,451
1 vote
1 answer
278 views

How do I enable mouse in netrw only (terminal vim)?

I would like to be able to use my mouse to scroll and click on directories to expand them in netrw. I don't want the mouse to be on for any other filetype/buffertype, so that I can still highlight/...
wxz's user avatar
  • 131
1 vote
1 answer
481 views

Is it possible to map one key to two commands, doing 2nd command only if first fails

I want to map the tab key to <c-w>w to switch windows when there is more than one window open. But if there is only one window but multiple tabs, I want it to detect that there is only one ...
domoremath's user avatar
1 vote
1 answer
2k views

How can I make a single mapping take effect for both Normal mode, Insert mode, and Visual mode?

I want to disable the arrow keys in Normal mode, Insert mode, and Visual mode. To achive this, I've created 12 mappings (see below) - 4 mappings for each mode. Is there a way to achieve the same using ...
Shuzheng's user avatar
  • 1,175
1 vote
1 answer
74 views

How to create ctrl map in command directly?

I'm trying to toggle some ctrl maps in command directly, it didn't work as expected: com Test0 nnoremap <c-j> :echo "c-j"<cr> com Test1 nnoremap <c-h> :echo "c-h"<cr> com ...
dedowsdi's user avatar
  • 6,068
1 vote
0 answers
201 views

Re-mapping Swedish letters

On a Swedish keyboard to the right of the keyboard one has: O, P, Å L, Ö, Ä [ and ] are extensively used by Vim, and hard to reach on my keyboard, so therefore I've mapped these to Ö and Ä in my ....
Max's user avatar
  • 153
1 vote
1 answer
863 views

How can I change the cursor moving on ctrlp?

I want to change the key mapping when I run CtrlP. For example, if I press ctrl+p to run CtrlP, type in something, and try to move the cursor to choose a file, I want to use ctrl+j to move down, and ...
Blaszard's user avatar
  • 527
1 vote
1 answer
371 views

Why does Vim interpret â as Alt-b in a mapping?

I have the following code in my vimrc: function! s:WordPos(dir) abort return a:dir ==# 'right' \ ? searchpos('\<', 'nz', line('.'))[1] \ : searchpos('\<', 'bn', line('.'))[1] ...
saginaw's user avatar
  • 6,626
1 vote
1 answer
491 views

How to read/get the number of lines of code in the buffer or a directory?

We can read some information about the current buffer, by hitting g C-g; for example: Col 3 of 2; Line 28 of 106; Word 144 of 474; Byte 916 of 3396 And we can capture the same information in a ...
user9433424's user avatar
  • 6,068
1 vote
2 answers
623 views

How to make hjkl with shift more flexible?

Currently I have the following maps: nmap J 5j nmap K 5k nmap L 5l nmap H 5h This works great if I hit Shift j, it moves down for quick cursor movement. However if I let go of shift while holding j ...
Jason Basanese's user avatar
1 vote
1 answer
392 views

Custom Number Format for CTRL+A

The ctrl+A command to increment numbers is super handy, but it doesn't work in languages that don't use C-style 0x and 0 prefixes for hexadecimal and octal numbers. In SystemVerilog, hexadecimal ...
jtst's user avatar
  • 13
1 vote
1 answer
590 views

How do I use regular expressions in ternary statements / keymappings?

I'd like to create a keymapping with a conditional statement, so that it behaves differently when a given line is blank. This thread gave me the following snippet, which is great – except that it ...
Ryan Lue's user avatar
  • 861
1 vote
1 answer
103 views

How do I make the current tab's windows equal width but leave their heights?

I know <C-w> = equalises window sizes but I often want to keep the heights as they are. I have set noequalalways in my .vimrc as leaving it on ruins layouts when temporary windows open (like ...
Walf's user avatar
  • 284
1 vote
2 answers
354 views

How to enable disabled movement keys in netrw?

Recently I started using and learning Vim. I turned off movement keys in my .vimrc file like this: noremap <Up> <NOP> noremap <Down> <NOP> noremap <Left> <NOP> ...
Igor R.'s user avatar
  • 113
1 vote
0 answers
1k views

How to map the slash key "/"

I am trying to map the NERDCommenterToggle command from the nerdcommenter plugin. I want to use "Ctrl+/" for this: vmap <C-/> <plug>NERDCommenterToggle nmap <C-/> <plug&...
rsaavedra's user avatar
  • 121