History Report a problem
Article Edit this page Discussion

Match every word except foo

From Vim Tips Wiki

(Redirected from VimTip220)
Jump to: navigation, search
 

[edit] Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 220Previous TipNext Tip

Created: February 25, 2002 Complexity: intermediate Author: Michael Geddes Minimum version: 6.0 Karma: 52/26 Imported from: Tip#220


This is a regular expression that matches all words except 'foo'

\v<(foo>)@!\k+>
  • \v Very magic
  • < Start-of-word
  • (Foo>) The atom 'Foo' followed by end-of-word
  • @! Match (with zero length) when the previous atom doesn't match.
  • \k+ Match one or more Keywords
  • > Match end-of-word.

The non-magic version is:

\<\(foo\>\)\@!\k\+\>

The use of \@! can be very tricky. According to the Vim help files, it is often easier to use \@<! instead. For example, to find all 'bar' strings unless they are part of 'foobar', use the following (non-magic):

\(foo\)\@<!bar

[edit] References

[edit] Comments

 

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Match every word except foo"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation