Home Explore Blog CI



neovim

5th chunk of `runtime/doc/usr_03.txt`
ac008cfe922b8bc183694d1ca1420dfdc71a792149ff7edd0000000100000fa5
    |
	| earlier text	   |		 | later text	    |
	| line with cursor |		 | later text	    |
	+------------------+		 +------------------+

The "zt" command puts the cursor line at the top, "zb" at the bottom.  There
are a few more scrolling commands, see |Q_sc|.  To always keep a few lines of
context around the cursor, use the 'scrolloff' option.

==============================================================================
*03.8*	Simple searches

To search for a string, use the "/string" command.  To find the word include,
for example, use the command: >

	/include

You will notice that when you type the "/" the cursor jumps to the last line
of the Vim window, like with colon commands.  That is where you type the word.
You can press the backspace key (backarrow or <BS>) to make corrections.  Use
the <Left> and <Right> cursor keys when necessary.
   Pressing <Enter> executes the command.

	Note:
	The characters .*[]^%/\?~$ have special meanings.  If you want to use
	them in a search you must put a \ in front of them.  See below.

To find the next occurrence of the same string use the "n" command.  Use this
to find the first #include after the cursor: >

	/#include

And then type "n" several times.  You will move to each #include in the text.
You can also use a count if you know which match you want.  Thus "3n" finds
the third match.  You can also use a count with "/": "4/the" goes to the
fourth match of "the".

The "?" command works like "/" but searches backwards: >

	?word

The "N" command repeats the last search the opposite direction.  Thus using
"N" after a "/" command searches backwards, using "N" after "?" searches
forwards.


IGNORING CASE

Normally you have to type exactly what you want to find.  If you don't care
about upper or lowercase in a word, set the 'ignorecase' option: >

	:set ignorecase

If you now search for "word", it will also match "Word" and "WORD".  To match
case again: >

	:set noignorecase


HISTORY

Suppose you do three searches: >

	/one
	/two
	/three

Now let's start searching by typing a simple "/" without pressing <Enter>.  If
you press <Up> (the cursor key), Vim puts "/three" on the command line.
Pressing <Enter> at this point searches for three.  If you do not press
<Enter>, but press <Up> instead, Vim changes the prompt to "/two".  Another
press of <Up> moves you to "/one".
   You can also use the <Down> cursor key to move through the history of
search commands in the other direction.

If you know what a previously used pattern starts with, and you want to use it
again, type that character before pressing <Up>.  With the previous example,
you can type "/o<Up>" and Vim will put "/one" on the command line.

The commands starting with ":" also have a history.  That allows you to recall
a previous command and execute it again.  These two histories are separate.


SEARCHING FOR A WORD IN THE TEXT

Suppose you see the word "TheLongFunctionName" in the text and you want to
find the next occurrence of it.  You could type "/TheLongFunctionName", but
that's a lot of typing.  And when you make a mistake Vim won't find it.
   There is an easier way: Position the cursor on the word and use the "*"
command.  Vim will grab the word under the cursor and use it as the search
string.
   The "#" command does the same in the other direction.  You can prepend a
count: "3*" searches for the third occurrence of the word under the cursor.


SEARCHING FOR WHOLE WORDS

If you type "/the" it will also match "there".  To only find words that end
in "the" use: >

	/the\>

The "\>" item is a special marker that only matches at the end of a word.
Similarly "\<" only matches at the beginning of a word.  Thus to search for
the word "the" only: >

	/\<the\>

This does not match "there" or "soothe".  Notice that the "*" and "#" commands
use these start-of-word and end-of-word markers to only find whole words (you
can use "g*" and "g#" to match partial words).


HIGHLIGHTING MATCHES

While editing a program you see a variable called

Title: Vim: Simple Searches and Options
Summary
This section describes the basics of searching in Vim using the "/string" command, including special characters, and searching forward with 'n' and backward with '?'. It also covers ignoring case with ':set ignorecase' and navigating the search history with the up and down arrow keys. Additionally, it explains how to search for a word under the cursor using '*' and '#', and how to search for whole words using '\<' and '\>'. Highlighting search matches and the use of the 'scrolloff' option for context are also mentioned.