9

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: *cgn Breakdown: *: start a search for the word under the cursor (g* if you don’t want the word boundaries) cchange gn the next ...


7

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-Z) restore (fg) 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 ...


4

A working, hacky solution function! Visual_indent_with_space() range abort '<,'>g/./exe "normal! " v:count1 . "I " endfunction vnoremap <leader><space> :call Visual_indent_with_space()<cr> Breaking down: '<,'>g/./exe "normal! " v:count1 . "I " '<,'>: use the selected range g/./: ...


3

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


3

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 ...


3

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 specifies where we want the lines to move to.


3

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 ...


3

If I get you right it is gv. You can also remap > and <: xnoremap > >gv xnoremap < <gv


2

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 ...


2

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 ...


2

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.


2

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 <silent>gJ :join!<CR>


2

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 global/=/normal! 0"Ayaw Using a capital ...


2

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 ...


2

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! v endif let startpos = getpos("'<") let endpos = getpos("'>") if startpos == endpos execute "normal! ^o".a:count."g_" return endif ...


2

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.


2

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 ...


2

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 (...


2

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 nmap &...


2

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 ...


2

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 ...


2

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 names first: vip:norm! WD vip select paragraph :norm! WD execute normal mode commands: move cursor 1 WORD and delete to the end of line.


1

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 '.shellescape(getline('.'))


1

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 selections and single-line selections, but there are some issues (see comments)


1

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 ...


1

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 ...


1

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.


1

If you want a command that does that based on the length of the prefix, here's one: function! Prefix(count) if a:count == 0 return endif let prefix = strcharpart(getline('.'), 0, a:count) let pat = '\V\^'.escape(prefix, '\') echom "pat = [".pat."]" let start = line('.') let end = start let last = line('$') while ...


1

1st Dan needed to delete the names. The delimiter is the first space. So delete everything from the first space to end of line: s/ .*$// 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 ...


1

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: call textobj#user#plugin(...


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