Skip to main content

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
1 vote
1 answer
97 views

Why do these two nearly-identical bindings take different time to execute?

I like to open Vim with many buffers open, and switch between them using plugins. Because I work a lot in C++, I like to have a way to quickly switch between header files and their corresponding ...
Svalorzen's user avatar
  • 143
0 votes
1 answer
35 views

remap with variables in the rhs

I want to remap <c-b> to foo<c-b>, being foo a number. However, it seems it won't work with function local variables. For instance, the following works: vim9script var foo = 4 if !...
Barzi2001's user avatar
  • 760
4 votes
1 answer
284 views

How to completely change the `f` key to a `/` and the `F` key to a `?`

I use neovim latest version 0.10.1, I want to convert the entire function of f button to / button and F button to ?, because I often use / and ? function to search for more than just f and F, I ...
tungsondkh's user avatar
1 vote
1 answer
50 views

Part of a mapping is a text object and I wish to pass it to a function. How to do that?

I wish to have a mapping like the one included in the following code: var a = 'foo' var b = 'bar' xnoremap s<text_object> <ScriptCmd>Myfunction(a, b, <text_object>) If for example I ...
Barzi2001's user avatar
  • 760
0 votes
1 answer
27 views

How to automate console.log random string with word (or selection) under cursor?

