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

Select multiple words, one at a time, then replace them all

I’m assuming all the things to change are the same. If not, I would probably proceed with either multiples of the steps below, or combine all the patterns into a single substitute pattern. So, not ...
D. Ben Knoble's user avatar
  • 26.4k
7 votes
Accepted

How do registers + and * interact with suspending Vim via Ctrl-Z?

Note that this is only applicable to Vim on *nix systems with an X server. Let's reduce the test to this: vim -u NONE insert a line of text yank it into either the plus or star register suspend (Ctrl-...
B Layer's user avatar
  • 19.9k
5 votes
Accepted

How to move selected lines up and down?

You can do this with the :move ex command: :2,3m0 In the above, 2,3 is a range which specifies which lines we want to move, m is an abbreviated form of the :move command, and 0 is an address which ...
Rich's user avatar
  • 32.1k
5 votes

How to move selected lines up and down?

You can select the lines with entering visual line mode V, deleting with d and pasting with p (after the cursor) or P (before the cursor). But if you need this often I highly recommend to read/watch ...
okket's user avatar
  • 151
5 votes

How to re-select a previously selected region in visual mode?

If I get you right it is gv. You can also remap > and <: xnoremap > >gv xnoremap < <gv
Maxim Kim's user avatar
  • 13.5k
4 votes
Accepted

How can I indent selected lines in Visual mode by space granularity instead of TABs?

A working, hacky solution function! Visual_indent_with_space() range abort '<,'>g/./exe "normal! " v:count1 . "I " endfunction vnoremap <leader><space> :call ...
Biggybi's user avatar
  • 2,760
3 votes
Accepted

Caret `^` and `\%V` compatibility in Vim regex

From :h /^ At beginning of pattern or after "|", "(", "%(" or "\n": matches start-of-line; at other positions, matches literal '^'. Hence, as @...
Matt's user avatar
  • 20.8k
3 votes
Accepted

How to multi select for the purpose of copy operation?

If you want to copy multiple separate words and paste them at the end of a long document, here are some options. Option 1: splits You can open the same buffer side-by-side using :vsplit. You can then ...
Andrew Ho-Lee's user avatar
3 votes

Select multiple words, one at a time, then replace them all

One way would be to press * when your cursor is on the word you want to replace, phrase in this case, which will search for that word (very useful in general!) It will use \<phrase\> as the ...
Martin Tournoij's user avatar
3 votes
Accepted

How to perform an action on search matches?

So you're referring to the search results that get highlighted when you have the 'hlsearch' option set. So, in effect, these are the search results. Your example has one more quirk to it, which is the ...
filbranden's user avatar
  • 28.9k
3 votes

Selector for line of text?

Here's an il operator that behaves like iw but selects a line, from first to last non-blank character in the line: function! SelectLine(count) abort normal! gv if visualmode() !=# 'v' normal! ...
filbranden's user avatar
  • 28.9k
3 votes
Accepted

Put cursor at arbitrary line and column

You need to set virtualedit=all. The virtualedit option controls where you can edit outside of the actual text (there are other options). Read :help 'virtualedit' for more.
D. Ben Knoble's user avatar
  • 26.4k
3 votes
Accepted

vim - how do I cut some lines of file-1 to file-2 in 1 step?

You could make it a one liner using a range: 2,3w >> b | 2,3d And if you want to keep doing this with visual selection, you can select the lines and then use '< and '> for the range: '&...
statox's user avatar
  • 50k
2 votes
Accepted

Gradient color background for visual selections

Vim (and neovim) use some highlighting groups (:h highlight-groups) to define which color a UI component should have. For the cursor line the group is hl-CursorLine (:h hl-CursorLine). Such groups ...
statox's user avatar
  • 50k
2 votes

How to end selection at an occurrence of a word?

To answer your question in a more general way, you can combine the visual mode with any motion you use in normal mode. That means that you can use f, t, w, etc but you can also use the search: In ...
statox's user avatar
  • 50k
2 votes
Accepted

Is it possible to ignore J if only one line is selected?

