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
62 views

Behaviour of Neovim when in insert mode is different from expected

I recently switched from vim to neovim. I have the following keybindings in neovim: vim.keymap.set("i", "0", "<Esc>la", { noremap = true }) vim.keymap.set("i&...
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 ...
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 ...
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: "...
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/...
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 :...
1 vote
1 answer
1k views

Mapping doesn't work for tabs

I have several files opened in tabs in Vim. I want to switch between tabs, so I use Ctrl+left to move left (previous) and for next also. But my mapping doesn't work. :map <C-Left> :tabprevious&...
0 votes
1 answer
115 views

Why does this key-mapping in vi not work correctly?

I'm just learning how to use the vi editor, and was trying to make use of the following map command in my .exrc file: map K 0I^I^[j0O^I^[j0 That is what appeared when I created the map in ex mode and ...
2 votes
1 answer
1k views

Why don’t these mappings to enter Terminal-normal mode work?

I have remapped "enter terminal normal-mode" to <Esc> with: tnoremap <Esc> <C-\><C-n> and it works. I also use zsh vi-mode, which requires <Esc> to enter normal ...
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 ...
0 votes
1 answer
47 views

How to map <C-z> to act like <C-y> in completion menu?

My keyboard has z and y switched compared to US keyboards, which makes pressing C-y for completions pretty awkward. I tried adding imap <expr> <C-z> pumvisible() ? "<C-y>" :...
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/ ...
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.
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 ...
3 votes
1 answer
2k views

Make YouCompleteMe open definition in vertical split even if buffer is not saved

There is something I cannot do with YouCompleteMe that I could do when just using tags to navigate to a definition or declaration. The desired behaviour is (taking into account that , is my leader ...
1 vote
1 answer
203 views

Can't figure out where this mapping comes from

For more than a year, I have unmap <C-X> in my .vimrc because I can't figure out where this mapping comes from. I used verbose map <C-X> as suggested in another topic, it returns v &...
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/...
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 ...
1 vote
1 answer
323 views

Jump from tag-to-tag in xml?

I'm using emmet-vim which says that it can work in xml files but I can't seem to navigate between tags. Say I have this structure: <dependency> <groupId>com.google</groupId> &...
1 vote
1 answer
626 views

Special characters, escaped special characters, escape sequences, and terminal codes

I refer to those 4 terms using terminology picked up by various sources: Steve Losh, in his Learn Vimscript the Hard Way's chapter 16 refers to things like <cr> (these 4 characters typed in a ...
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 ...
0 votes
1 answer
98 views

Mapping > (and <) to function for special indent

I would like to map > (and <) in normal mode to a function such that it indents the line and keeps the cursor at the original position after performing the indent Here my code in the file ...
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 ...
1 vote
4 answers
2k views

Toggle Vim Terminal with Mapping like VS Code

I am trying to implement toggling of the Vim terminal like VS Code by doing <C-~>. But am not sure how to go about it. I find executing :term to open and to close tedious. I figured having a ...
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 ...
0 votes
1 answer
84 views

vnoremap to sort highlighted lines by length not working as expected

I found a command that would sort highlighted lines by their length and wanted to make a mapping for it so that I could avoid typing it every time. vnoremap ,s :<C-U>'<,'> ! awk '{ print ...
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 ...
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&...
0 votes
1 answer
195 views

Can I make a new mode in Nvim?

I want to create a new mode other than normal, visual, or insert because I want to: change the functions of all keys at once allow remapping preserve the mappings of other modes and retrieve when go ...
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 ...
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 ...
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'}, ...
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 ...
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 ...
34 votes
4 answers
81k views

Remap Esc key in Vim

Is it possible to remap the Esc key to another key in Vim? When I'm using Vim in a full screen VMware vSphere web client console window and I press the Esc key to exit edit mode, it also takes me out ...
0 votes
1 answer
53 views

MacVim: <Delete> key does not work in a terminal window

I happened to find that we may open 'Terminal windows' in Vim and am happy to stop using terminal app. (It's available in v8 and v9) However, when I have a typing mistake, pressing Delete key does not ...
6 votes
1 answer
1k views

Why can't I type certain non-ASCII letters?

I recently had a need to type the letters æ, ø, and å. For context, these are available on my physical keyboard, and work fine in other programs. It's also a Norwegian keyboard (+ layout), if that's ...
1 vote
1 answer
876 views

<Tab> out of insert mode - lua keymap

I'm a relatively new neovim user. I use nvim-autopairs to always induce matching (, [, {, ', " character pairs, and automatically placing my cursor inside them. As an example, in insert mode, if ...
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 ...
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 ...
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 ...
118 votes
9 answers
261k views

What is the command for "Select All" in Vim and VsVim?

How do I select all the content of a file in Vim and VsVim? Like in other editors Ctrl-A does the job for select all.
0 votes
1 answer
99 views

How to debug this problem with the :map command?

I was trying to view my key mappings because I can't seem to jump through parts of snippets in UltiSnips. So I type :map and hit enter and it comes up with the start of the list, but there I can't ...
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 ...
0 votes
1 answer
368 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 ...
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", "...
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", ...
1 vote
1 answer
470 views

vim.keymap.set issue

I've tried to make a key map as follows: vim.keymap.set('x', '<leader>n', function() -- Here <leader> is <Space> line1r, line1c = unpack(vim.api.nvim_buf_get_mark(0, "<&...
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 ...
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 ...

1
2 3 4 5
31