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
0
votes
1answer
19 views

How to prevent inoremap mapping from being "run" inside iabbrev? [duplicate]

I have the following abbreviation: iabbrev .d. [[2021-12-02]] I also have the following remap: inoremap [[ [[]]<Left><Left> The problem is, whenever I type .d. to get the date string, I ...
1
vote
1answer
42 views

Silently run two commands mapped by nnoremap in vim

I have this sort of command in my vim settings which read the output of some external command (here is date) and then run another external app. My problem is I want to run it without leaving current ...
4
votes
2answers
168 views

Double Press Override for 0 Key

My .vimrc remaps 0 to ^ in normal and visual+search modes. :nmap 0 ^ :vmap 0 ^ Ideally, I would like 00 to go to the true beginning of the line (i.e., what 0 does by default). Is this possible in a ....
0
votes
1answer
33 views

Macro won’t repeat when remapping <esc>

I remapped vv to <esc> inoremap vv <esc> "some notes cnoremap vv <esc> When using a macro, it can't be repeated. For example: qaifind^Mvvq,then @a and @@ works fine but 2@@ ...
0
votes
1answer
23 views

How to expand a value to place it in the ex command?

The goal is to create a mapping that will: create a mapping for the user --> remap does the trick that gets the current expression under the cursor --> expand('<cexpr>') will do the trick ...
6
votes
2answers
1k views

Ctrl-A and Ctrl-X doing the opposite of what they should

I had the following piece of Markdown text that I wanted to edit: * 2-6 for a moka pot * 7-10 for a drip machine * 5-12 for a pour-over When I had the cursor over the number 6 in the first bullet ...
0
votes
1answer
32 views

Can I make old Vim treat Alt key mappings <M-..> as Esc-prefixed, like Neovim and other CLI software(e.g. bash) do?

Do Vim users use Alt key for mappings? If yes, how exactly? As it is known, there are 2 common ways of handling Alt key in CLI software: either <Esc>-prefix or 8-bit. It seems like Vim chooses ...
0
votes
1answer
47 views

Key mapping for converting `((` to `\left( | \right)`

I would like to have something in .vimrc where when I type (( in insert mode, it automatically converts that into \left( | \right) with the cursor position at | in insert mode. Any ideas? I also would ...
1
vote
2answers
22 views

Insert mode remap to insert an underscore

I am starting to have issues with my pinky finger. I tend to write variables and functions using underscores as in my_variable. I would like to find a way to avoid having to press "shift + -"...
0
votes
0answers
24 views

Is is possible to include other behaviour in a keymapping which would normally invoke a <Plug>?

I am working with a plugin which exposes mappings via <Plug>. For example, let's say it has a mapping for <Plug>XYZCommand. Then, I can put the following in my ~/.vimrc: nmap a <Plug>...
0
votes
1answer
34 views

How to map a surround command?

I'm trying to map commands that are used with the vim surround plugin. Using vim surround you can type ysiW], for example, while in normal mode and it will surround the word at the cursor with ...
0
votes
2answers
31 views

How to deal with two vim plugins having the same mapping?

I have two plugins (todo.txt-vim and vim-buffergator) that both map the <localleader>b command (for .txt files at least). One plugin ended up dominating the other. I solved this by removing the ...
1
vote
1answer
39 views

How can I create a shortcut that saves the file and executes a sequence of shell commands?

I know that I can create shortcuts on a vimrc file like the following: :map <C-W> :w<CR> However, let's say I have some different commands that I can execute on my shell: notify-send &...
0
votes
1answer
13 views

How can I leave completion mode keeping the completion result in a binding when there's no popup?

Currently: I have some key binding A → ^X^O (in insert mode) to omni-complete something I have some key binding B → ^Ogj to temporarily do something in normal mode (in this case, move down a display ...
0
votes
0answers
29 views

Mapping Esc makes vim open in REPLACE mode [duplicate]

I've enabled hlsearch to highlight text after searching, $ grep hlsearch ~/.vimrc set hlsearch and now I want to clear the highlight, which I can do with :noh. I saw that I can assign this to esc key ...
1
vote
1answer
38 views

To toggle statusline colors when switching modes. Problem with C-C

I use the following code to have different statusline colors for Normal and Insert modes: highlight statusLine ctermfg=black ctermbg=red guifg=red guibg=black autocmd ...
0
votes
1answer
37 views

Is there a way to navigate windows without CTRL-W + ... ie. from the command prompt?

I want to reclaim CTRL-W for closing my terminal tab to get the same behaviour as in Firefox and other programs. Is there a command I can run to avoid having to press CTRL-W to navigate windows in vim ...
0
votes
1answer
28 views

Dump output with command line in vim with placeholder

I use :enew|pu=execute('scriptnames') for dumping output into a buffer. How do I write a mapping with this command line? For example, I press <F6> and it auto write the command line and jump to ...
1
vote
2answers
46 views

jedi-vim prevents mapping [[ to * and ]] to #

jedi-vim appears to prevent mapping [[ to # and ]] to * mapping does not alter behaviour produced by [[ or ]] in .py files when jedi-vim in bundle folder (and does alter behaviour in .py files ...
0
votes
2answers
30 views

Stop waiting for the rest of a normal mode command and accept the command typed so far

I have a mapping for m and a mapping for m/ in the same buffer, in Normal mode. If I type m, is there a way to tell Vim to stop waiting for the 2nd character, and to just submit the current command as-...
0
votes
1answer
19 views

Spaces in mappings: where to put them and where not?

The question is actually rather short, don't be afraid. :-) I'm Russian, and so to tweak Vim in a way it will understand its commands even if a Russian language is currently active, I have the ...
0
votes
2answers
39 views

how to make a word turn into certain commands in vim command line?

I want :cup in vim command line to turn into :tabdo call MapRunCmd()<CR> Hope that somebody can help me out PS: I've tried this nnoremap :cup :tabdo call MapRunCmd()<CR> but didn't like ...
2
votes
1answer
42 views

What is the purpose to use "==#" with empty string?

The following is from vim-sensible plugin: set incsearch " Use <C-L> to clear the highlighting of :set hlsearch. if maparg('<C-L>', 'n') ==# '' nnoremap <silent> <C-L> :...
0
votes
1answer
60 views

How to make a toggle function in .vimrc that toggles multiple configs of almost same type?

My .vimrc code autocmd FileType cpp nnoremap <F4> :RunWithFile autocmd FileType cpp nnoremap <F4> :RunWithFile ~/Downloads/ > output.txt && cat output.txt<s-left><s-...
0
votes
2answers
39 views

How to move `n` number char <left> in vim command line?

My init.vim code autocmd FileType cpp nnoremap <F4> :RunWithFile ~/Downloads/ > output.txt && cat output.txt I want my cursor position to be exact 31 times <left> in command ...
0
votes
1answer
44 views

Youcompleteme: shortcut key to format selection

According to this documentation :'<,'>YcmCompleter Format will format the selected text. I am struggling to map this to shortcut key <S-F2>. I have tried all of the following after having ...
0
votes
1answer
25 views

how to delete character which inserted automatically

I have the following mapping in my vimrc inoremap < <><left> but this statement conflicts with iabbrev cout cout<< and in insert mode I get cout<<>> how to delete &...
0
votes
1answer
31 views

How do I remap <c-x><c-k> to work with fzf.vim completion?

I'm trying to set up work completion with fzf.vim. Following the manual, I have: inoremap <expr> <c-x><c-k> fzf#vim#complete#word({'window': { 'width': 0.2, 'height': 0.9, 'xoffset': ...
1
vote
2answers
40 views

Completely expand `<plug>` mappings before execution into insert mode

Consider the following mappings: nmap <plug>test a123 nmap M <plug>test<plug>test If both <plug>test were expanded, vim would type out in the buffer "123a123". ...
0
votes
2answers
39 views

Reduce lag in mappings that frequently switch between normal and insert mode

As a concrete (although hyperbolic) example: nnoremap , a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>a<esc>...
0
votes
1answer
64 views

How can you create a vim mapping with a description

Context: I am using NeoVim on mac with a plugin called SpaceVim that I really like. SpaceVim basically loads a ton of mappings all mapped to the space bar. I also have added a ton of my own personal ...
3
votes
1answer
75 views

Inserting strings with `<plug>` inside `<cmd>`

When using <cmd>...<cr>, there are some special keys such as <plug> or <cmd> that are not allowed to be contained inside the block. Trying to execute the command will result in:...
1
vote
2answers
40 views

How to have a new keymap not block an existing one?

There is a built-in mapping Ctrl-g which presents the current filename immediately in the command area. I would like to augment this by tapping Ctrl-g again to copy the filename to my system clipboard ...
0
votes
0answers
13 views

Scroll mouse down triggers a mapping

Usually I know how to debug mapping. But I am not sure about this. When I do scroll down using the mouse, it enters insert mode and adds a line. I believe it is a bad mapping that is triggered (on ...
0
votes
0answers
41 views

How to keybind vim to a shell script

I'm new to vim and apologize if the question seems redundant, but I couldn't find a suitable answer. I have a shell script compile.sh that I would like to run each time I press some key (say, F8) on ...
0
votes
2answers
26 views

send key presses before previous command finishes

When running :browse oldfiles, if the output goes longer than one screen then you have to hit <space> for the next screen or <esc> to go to the menu where you can type the number of the ...
0
votes
0answers
30 views

Mapping ´ to / not working

I'm trying to map ´ to / and ¨ to ? as follows: nnoremap ´ / nnoremap ¨ ? It works fine if the first letter behind de map key is not any of i, I, a, A, o, O... guessing is something wrong with the ...
0
votes
1answer
33 views

Mapping won't work when cursor is at the last character of the buffer

I have the following mapping set in vimrc that saves the file and copy its content to clipboard: :map <F3> :w<CR>gg<S-V>G"*y It does what I want, except when I have the cursor ...
1
vote
1answer
46 views

Delete from cursor position until end of line in command-line mode

I am trying to emulate readline keybindings in insert and command-line modes (for example, <C-u> for deleting from cursor position to beginning of the line, or <C-w> to delete previous ...
1
vote
2answers
46 views

Tab to align cursor with next non-whitespace character in the line above (in insert mode)

How can we do this with vim? set hlsearch " Highlight search matches set incsearch " Highlight search matches as you type set visualbell ...
0
votes
1answer
28 views

force close windows and last empty buffer

when i open multi windows like bellow: vim foo.txt bar.txt then , if i'm closing foo.txt by :bw then ,i'm closing bar.txt by :bw vim still open ! , i must close by :q i don't want vim open if last ...
0
votes
1answer
16 views

Pseudo command :[line number][eof]d

How could I execute the entitled command, as is (I give a pseudo version)? My current workaround is to G to get the eof line number itself, then execute the command.
0
votes
1answer
29 views

Run another command if first command fails on keypress

Is it possible to combine the two commands map <F5> :w<CR>:exec '!python' shellescape(@%, 1)<CR> map <F6> :w<CR>:exec '!poetry run'<CR> so that when I press F5, it ...
0
votes
1answer
50 views

How to set a keybinding in Insert mode

I'm new to Vim, and I've read that a best practice in Vim is to begin a new Append with each line. In other words, instead of pressing <Enter>, it is more advisable to leave Insert mode, and ...
0
votes
1answer
27 views

Why does the cursor advance to the next character?

I have nnoremap Y y$ in my .vimrc. If I type "*y$, my cursor stays in the same spot on a word. However if I type, "*Y, the cursor is advanced one character. Why is that?
1
vote
0answers
49 views

Cricle through brackets mapping [closed]

I'm using bracket a lot and I'm trying to quickly circle through the bracket in both back and forth with the following mapping: nnoremap 0 f) nnoremap 9 F( Unfortunately, it does not work. Any ...
2
votes
2answers
83 views

Shortcut to exit insert mode and switch window?

While doing TDD I switch back and forth between windows often. I would like to reduce the number of keystrokes for this. I have tried both: inoremap <C-w> <ESC><C-w> and imap <C-...
0
votes
2answers
192 views

How to remap vim-commentary commands?

I have downloaded the vim-commentary plugin for commenting in vim. I was trying to remap the default shortcuts for the plugin so as to use ctrl+/ for commenting and remove commenting (default is gc). ...
0
votes
0answers
18 views

vim highlights the same occurence of a string and :nohl does not clear it

I have accidently pressed something and the string "#def" now always shows a white (as opposed to my regular dark) background: This occured while trying to comment out a function in python. ...
0
votes
1answer
41 views

Inconsistent behavior of dj and other motion-delete operations

I'm running Neovim 0.5.0 locally. I'm going through Harvard's CS50 course and they have an IDE (accessible here: https://ide.cs50.io/) with a shell that's running this version of Vim: version 8....

1
2 3 4 5
26