Skip to main content
Share Your Experience: Take the 2024 Developer Survey
8 votes
Accepted

Why does `yW` yank until the end of the WORD, but `W` move to the next one?

It might be useful to quote :help exclusive, here: A character motion is either inclusive or exclusive. When inclusive, the start and end position of the motion are included in the operation. When ...
romainl's user avatar
  • 41.1k
6 votes
Accepted

Why variables related to visual mode start with two uppercase letters in Vim source code?

There are pointers in version.c of v2.4: Included code to save the xterm title. Need to define USE_X11, because specific include file and library are needed. Added 'icon' option (default off): when ...
Aliaksei Budavei's user avatar
4 votes

Why variables related to visual mode start with two uppercase letters in Vim source code?

It appears first in vim-2.4 (July 1994), was not in vim-2.0 (December 1993). There are no comments about this, but seeing that "Visual" and "visual" are used in the comments, it ...
Thomas Dickey's user avatar
3 votes
Accepted

How can expand and contract visual selection from a tag block?

When using "a something" text objects (at, a(, etc.) in visual mode, you can generally keep using them to expand the visual selection. In this case, you should be able to do vatat to select ...
romainl's user avatar
  • 41.1k
2 votes

Yank lines without leading whitespace

Let me provide a multiline version of the answer by @theonlygusti. This version does not rely on anti-quotations and global variables so I hope it might be considered more readable. When executed, it ...
Grwlf's user avatar
  • 121
2 votes
Accepted

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

In Vim I think you would do xnoremap <leader>ld :LineDiff<enter> taking advantage of : inserting marks. The problem with <Cmd> is it doesn’t switch modes… so probably : is the right ...
D. Ben Knoble's user avatar
  • 26.4k
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
2 votes
Accepted

Paste in front or after in visual-block mode?

To accomplish what you want, you can use I from visual-block mode to perform a "Visual-block Insert" (see :help v_b_I), or A to perform a "Visual-block Append" (see :help v_b_A). ...
nullromo's user avatar
  • 255
2 votes

Keybinding to quickly update (aka prettify) React indentation

Find a command line tool that can format part or whole buffer the way it suits your needs. Integrate it with vim using :h 'formatprg' which then could be used with gq. e.g. Let's imagine there is a ...
Maxim Kim's user avatar
  • 13.5k
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

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

As mentioned in another answer, visually selecting text generally moves the cursor to one end of the selected area, because moving the cursor is the mechanism by which the boundaries of the visual ...
romainl's user avatar
  • 41.1k
1 vote

How to use register expression with visual selection?

If you've already visually selected the word, pressing s or c will let you start changing it. The change is dot-repeatable. If you wanted to be able to repeat the change (like & with :substitute), ...
D. Ben Knoble's user avatar
  • 26.4k
1 vote
Accepted

How to use register expression with visual selection?

I would introduce a v mapping: vnoremap <leader>rn "zy:%s/<C-r>z/ "zy copy the selection in the z register. <C-r>z paste the z register. If you want to get rid of the all ...
Vivian De Smedt's user avatar
1 vote
Accepted

How can I accept a range in a Lua user command?

I would do: vim.api.nvim_create_user_command('Pizzafy', function(args) if args.range > 0 then -- visual mode, I think print(args.line1 .. "-" .. args.line2 .. "...
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.8k
1 vote
Accepted

Search and replace text in visual range but not entire line

You could do: :'<,'>s/\%V /-/ Where \%V match only if the next character is within the visual range. For more information see :help /\%V
Vivian De Smedt's user avatar
1 vote
Accepted

Pipe visual region to external command, not whole line

There is no way to pipe partial lines using !. A workaround is to use a function like system(). xmap <leader>c y:echo system('wc', @")[:-2]<cr>gv Breaking this down, y yank the ...
Mass's user avatar
  • 14.1k
1 vote

How to wrap my visual selection with brackets using vnoremap?

You could start by improving your normal mode mapping: nnoremap <F5> ciw{<C-r>"}<C-c> where we: "change" the current word (which means "cut it into the unnamed ...
romainl's user avatar
  • 41.1k
1 vote
Accepted

How to wrap my visual selection with brackets using vnoremap?

I would do: vnoremap <F5> c{}<Esc>P c for change {} to insert the braces <Esc> to leave insert mode P to past the text before the closing brace
Vivian De Smedt's user avatar
1 vote

How can I source a visual selection of vimscript?

In Vim 9, you can source either all the lines in a buffer or some selected lines in a buffer by simply using the :source command without any arguments. The help topic source-range has more information ...
Yegappan Lakshmanan's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible