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 really what you asked for, but:
*: start a search for the word under the cursor (g* if you don’t want the word boundaries)
gn the next ...
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
Result: the value that was yanked into one register is now also in the other register.
I think some inference is needed but the baseline facts ...
From :h /^
At beginning of pattern or after "|", "(", "%(" or "\n": matches start-of-line; at other positions, matches literal '^'.
Hence, as @ChristianBrabandt noted in comments, you must write your pattern as :'<,'>s/^\%V$//n, or alternatively, :'<,'>s/\%V\_^$//n
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 jump between the two using window motions such as CTRL-WCTRL-W. So a workflow might look like this:
:vsplit to open the same buffer in a vertical split
G to ...
You can do this with the :move ex command:
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 specifies where we want the lines to move to.
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:
'<,'>w >> b | '<,'> d
Edit To address the questions in comments:
If the file you're trying to write doesn't exist you can use w! to force the ...
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 can only contain one color and the code is not made to support the kind of customization you are looking for. So the answer is: it is not possible to recreate ...
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 your case with your cursor after GGg you can start reverse search mode with ? and type < in your search prompt. When you type Enter the end of your selection ...
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 to do, there are often several approaches. In this case, to copy:
" clear register A
let @a = ''
" yank all the words
Using a capital ...
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, plug-in wellle/targets.vim extends many of the built-in motions and text objects, `i`` included, to make them more powerful.
In particular, it supports multi-line ...
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
if visualmode() !=# 'v'
let startpos = getpos("'<")
let endpos = getpos("'>")
if startpos == endpos
execute "normal! ^o".a:count."g_"
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 do it with an ex command, . is the shortest "this line" range; note that many commands take it by default.
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 pattern: the \> are word boundaries (similar to \b in Perl-style regexps) so that it won't match phrases.
You can then use :%s//sentence/g; to replace phrase ...
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 fact that you're ending with a \zs, so in effect what Vim is highlighting there is the character following the search term and not the match itself (...
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 Vimcasts episode #26 "Bubbling Text", which introduces two generic solutions with keybindings:
" Bubble single lines
nmap <C-Up> ddkP
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 README, also the Wiki has specific sections, for instance one on Motions and Modes. Once you install the plug-in, you can also find more documentation in Vim ...
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 characterwise visual mode, the > command affects the line in a way that the original bounds of the selection are lost (in that they're no longer tied to the ...
To delete all emails first:
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 names first:
vip select paragraph
:norm! WD execute normal mode commands: move cursor 1 WORD and delete to the end of line.
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 '.shellescape(getline('.'))
If it’s always a whole line, just replace gv with V
xnoremap <expr> <Tab> line("'<") isnot# line("'>") ? '>gvVgv' : '>V'
to handle multi-line selections and single-line selections, but there are some issues (see comments)
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/vim-multiple-cursors.)
But since these plug-ins need to use Vim highlighting features to emulate multiple selections and they typically need to re-implement ...
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 the tabstop is at 4 characters, the shiftwidth is also at 4 characters, and expandtab is also turned on (so no tabs anywhere, just spaces).
When I have a problem ...
If you want a command that does that based on the length of the prefix, here's one:
if a:count == 0
let prefix = strcharpart(getline('.'), 0, a:count)
let pat = '\V\^'.escape(prefix, '\')
echom "pat = [".pat."]"
let start = line('.')
let end = start
let last = line('$')
1st Dan needed to delete the names. The delimiter is the first space. So delete everything from the first space to end of line:
To delete the emails, a 2nd Dan is needed. Delete any non-space and the first space from the beginning of the line:
s/^[^ ]* //
Note: This answer assumes, that the delimiter is a single space character. If the delimiter ...
You can use plug-in vim-textobj-user to define custom text objects using patterns or higher level functions.
In fact, vim-textobj-user uses il as an example of how to use the plug-in:
Complex text objects defined by functions
Define al to select the current line, and define il to select the current line without indentation: