with grep I can do a grep -v "my search" to get all the lines with out "my search"

with sed I can sed '/baz/!s/foo/bar/g' to find replace text on lines with out baz

Is there a way to do the same thing vim. And is it possible but with out the "s///" syntax. Using just the "/" search syntax.

link|improve this question

feedback

2 Answers

up vote 11 down vote accepted
:g/pattern/

matches all the lines were pattern is found.

:v/pattern/

does the opposite. See :h global for more details.

You can use it like this:

:v/pattern/norm Ipattern not found - <CR>

to prepend "pattern not found - " to every line that doesn't have "pattern" or

:v/pattern/s/nrettap/pattern

to replace "nrettap" with "pattern" on every line that doesn't have "pattern".

Contrived examples, yes.

link|improve this answer
I lol'd on "nrettap". – UncleZeiv Jan 30 at 14:44
feedback

To search for the lines not containing foo, for example, do:

/^\(\(.*foo.*\)\@!.\)*$

Source: http://vim.wikia.com/wiki/Search_for_lines_not_containing_pattern_and_other_helpful_searches

link|improve this answer
I did not know about the \@ directive that lets you reference the previous atom in search. Very useful. – nelaar Jan 30 at 14:19
Even if correct, this is really costly. – Benoit Jan 30 at 17:25
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.