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
22 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
27 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
27 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
64 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
  • 469
1 vote
3 answers
73 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
40 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
21 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
42 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
0 votes
0 answers
8 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
0 votes
1 answer
19 views

mapping works on next line instead of current

I have this mapping in my .vimrc: inoremap <C-f> <Esc> : exec '.!printf "world"'<CR> I expected it to replace the current line with "world" after pressing C-f in ...
k-dx's user avatar
  • 3
0 votes
2 answers
43 views

yank to register in a map expression

I have this mapping that starts a substitute command with the selected text prefilled: xnoremap <Leader>s "vy:% s#\v<C-R>v#<C-R>v#g<left><left> When I select the ...
MaxGyver's user avatar
  • 231
1 vote
4 answers
37 views

Rotate list of lines

Assume you have the following block of text (yes: I am using vim-latex, but this is not relevant): \begin{itemize} \item 1 % [[[ \item 2 \item 3 \item 4 \item 5 % ]]] \item 6 \end{itemize} My ...
brad's user avatar
  • 131
0 votes
0 answers
20 views

In Neovim which-key, how can I show the command instead of the description?

I'd like to make the label for each keymap the keymap.rhs instead of keymap.desc in the folke/which-key.nvim UI menu, even when they are both defined in the keymap. keymap.rhs is displayed by default ...
ql88888's user avatar
2 votes
1 answer
57 views

Vim macro to copy paste text

I would like to copy paste everything after a comment into the [] place holder of the next line. E.g.: %This is a comment Target box: [] with some more text The desired output would be: %This is a ...
Hugh's user avatar
  • 23
2 votes
1 answer
25 views

Neovim: Making a function that checks the beginning of line and acts depending on it

