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
6
votes
1answer
872 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 ...
6
votes
1answer
2k 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 ...
5
votes
5answers
879 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 ...
5
votes
1answer
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" ...
4
votes
2answers
291 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 ...
4
votes
0answers
436 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, ...
3
votes
2answers
220 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] " | | | | | | ...
3
votes
2answers
8k 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 ...
3
votes
1answer
223 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 ...
2
votes
0answers
870 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 ...
2
votes
1answer
120 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&...
1
vote
2answers
297 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> ...
1
vote
1answer
697 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 ...
10
votes
2answers
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 ...
7
votes
1answer
474 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. ...
6
votes
1answer
243 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 ...
6
votes
1answer
160 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 ....
6
votes
4answers
647 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 "...
6
votes
1answer
736 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>(...
6
votes
1answer
2k views

Is it possible to map control forward-slash with vim

I'm wondering if it is possible to map control + forward-slash in vim. The mapping would be for normal mode if that makes a difference. I have tried <c-/> but that didn't work. I also tried ...
5
votes
1answer
844 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 ...
5
votes
1answer
1k 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 ...
5
votes
1answer
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 ...
5
votes
1answer
827 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.
5
votes
1answer
649 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 ...
4
votes
1answer
240 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 ...
4
votes
1answer
378 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....
4
votes
1answer
616 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 ...
4
votes
2answers
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 ...
4
votes
2answers
463 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 ...
4
votes
1answer
1k 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. ...
4
votes
2answers
596 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 ...
3
votes
1answer
68 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 [ ...
3
votes
1answer
32 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 ...
3
votes
1answer
90 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 &...
3
votes
2answers
625 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 ...
3
votes
1answer
279 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 ...
3
votes
1answer
235 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 ), ...
3
votes
1answer
131 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 ...
3
votes
3answers
181 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><...
3
votes
3answers
151 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 ...
3
votes
1answer
50 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 ...
3
votes
3answers
2k 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> ...
3
votes
2answers
412 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 ...
2
votes
1answer
61 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 ...
2
votes
2answers
113 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. ...
2
votes
1answer
210 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 ...
2
votes
1answer
114 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 ...
2
votes
1answer
157 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 ...
2
votes
1answer
404 views

Why is `vmap` for both Visual *and* Select mode?

Vim has both Visual and Select modes. Select mode is similar to Visual mode in some senses, but different in that when a printable character is typed, Vim will replace the selection with that ...