Finding a backslash character in vim

How to search for the beginning of the word \word in vim. I can do this using the search menu. Is there any other short cut for this?

+6
vim keyboard-shortcuts
source share
4 answers

Try:

 /\\word 

in command mode.

+13
source share

You can search anything in the document using regular expressions. In normal mode, type '/', and then start typing in your regular expression, and then press enter. '\ & L;' will match the beginning of the word, therefore

 /\<foo 

will match the string "foo", but only where it is at the beginning of the word (in most cases these are spaces).

You can search for a backslash character by escaping it with a backslash, therefore:

 /\<\\foo 

Found pattern '\ foo' at the beginning of a word.

+4
source share

The reason for searching for something, including "\", is different from the fact that "\" is a special character and must be escaped (added with a backslash)

Similarly, to search for "$ 100", which includes the special character "$":

 Press / Type \$100 Press return 

To search for "abc" that does not contain a special character:

 Press / Type abc Press return 
+3
source share

Directly relevant ( /\\word is the correct solution, and nothing changes here), but for your information:

:h magic

If you use a multi-character pattern with a special meaning for regular expressions, you can find the “nomagic” and “very nomagic” modes.

  /\V^.$

will look for a literal string ^.$ instead of "lines of exactly one character" ( \v "very magic" and by default \m "magic" modes) or "lines of exactly one period" ( \m "nomagic" mode).

+2
source share

All Articles