Extra details, The whole code: local obsidianSettingsGroup = vim.api.nvim_create_augroup('Obsidian Group', { clear = true }) vim.api.nvim_create_autocmd('FileType', { pattern = {'markdown'}, ...
Crimson Crusader's user avatar
1 vote
1 answer
471 views

How do I enhance the '~' command to toggle the "+/-" signs as well?

I need to make a report about investment everyday. It requires a lot of changes of the sign of figures. (from - to + or from + to -) Is there a simple way to overload (extend) the ~ command (switch ...
Charles Jie's user avatar
1 vote
2 answers
39 views

Help understanding this :global command

I have this command to prune :verb map down to only my plugin mappings: g!^\~/vimfiles/plugin/^-1d _ It also needs :$d to remove last line that has verbose comment "Last set [...]". Can ...
Tom's user avatar
  • 67
1 vote
3 answers
265 views

Order of sourcing scripts

I've recently been organizing my vimrc and putting mappings into vimfiles/plugin and vimfiles/ftplugin files (not to mention abbs, functions and commands). However, these scripts are sourced before ...
Tom's user avatar
  • 67
0 votes
1 answer
53 views

Keymaps get reset upon switching focused window back to Neovim instance

Lately I've been running into a strange issue where, upon switching focus in and out of Neovim to other windows, some of my keymaps will not be set properly upon re-focusing and instead use the ...
Devildude4427's user avatar
0 votes
1 answer
34 views

Keybinding to quickly update (aka prettify) React indentation

This is an example of the original code <Text fontWeight="bold" size="lg" color="turquoise.500">Use Search V2 Beta</Text> and I want a keyboard shortcut (say ...
abbood's user avatar
  • 733
0 votes
1 answer
71 views

Conditional Key Mapping in Neovim Based on File Type

How can I do in nvim if the file type is js do this: vim.api.nvim_set_keymap('n', '<A-1>', [[:w | split term://node % <CR>]], { noremap = true, silent = true}) else if file type is lua do ...
user50451's user avatar
0 votes
3 answers
102 views

How to map q for saving and quitting?

I was reading the Vi documentation, by Joy and Horton and on section 6, 6.9 Macros they give a way to map q to save and quit: :map q :wq^V^VCR CR When trying that out in Vim it creates a new file ^V^V ...
Miguel Cortes's user avatar
0 votes
1 answer
71 views

Mapping works only on select mode and not with visual mode?

I have a custom "plugin" I use extensively for verilog development, and I have a few functions I obviously call using respective mapping. For example: function! FormatIoInstance() range ...
xyx's user avatar
  • 464
0 votes
1 answer
32 views

keybindings that change mode: cannot use keybindings on the new mode

I have defined the following keybindings: local opts = { noremap = true } local ll = "<leader>i" opts["desc"] = "Send visual lines" vim.keymap.set("v", ...
robertspierre's user avatar
2 votes
1 answer
57 views

What is set_opfunc?

I'm configuring toggleterm.nvim, and in particular I'm putting this keybinding in my config file, as suggested by the plugin author here: -- Send motion to terminal vim.keymap.set("n", "...
robertspierre's user avatar
1 vote
1 answer
60 views

Redraw cursor at absolute top or bottom while keeping scrolloff

My goal is to remap zt and zb to set scrolloff=0, run zt or zb, then set scrolloff back to its original value. I like the context when scrolling, but when I hit one of these keys I really want the top ...
theherk's user avatar
  • 133
0 votes
0 answers
29 views

":term" style completion in vim.ui.input()

I currently have the following keymap: vim.keymap.set('n', '<leader>sr', function() return ":vs | term " end, { expr = true }) This drops me into a vim command where I can complete ...
Kurtis Nusbaum's user avatar
0 votes
1 answer
48 views

AstroNvim in diff mode: navigating to next difference

In plain old (n)vimdiff, one can jump to the next/previous difference using [c or ]c respectively. (says :help diff documentation, at least) Not so much in my AstroNvim; running nvim -d -R old.txt new....
Marcus Müller's user avatar
0 votes
2 answers
57 views

How to automatically fold html tags?

If I have this react code: <tag> .. </tag> and the cursor is on top of <tag>, tapping on % will make the cursor jump to the closing </tag>. I want to create a vim key mapping ...
abbood's user avatar
  • 733
1 vote
1 answer
46 views

Vim keybinding case-insensitive

I would like to have a key bindings on <C-l> and on <C-L>. But it seems that Vim is case-insensitive regarding this. For example, if I have a Vim script like this: imap <C-l> <C-W&...
john's user avatar
  • 68
2 votes
3 answers
111 views

Best way to keybind subsequent substitutions in visual mode

I need a keybinding that, given some text selected in visual mode (line visual mode, block visual mode, or whatever): Add > _ before the text Add _ after the text In case of empty lines, > ...
robertspierre's user avatar
0 votes
1 answer
20 views

Efficiently create "key-key" pairs from "key-value" pairs

I'm looking for an efficient way of going from this: AIRFLOW__SMTP__SMTP_HOST=asd.sadas.dashasd AIRFLOW__SMTP__SMTP_STARTTLS=False AIRFLOW__SMTP__SMTP_SSL=False AIRFLOW__SMTP__SMTP_USER=asdash@...
Alex's user avatar
  • 103
0 votes
0 answers
65 views

How do I allow higher function keys (F13-F24) in Vim?

My vim sessions use term=win32 and my F13-24 keys do not work, but they are permitted I believe from checking :help t_ku. I've gained shallow insight on how to connect vim keycodes to term keys via &...
Kasz's user avatar
  • 1
1 vote
3 answers
62 views

Block select unequal lines

I often have code of the form: money = double(123) user_level = user["level"] timer = get_time() and want to have: money = double(123) user_level = user["level"...
FromTheStackAndBack's user avatar
0 votes
0 answers
674 views

How to map Enter, Ctrl-Enter and Shift-Enter in Neovim (nvim-cmp)?

According to this My Kitty conf map shift+enter send_text all \x1b[13;2u map ctrl+enter send_text all \x1b[13;5u According to this My Tmux conf bind -n S-Enter send-keys Escape "[13;2u" ...
f4T1H21's user avatar
  • 23
1 vote
0 answers
33 views

How to prevent cursor shift when using `<cmd>` (like `<c-\><c-o>`)?

I currently have inoremap <M-j> <C-\><C-o>gj in my config but I would like to avoid triggering all InsertLeave autocommand when doing this. inoremap <M-j> <cmd>normal! gj&...
0x539's user avatar
  • 197
1 vote
1 answer
52 views

Can I map Alt+j without mapping Escape followed by j to the same thing?

If in insert mode I do Ctrl+v and then press Alt+j, I see ^[j inserted, with ^[ being actually a single character. That's the same I get if I press Escape followed by j instead of Alt+j. I've known ...
Enlico's user avatar
  • 2,194
0 votes
1 answer
37 views

How do I append every single occurance of a phrase with that phrase plus an incremental number?

I am using the Vim extension in VSCode. I want to append every occurrence of a phrase, for example: breadCrumbLabel In my codebase with the instance number. The first occurrence would have to be: ...
Kandala Sreekar's user avatar
1 vote
1 answer
72 views

"gi" doesn't work in my buffers. No error

I recently learned about gi. It doesn't seem to work in my PHP buffer. I get no error message. I expect gi to go to insert. I also write with markdown. In this buffer I get an error that says I do not ...
Vinn's user avatar
  • 771
0 votes
2 answers
53 views

How to combines two mappings into one in Neovim?

I have two keymaps like this vim.keymap.set("n","te","<C-w>l|ia.exe<CR>") vim.keymap.set('n', 'c', ':w <bar> !gcc "%" -o "~/Newfolder/...
Prajwal 's user avatar
1 vote
1 answer
43 views

Normal mappings not working anymore in Vim 9.0 for foreign and special characters

I used to have the following key mappings within _vimrc: nmap è "_ddP nmap ò yaw nmap à "_dwP nmap § .n working in Vim 7.4 on Windows and an Italian keyboard. Now, after upgrading to Vim 9....
Fabius Wiesner's user avatar
1 vote
2 answers
63 views

Is there a default normal-mode command for `:write`?

I know ZZ will write and quit, and ZQ will quit without saving. Is there another such command to write the buffer without doing anything else, or should I map one myself? I'd like to know if there's ...
wallefan's user avatar
  • 171
1 vote
1 answer
49 views

How to use mapmode-x (xmap) and mapmode-s (smap) in Neovim?

I have these two key mappings to surround the visual selection with double asterisks: " This one works for line selections done with V, but not selections done with v vmap <A-b> <ESC>'...
Talex's user avatar
  • 13
1 vote
1 answer
234 views

How to search and replace the highlighted text from visual mode?

The following is the functionality I am attempting to implement. 1. What works (normal mode): Search/highlight the word the cursor is on. Replace the word the cursor is on. Note that the word doesn'...
Vladimir's user avatar
1 vote
4 answers
111 views

Vim mapping to make function parameters become multi-line?

I'm looking for a minimal way to convert code that looks like this: my_function(param1, param2=value2, param4=a_function_call()) into something like: my_function( param1, param2=value2, ...
beyarkay's user avatar
  • 205
1 vote
1 answer
83 views

Restricting `bufdo` to Specific File Types

I'm currently using a key mapping in Vim that's causing some issues. The mapping is: nmap <buffer> <Leader>tr :silent bufdo TaskWikiBufferLoad<CR> The problem is that the command ...
NonalcoholicBeer's user avatar
0 votes
0 answers
55 views

Why is key binding for CTRL-L key messed up?

I have run into a Vim key binding issue at the office recently. On the Linux system where I do my development work, while running Vim the CTRL-L key no longer redraws the screen. The .exrc file in my ...
Barry Kimelman's user avatar
0 votes
1 answer
56 views

How do I create key mappings for Windows and/or nano Shortcuts?

Having used text editors (mainly Notepad/++) and some IDEs on MS Windows, I've become familiar with their Alt and Ctrl shortcuts to the point that I use them automatically. Having used nano on a GNU/...
Agi Hammerthief's user avatar
1 vote
1 answer
56 views

How to save the files when global replace completed in one command line

I have so many huge size of files and always need to do search and replacement so I map the command as nnoremap aa :let i=1 \| g/regexp/ s/^/\=printf("%1d. ",i)/g \|let i =i+1\|:w! 1.txt ...
M_Sea's user avatar
  • 157
1 vote
2 answers
356 views

How to replace a space after a word with a line break (new line)?

In Neovim, I used the J command to join lines, and now I'm looking for a keybinding in normal mode that can do the opposite: replace the space after a word with a line break. I've tried a few "...
pwanker's user avatar
  • 11

1
2 3 4 5
31