New answers tagged

4

Why spend 2 minutes reading :help /\@<= when you could spend 20 writing an exhaustive question for vi.se? Theoretically these matches could start anywhere before this position. But to limit the time needed, only the line where what follows matches is searched, and one line before that (if there is one). This should be sufficient to match most things and ...


1

Peter Rincker's existing answer is the correct one for this, but there is another technique you could use if you want to do this interactively, reviewing each change as you make it. First get the text you want to append into a register. A simple way of doing this is typing yy with your cursor on a line containing the text. Enter the following command: :/3)...


1

I've answered this before, but the general strategy is this: globally join from the start of a paragraph to the end (given by /^$/-). But we have to handle the last line of the document specially. The easiest version is :$put ='' :global/./,/^$/-join :$delete where we make a blank line at the end, do our join (which doesn't fail on the last line, now), and ...


4

You can use a substitution with \zs (or &) to do to "append" your line in the form: :%s/pat\zs/\rAppendMe/g :%s/pat/&\rAppendMe/g To do this across multiple buffers you need a list of files/buffers then a way to execute your command. All buffers use :bufdo {cmd} where {cmd} is your command These are buffers in the Quickfix List then you ...


3

If those two (tothem and tohim) are the only patterns then you can modify the regexp to be more specific i.e. to only match those two specific patterns : :%s/\( to\)\(him\|them\)/\1 \2/c Another way : :%s/\( to\)\(.\?..m\)/\1 \2/c The regex in the second group is looking for a pattern that has either 2 or 3 character followed by the character m. The more ...


3

I think what you are trying to use with \?\! is an adaptation of Perl's zero with lookahead which doesn't exist in vim. The equivalent in vim is :h /\@!, you could use it this way: :%s/\(to\)\(gether\|nal\|ne\)\@!\([a-z]\)/\1 \3 \(to\) match "to" \@! not ...


2

There's a lot missing there. Ignoring the part after the first <CR> for now... First, there are some contexts, i.e. where a filename is expected, where you can use <cword> bare. But in many cases, including this one, you need to force it to be resolved or "expanded". That can be done with, naturally, expand('<cword>'). ...


5

I found something on the Vim wiki that combines ranges with searches. This command did the trick for me: :g/^"/,/"$/j e.g. :g (global) /^"/,/"$/ (a range between a line starting with ", and a line ending with ") j (join the lines specified in the range)


2

About :match With the match command, you only get 3 match ids: :match noteHi /\[\cNOTE:[^=]*\]/ :2match todoHi /\[\cTODO:[^=]*\]/ :3match what /ever/ Each time you call these commands for a particular id (1,2,3) you replace whatever was there before. So you can have 3 different ones but that's it, only 3. If you need more, use matchadd(). About matchadd() ...


1

you can also use it like this :%s/file\zsName/Path/ge which would substitute fileName with filePath without you having to retype file or any other more bothersome to type word just used to identify the search term use :help /\zs for more info. just learned about it here: http://vimcasts.org/episodes/project-wide-find-and-replace/


Top 50 recent answers are included