New answers tagged

0 votes

Conditional Key Mapping in Neovim Based on File Type

The standard way to do this is to define buffer mapping in the filetype configuration. I would have a ~/.config/nvim/after/ftplugin/js.lua file with the following content: vim.api.nvim_set_keymap('n', ...
Vivian De Smedt's user avatar
2 votes

How to map q for saving and quitting?

(cross-posted from SO) First things first: Vim is Vim, not Vi. They have lots of things in common but even more differences. If you absolutely want to learn from a book, pick a book about Vim, not a ...
romainl's user avatar
  • 40k
2 votes

How to map q for saving and quitting?

The answer of @MaximKim is the modern one. When Joy and Horton say at paragraph 6.9: :map q :wq^V^VCR CR They actually mean: :map q :wqCtrl vCtrl vEnterEnter The document you are reading is about vi ...
Vivian De Smedt's user avatar
2 votes
Accepted

How to map q for saving and quitting?

Only for normal mode: nnoremap q :<C-u>wq<CR> or nnoremap q <cmd>wq<CR> PS, be aware with mapped q you will have trouble to work with macro recordings.
Maxim Kim's user avatar
  • 13.1k
2 votes
Accepted

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

I wonder what "doesn't work" mean and what exactly your xnoremap mapping looks like? Did you try xnoremap <buffer> <silent> <nowait> <M-8> :call FormatIoInstance()<...
Maxim Kim's user avatar
  • 13.1k
1 vote
Accepted

What is set_opfunc?

The set_opfunc need to be defined first: local set_opfunc = vim.fn[vim.api.nvim_exec([[ func s:set_opfunc(val) let &opfunc = a:val endfunc echon get(function('s:set_opfunc'), 'name') ]], ...
Vivian De Smedt's user avatar
1 vote

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

The key code is actually remap and not noremap. I would define it like this: local opts = { remap = false } local ll = "<leader>i" opts["desc"] = "Send visual lines&...
Vivian De Smedt's user avatar
1 vote

Redraw cursor at absolute top or bottom while keeping scrolloff

Based on great feedback and some really good inspiration from Rich, I have put together a working solution for this and I love it. local function scrolloff_should_reenable() if vim.w.orig_scrolloff =...
theherk's user avatar
  • 121
0 votes

Toggle Vim Terminal with Mapping like VS Code

<C-`> isn't valid. I use this: nnoremap <Leader>t :bel term<CR> tnoremap <Leader>t exit<CR>
ranemirusG's user avatar
1 vote
Accepted

AstroNvim in diff mode: navigating to next difference

There is no option indeed (I believe because ]c is a standard functionality and that are no added mapping has been introduced) but the command do work (at least for me).
Vivian De Smedt's user avatar
2 votes
Accepted

How to automatically fold html tags?

If your foldmethod is default (foldmethod=manual) than you can: zfit :h zf -- create fold :h it -- over "inner tag block" text object PS And if you are into "automatic" folding, ...
Maxim Kim's user avatar
  • 13.1k
1 vote

How to automatically fold html tags?

I would do: nnoremap <leader>f v%zf Under the hypothesis that foldmethod is manual: set foldmethod=manual
Vivian De Smedt's user avatar
0 votes

Vim keybinding case-insensitive

If by <C-L> you mean CtrlShiftl I would do: imap <C-S-l> <Plug>(copilot-accept-word) Or even: inoremap <C-S-l> <Plug>(copilot-accept-word) As @romainl says this may ...
Vivian De Smedt's user avatar
0 votes

Best way to keybind subsequent substitutions in visual mode

I would probably write xnoremap <leader>q :substitute/^\(.*\)$/\=empty(submatch(1)) ? '>' : printf('> _%s_', submatch(1))<enter> " or xnoremap <leader>q :substitute/^/> ...
D. Ben Knoble's user avatar
  • 25.8k
2 votes
Accepted

Best way to keybind subsequent substitutions in visual mode

To avoid the double '<,'> problem the old way is to add <C-u> at the start of the mapping: vim.api.nvim_set_keymap( "v", "<Leader>q", ":<C-u>'<...
Vivian De Smedt's user avatar
1 vote

Best way to keybind subsequent substitutions in visual mode

The point is that Vim switches from mode to mode as it reads buttons. No matter if they come from keyboard or mapping. So you only start from Visual mode. But then you get into cmdline, then into ...
Matt's user avatar
  • 20.6k
1 vote
Accepted

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

The first case is best handled with :substitute :%s/^\(\k\+\)=\zs.*/$(\1) on every line from the first column create a group of more than one consecutive keyword characters expect a equal sign start ...
Luc Hermitte's user avatar
  • 17.2k
3 votes
Accepted

Block select unequal lines

Indeed, with visual block selection one operates on rectangular block of text. If it was aligned on = you would be able to do it, otherwise you can use suggested in other answers methods. Similar one ...
Maxim Kim's user avatar
  • 13.1k
1 vote

Block select unequal lines

You could: Duplicate the line first Apply the following macro 0Iprint(^[eld$a)^[ 0 go to the start of the line (when you run a macro on many lines it is a good practice not to assume anything about ...
Vivian De Smedt's user avatar
1 vote

Block select unequal lines

I would: Duplicate the lines first On the first line I would run the following substitution: :s/\v(\S+).*/print(\1) I would repeat it using the & key on the other lines
Vivian De Smedt's user avatar

Top 50 recent answers are included