As :join[!] command does not really do anything if range has equal start and end values, you can make use of it instead of original J / gJ xnoremap <silent>J :join<CR> xnoremap <...
Matt's user avatar
  • 20.8k
2 votes
Accepted

Select text in block-wise visual mode on each line asynchronously

In general, visual block selections must be blocks (rectangles). The only "jagged" selections are when you hit <C-v>$ to select to the end of multiple lines. However, depending on what you want ...
D. Ben Knoble's user avatar
  • 26.4k
2 votes
Accepted

How to line-select a block within a back-ticked string

The vi` motion from stock Vim will not work, since i` (and a` or i' or i") only work on a single line of code. See :help v_a` for more details. But it turns out there's a plug-in that helps here, ...
filbranden's user avatar
  • 28.9k
2 votes
Accepted

Selector for line of text?

The fastest I can come up with is really ^vg_ to be precise about start and end of line. But, by way of challenge, perhaps you really need dd, yy, cc, or similar? Even guu and g~~ work. If you can ...
D. Ben Knoble's user avatar
  • 26.4k
2 votes
Accepted

How to do multiline non-rectangular deletion?

To delete all emails first: vip:norm! dW vip select paragraph :norm! dW execute normal mode commands: delete WORD Then you end up having only names -- delete them as usual I guess? To delete all ...
Maxim Kim's user avatar
  • 13.5k
2 votes

Can you do a jagged visual selection or jagged yank?

Plug-in vim-visual-multi implements multiple selections and it can do what you describe here. (It can even select multiple visual selections on lines that are not adjacent.) See some examples on the ...
filbranden's user avatar
  • 28.9k
2 votes
Accepted

How to grow/shrink a selection per tab?

This works if you're in Visual Line mode, so one option (the one I'd recommend) is to always convert to Visual mode (from character or block visual mode) if needed, before the operation. With ...
filbranden's user avatar
  • 28.9k
2 votes

How to diff a selected part of two files?

I have a same problem so I developed and posted spotdiff.vim, which provides commands and custom operators to select a range of lines and text area to compare partially in everywhere within windows. ...
Rick Howe's user avatar
  • 363
2 votes
Accepted

How to replace selected text T with some function(T), using a keyboard shortcut?

Normal mode with the :substitute command. nnoremap <leader>t :s/\%#\<<c-r><c-a>\>/[&]()/<cr>f(a The trick is to use <c-r><c-a> which will insert the :h &...
Biggybi's user avatar
  • 2,760
2 votes
Accepted

Select entire function call or extend selection

For func(gunk(a, b)) with the cursor on the f of func, I would press y% or d%. The % command jumps between matching pairs (roughly; depending on configuration, optional plugins that ship with Vim, ...
D. Ben Knoble's user avatar
  • 26.4k
1 vote
Accepted

How to get current line string without visual selection?

You're close! You can use shellescape() to quote the argument to pass it to the shell, which will take care of spaces and any shell metacharacters that might be present in the line. exec '!commandhere ...
filbranden's user avatar
  • 28.9k
1 vote

How to grow/shrink a selection per tab?

If it’s always a whole line, just replace gv with V We tried xnoremap <expr> <Tab> line("'<") isnot# line("'>") ? '>gvVgv' : '>V' to handle multi-line ...
D. Ben Knoble's user avatar
  • 26.4k
1 vote

Select multiple words, one at a time, then replace them all

There are Vim plug-ins that emulate the "multiple cursors" feature from other editors such as Sublime or VS Code, for example, mg979/vim-visual-multi (successor to the now deprecated terryma/...
filbranden's user avatar
  • 28.9k
1 vote

How can I indent selected lines in Visual mode by space granularity instead of TABs?

I just do column selection + copy for such unaligned movement of my code. So... first I have expandtab (et) as part of my settings at the bottom of my file like so: // vim: ts=4 sw=4 et This means ...
Alexis Wilke's user avatar
1 vote

gvim swaping between underline and normal visual text selection in visual mode

Responding For Future Reference. It was indeed the VisualNOS highlight, fixed it by making VisualNOS highlight match Visual highlight and removing the underline. Thanks for the help.
Pedro Peixoto's user avatar

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