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
2 votes
1 answer
20 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
415 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
38 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
  • 55
1 vote
3 answers
262 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
  • 55
0 votes
1 answer
44 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
32 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
  • 713
0 votes
1 answer
44 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
92 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
  • 422
0 votes
1 answer
28 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
45 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
55 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
  • 121
0 votes
0 answers
13 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
28 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
50 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
  • 713
1 vote
1 answer
30 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
  • 58
2 votes
3 answers
101 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
19 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
54 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
59 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
340 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
  • 13
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
44 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,184
0 votes
1 answer
35 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
67 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
  • 731
0 votes
2 answers
46 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
42 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
62 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
39 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
196 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 ...
faceclean's user avatar
  • 113
0 votes
0 answers
48 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
47 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
247 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 vote
1 answer
204 views

How is the right hand side of an <expr> binding evaluated?

I like using <cr> to save a file, except in a quickfix window where I want <cr> to enter the directory or file shown. Here's one way to achieve this (works as a .vimrc by itself). I'm ...
Greg Nisbet's user avatar
  • 1,839
1 vote
1 answer
84 views

File Type dependent key mapping valid only for that specific filetype

I am aware that you can either use an Autocommand or defining a key-binding in some ftplugin file. However, once the key-binding is defined, it will stay, no matter the filetype. However, imagine that ...
Barzi2001's user avatar
  • 536
1 vote
1 answer
25 views

Clean the placeholder text after multiple jumps

I am studying the book "Hacking Vim" by Packt publishing. In chapter 4 the author gives us an example of a template for HTML files. I followed the guide of the author. Created a file ~/.vim/...
user4035's user avatar
  • 133
1 vote
1 answer
38 views

How to open NERDTree quickly?

I have read the NERDTree help and found that to close NERDTree, we could type :q. How can I open NERDTree the shortest way? I am now typing :NERDTree to open NERDTree, but I think it is too slow for ...
Dolphin's user avatar
  • 113
2 votes
1 answer
216 views

Cannot overwrite existing keybinding Shift+k in Neovim

I want to map Shift-k (K) as 5k but it is mapped to call a function vim.lsp.buf.hover() These commands dont work: map <S-k> 5k nmap <S-k> 5k noremap <S-k> 5k nnoremap <S-k&...
Sahaj Bhatt's user avatar
2 votes
1 answer
103 views

How do I capitalize the first letter of a list item (ignoring the bullet)?

I have a list: - item one - item two - item three and this as well. and I want to capitalize the first word in a line. However the two bindings that I know to go to the first character of a line '0' ...
alejandro_hagan's user avatar
3 votes
1 answer
195 views

# key causing delay in Neovim

Whenever I input # in Neovim I get delay. I tried to fix this with nnoremap # <nop> vnoremap # <nop> In my init.vim but that seemed to only fix it in non .tex environments. I assume this ...
Maths Wizzard's user avatar
1 vote
1 answer
241 views

How to add a keymap for a visual mode plugin command and pass it the visually-selected range?

I have the linediff.vim plugin installed. Its main command :Linediff only works for visual mode, to which I'd like to add a keymap for this command. I'm using Neovim's Lua API, so I tried this: vim....
Jethro Cao's user avatar
2 votes
2 answers
512 views

How to validate and reference digraph /special character in Vim?

I want to remove the ending section of my output that typically follows the below pattern: ^[[2D[^[D but my regex will not allow me to select the ^[ parts of the word. Note on my Vim that part shows ...
alejandro_hagan's user avatar
2 votes
1 answer
57 views

How to use function argument in a mapping?

Let's take a look at the example below. function! Print (text) echo a:text endfunction function! Mapping_test (parameter) nnoremap m1 :call Print (a:parameter)<CR> nnoremap m2 :call ...
Artur Pyszczuk's user avatar
1 vote
2 answers
198 views

Conditional keymap

Is it possible to map a key (e.g.: Alt h) to _ (to go to the first character in the line), but to |, when already there? Perhaps in nvim/lua? What I have tried is: vim.keymap.set({'v', 'n'}, '<A-...
Alois Pichler's user avatar
2 votes
2 answers
875 views

How to disable hjkl movements?

Before you crucify me please note I have a an Ultimate Hacking Keyboard and I already can move with arrow keys on the home row :) I suppose I don't have to since I have a different layer to activate ...
Rick Penabella's user avatar
0 votes
1 answer
236 views

Can not remap command using mapleader and keymap

I am trying to set <leader>pv as :Ex but always it shows E492: Not and editor command: ,pv Basically the newly added command mapping is not setting up or saving properly. I do not know what to ...
piedpipr's user avatar
  • 101
0 votes
1 answer
127 views

Neovim Markdown toggling bold keybind

I am trying to make it so I can have a keymap for toggling things like bold in a markdown file. I used to use vscode with the markdown plugin and they offered the option to, with a simple keybind, ...
Educpf's user avatar
  • 33

1
2 3 4 5
31