I am using this code snippet for adding console.log: imap cll console.log()<Esc><S-f>(a " Console log from visual mode on next line, puts visual selection inside parentheses vmap cll ...
illdo's user avatar
  • 1
1 vote
0 answers
61 views

Mapping ESC sequences doesn't work

I'm using wezterm to forward Shift keypresses in the combination CTRL+SHIFT+c to nvim. This is my conf: ... { key = 'c', mods = 'CTRL|SHIFT', action = wezterm.action_callback(function(win, ...
glades's user avatar
  • 23
1 vote
1 answer
117 views

Map Shift+Alt+Period

emacs uses shift + alt + > and shift + alt + < for home and end (Note < > are the same as , . since shift is pressed anyways). Is there a way to map this in vim? This doesn't seem to work: ...
AvidSeeker's user avatar
1 vote
1 answer
48 views

Map key to interrupt Insert-mode completion

Often, insert-mode completion can take some time (e.g. <C-x><C-l> on a common prefix in your project). <C-c> interrupts this. I'd like to map another key to also have this interrupt ...
user22476690's user avatar
1 vote
0 answers
29 views

How to find the correct "keystring" for an input keystroke in neovim?

I want to map the keystroke Ctrl + § to :Telescope oldfiles in neovim. I naively tried this: vim.keymap.set('n', '<C-§>', ':Telescope oldfiles<CR>', {noremap = true, silent = true }) but ...
glades's user avatar
  • 23
0 votes
2 answers
140 views

How do I synchronize system clipboard and nvim clipboard?

I would like to synchronize the system and nvim clipboards so I don't have to do anything extra to copy and paste. I want to do (since I am on MacOS) command c to copy and command v to paste, inside ...
BigMistake's user avatar
2 votes
3 answers
422 views

Correctly escaping <CR>: how can I map a command to send the literal string "<CR>" to a vim function?

I'm currently trying to create a mapping that sends a command and a newline to an open terminal using nnoremap and term_sendkeys(). term_sendkeys() interprets the \<CR> string as a newline, so ...
Martín Fixman's user avatar
0 votes
2 answers
44 views

Copy lines/ blocks of lines up or down like in vscode

In VSCode I had a keybinding I really liked. Basically you could use Alt+Shift+Up/Down arrow to copy the selected block of code above or below the active selection. Now that I switched to Vim I ...
glades's user avatar
  • 23
7 votes
1 answer
879 views

vi (an old AIX vi, not vim): map: I can search, move, yank, or dd, but cannot paste

On regular AIX vi (not vim, just plain old vi): I tried to do the following map, but it fails on the "P" or "p" part with the message Cannot use the put command while inside a ...
Olivier Dulac's user avatar
0 votes
2 answers
41 views

Using filename in mapped command

I am on Neovim, and have ToggleTerm installed. I would like to do :nnoremap <leader><leader>r :ToggleTerm<cr>my_interpreter %<cr> but this will just open ToggleTerm, and run ...
CocoaNut's user avatar
0 votes
0 answers
112 views

How can I resolve "WhichKey: WARNING conflicting keymap exists for mode [...]"

How can I find the source of these errors as reported by :LazyHealth which-key: require("which-key.health").check() WhichKey: checking conflicting keymaps - WARNING conflicting keymap exists ...
Evan Carroll's user avatar
  • 1,493
0 votes
1 answer
129 views

How can I chain multiple commands in one mapping?

These two mappings work separately: nnoremap <leader>zs :let @+=substitute(substitute(join(filter(getline(1,'$'),'v:val=~"^source:"'),"\n"),'^\(source:\s*\)\(.*\)$','\2',''),'...
JitteryNutmeg's user avatar
0 votes
1 answer
50 views

Copying the previous block of code

// some // code 1 // some // code 2 // cursor here I wish to quickly copy and paste the immediate previous block of code (2). By a block, I mean all code that is between two empty lines (...
DatBoi's user avatar
  • 111
0 votes
1 answer
84 views

Remapping telescope's move_selection doesn't work

New to vim. Using Dvorak layout. Trying to remap the move_selection_{next,previous} to t for next and c for previous, to match my text editing mappings. Here's the code: { "nvim-telescope/...
splaytreez's user avatar
-1 votes
1 answer
37 views

How to make mappings for "jump to after next occurrence of character" / "jump to the before previous occurrence of character"?

There are standard keybindings: fx - jump to next occurrence of character x tx - jump to before next occurrence of character x Fx - jump to the previous occurrence of character x Tx - jump to after ...
Anton Samokat's user avatar
0 votes
0 answers
36 views

LINUX OS - Window resizing keymaps not working

This question follows this one. I set some custom keymaps to ease window resizing, such as nmap <A-j> <C-w>-. However, they do not seem to work in any window. But, if I play the command ...
mEm's user avatar
  • 157
1 vote
1 answer
37 views

Remaps to move across windows do not work when in netrw window

Can someone explain why remaps to navigate across windows like nmap <C-h> <C-w>h does not work when in the netrw window? Is there any reason why? Is there a setting to enable them?
mEm's user avatar
  • 157
0 votes
1 answer
38 views

What does this command do?

In vim fandom wiki I found this command: nnoremap \z :setlocal foldexpr=(getline(v:lnum)=~@/)?0:(getline(v:lnum-1)=~@/)\\|\\|(getline(v:lnum+1)=~@/)?1:2 foldmethod=expr foldlevel=0 foldcolumn=2<CR&...
Antonio's user avatar
  • 289
0 votes
2 answers
91 views

How do I remove the delay when using a key remapped to `k`?

I use the Dvorak layout and am trying to start using Neovim. By default, the arrow buttons were scattered all across the keyboard, so I created this script to remap them: local function noremap(...
splaytreez's user avatar
1 vote
2 answers
46 views

How do I swap surround's spacing for opening vs. closing delimeters?

I use vim-surround all day, and it's a constant annoyance to me that I have to reach a little bit farther to hit the closing delimiter when I don't want spaces around the delimited content (which is ...
Eric Burgess's user avatar
1 vote
1 answer
88 views

How do I start a search with the currently selected text?

What to add to init.lua such that / set the CLI with: / followed by the selected text if any / otherwise
user17227456's user avatar
0 votes
1 answer
119 views

How to hide keybinds in which-key.nvim depending on buffer type?

I have been refactoring my nvim setup. I manage my plugins with lazy.nvim. I have vimtex plugin, with following binds: local wk = require"which-key" wk.register({ l = { name = &...
Vladyslav Rehan's user avatar
0 votes
2 answers
48 views

How to get default Generic Keywords autocomplete functionality when LSP is in use?

I used to rely heavily on the default autocompletion provided by the Ctrl + n keys in the insert mode. But when I started to use NeoVim and its LSP functionality, the keys started to provide a ...
d.k's user avatar
  • 734
0 votes
1 answer
33 views

Neovim configuration to join lines with BACKSPACE [duplicate]

On insert mode, at the end of the line, how to make Neovim joins the current line with the next one when hitting Del? And harmoniously, on insert mode, at the start of the line, how to make Neovim ...
user17227456's user avatar
3 votes
2 answers
642 views

Is there a reliable way to know whether a keybinding is already in use?

When making a custom keybinding, it's always in the back of my mind that I might be conflicting with some other keybinding, especially one from a (not loaded) plugin. Hence the act of pressing the ...
stevec's user avatar
  • 133
0 votes
1 answer
40 views

<CR> behavior unexpectedly changed in normal mode

I recently made a bunch of changes to my vim configs and I later noticed that the enter/<CR> behavior on normal mode has changed. I used to be able to select and execute a line in the command ...
Daniel Baulig's user avatar
0 votes
2 answers
43 views

Any commands to switch to the window on the far left or right?

Let's say I have a grid of 3x2 windows open and I am focused on the bottom right one. I want to switch to the one on the bottom left with one command, not move left twice. Vice versa as well. There's &...
Oneechan69's user avatar
1 vote
1 answer
25 views

Paste and enter insert mode at the beginning of line, terminal bash Lunarvim

When editing a text file, p and I pastes what I copied and gets me to enter insert mode at the beginning of line. But in terminal (executed by term bash) this not works. p pastes somthing, but I or i ...
Crispy13's user avatar
  • 113
1 vote
1 answer
46 views

Show only 1 line from the prior screenful?

How may I tweak the Vim <C-F> command to show only 1 line from the prior screenful? Well I tried to map a normal mode command that scrolls forward by 1 line less than the number of lines in the ...
gregrwm's user avatar
  • 13
0 votes
1 answer
38 views

Get relevant script for (all) mappings

vim.api.nvim_get_keymap('n') does return a table with lnum (line number) , but not with the name of the script that set it (or path). I only know that verbose nmap .. does it, but prefer to avoid it (...
eyal karni's user avatar
  • 1,186
0 votes
2 answers
43 views

Select current Line from normal mode without changing cursor position AND without selecting the new line character at the end

What I am asking about can be done using multiple ways but none of them fully achieves what I want. For an instance : 0vg_ selects the current line without the new line character at the end but ...
pic810's user avatar
  • 1
0 votes
0 answers
23 views

Is there a way to define a "toggle breakpoint" mapping in termdebug?

How to implement a there_is_a_breakpoint_on_this_line condition to be used in the following if-then-else block in termdebug? if there_is_a_breakpoint_on_this_line <cmd>Clear else <cmd&...
Barzi2001's user avatar
  • 760
1 vote
2 answers
28 views

How do I bind a key to open an ipython shell in a new split

I want to bind a key that will open a new terminal running ipython in a vertical split. So far I have figured out opening a new terminal in vertical split: local map = vim.api.nvim_set_keymap opts = {...
Anurag Patil's user avatar
1 vote
1 answer
39 views

Can I bind with numbers in the binding, d{n}c to d{n}l for example?

I am trying to bind my keys in such a way that if I press d, then a number, and then c it deletes that number of characters, like d, number, l would do. So for example if I press d5c it would do d5l. ...
vosjedev's user avatar
0 votes
1 answer
81 views

Swap K and T not working

I'm trying to swap the K and T keys. T should give me help, K should do "till (backwards)" Moreover, the help command only makes sense in normal mode; the till action makes sense in normal, ...
ElRudi's user avatar
  • 201
2 votes
2 answers
65 views

How can I jump outside the scope of LaTeX delimiters?

I want to define insert mode mappings that will jump outside the scope of any delimiter I'm in (forward/backward). Where "delimiter" is in the broad sense of LaTeX delimiters, so not only {},...
Ur Ya'ar's user avatar
  • 127
1 vote
1 answer
39 views

Ctrl+w Shift+n after :term does not start a normal window

In Vim, you can start the terminal by :term, and Ctrl+WShift+N allows you to treat the terminal window as a normal Vim window. I tried the same in NeoVim, but it does not work. Is it an expected ...
T_T's user avatar
  • 189
0 votes
0 answers
36 views

How to fix a direction keys remapping bug?

I don't want to change the default position of my right hand to use the direction keys, also I'd like to be able to use them in the insert mode. So I've got the following part in my .vimrc file: "...
Fyodor's user avatar
  • 1
1 vote
1 answer
316 views

Neovim command mode keymap without executing

In my vimrc I had a mapping to read the word under the cursor (<C-R><C-W>) and put it on the command line as an argument ready to search with the GrepperRg tool: nnoremap <leader>gg :...
Noel Evans's user avatar
1 vote
2 answers
434 views

init.lua - Remove default mapping recursively

I want to use the i_CTRL-G mapping to abort the current cmp selection, but i_CTRL-G is already used by neovim. I tried to delete the mapping with this: vim.keymap.del('i', '<C-g>') But it just ...
Bog's user avatar
  • 509
1 vote
3 answers
76 views

Mapping two slashes to braces deletes two previous characters

In ftplugin directory I created pascal.vim with the following mapping: imap // <ESC>hc2l{ }<ESC>hi The aim of this mapping is to replace two forward slashes with braces and leave the ...
Pontiac_CZ's user avatar
0 votes
2 answers
45 views

Why does ":normal gv" keep removing one line from my visual block?

I'm trying to create a vimscript function that does a substitution on a visual block and then highlights the visual block again with gv. For instance: function! MySubstitution() s/foo/bar/ ...
wxz's user avatar
  • 155
0 votes
2 answers
33 views

How to use register expression with visual selection?

I have this key map in my Vim configuration: nmap <leader>rn :%s/\<<C-r><C-w>\>/ But for this code from php I have a problem. $text=$home_intro['text']; Because, if cursor is ...
serii 's user avatar
  • 91
0 votes
3 answers
50 views

Swap a 0 under the cursor with a 1 and vice versa

Assume that, in normal mode, the character under the cursor is either 0 or 1. I want that, upon pressing a key (say F6), it is swapped to the other one.
brad's user avatar
  • 131
2 votes
5 answers
551 views

auto enclose word under cursor with {} () []

Usually I would like to enclose the word under cursor with [, ], (, ), {, } by simply selecting the word (select mode or visual mode) and typing [ (or {, )), for example resulting to: hello to [hello]....
xyx's user avatar
  • 466
0 votes
0 answers
15 views

Make vim.execute function dot repeatable

I made the following keybinding to substitute "a/b" with "\frac{a}{b}". -- convert / to \frac{}{} -- (dot repeatable) _G.div_to_latex = function() vim.cmd('execute "normal f/...
robertspierre's user avatar

1
2 3 4 5
32