Whenever you want to search for text in vim you would type / and then the string you are looking for.

However, when the string is a long one, and you want to do this multiple times, is there a way to do it so that you don't have to type /andthisreallylongstring more than once?

  • 12
    I recommend you briefly peruse a Vim Cheat Sheet or Vim Tips - you may find many other ways of getting more out of vim. Commented Oct 11, 2011 at 10:12
  • Protip: there are text editors for Linux that don't require weeks of studying to use. Commented Oct 11, 2011 at 22:10
  • 4
    @BlueRaja: not sure this is a good place for an editor war. Also for an OS war as there are also nice and user-friendly text editors for Windows or Mac OS. Having to study how to be efficient with an editor will make you probably more efficient in the end than sticking with basic features.
    – Benoit
    Commented Oct 12, 2011 at 7:01

14 Answers 14


Press "n" after you completed a search, then it will repeat the previous action(search).

  • 14
    Also, N will go to the previous result.
    – Jin
    Commented Oct 11, 2011 at 7:12
  • 17
    Also, hitting the up-arrow after hitting / will recall the last search term
    – bastibe
    Commented Oct 11, 2011 at 12:41
  • 8
    Also q/ will show an editable window with all recent search term.
    – UncleZeiv
    Commented Oct 11, 2011 at 16:22
  • 9
    Also, hitting / and Enter will repeat the previous search. Hitting ? and Enter will repeat the previous search backwards. Commented Oct 11, 2011 at 17:09
  • 4
    /Ctrl-F is an alternative to q/ that may be an easier mnemonic (ctrl-f == find). Like q, it also works for command mode.
    – idbrii
    Commented Oct 12, 2011 at 1:53

If the string you search is under the cursor, then you can type * to search for it forward, or # to search for it backwards.


How I usually search is something like;

  1. Press '/'
  2. Enter Search Term
  3. Press Enter
  4. Use 'n' and 'N' to navigate forward and backwards within the search.

Vim keeps a history of your searches, so if you need previous searches you can press '/' and use the UP and DOWN keys or <Ctrl-P> <Ctrl-N> to browse the search history.

You can also use '?' instead of '/' to search backwards.

I also like to use:

set ignorecase smartcase

Now it will only be a case sensitive search if you have uppercase characters in the search string.


Two additional tips that can make your searching more efficient are set hlsearch and set incsearch.

  • set hlsearch, well, highlights your search results. Type :noh to turn them off when you don't need it anymore.

  • set incsearch turns on incremental searching.

    Extracted from :help incsearch

    While typing a search command, show where the pattern, as it was typed so far, matches. The matched string is highlighted. If the pattern is invalid or not found, nothing is shown. The screen will be updated often, this is only useful on fast terminals.

    Without incsearch, your results will only be displayed after pressing <CR> on your search keyword.


    You want to search for wildignore

    enter image description here

    You type /wild and the first match gets highlighted automatically.

    enter image description here

    Then type i and it goes on to the next correct match.

    enter image description here


Another tip not yet covered: Pressing the characters q and then /, will give you a list of your previous search terms. You may edit them like any other line in a document, and then press enter to re-use them for a new search.

  • 3
    Was looking for this. This is an important note, and very on-topic. Commented Oct 11, 2011 at 20:29

After pressing / to start the search, you can up-arrow to scroll through your search history.

You can enter a regular expression to avoid having to type out the whole search term: and.*longstring


Does just hitting / with no arguments following not work for you? On all our systems, that causes a repeat of whatever search was done last.


There is a nice pattern you can follow to search for yanked text. Then you don't even have to type the word in itself, if you've navigated to it by means other than a search. In summary, if you're on the first character of the word you want to search for:


(then continue to next match with n or N)

However * (or #) accomplishes pretty much the same thing as all these commands. The only difference is you can be flexible by how much of the word you specify (rather than e, to the end of the word, you can select as much as you want to, e.g. 9l)

  • /string — Search forward for string
  • ?string — Search back for string
  • n — Search for next instance of string
  • N — Search for previous instance of string

A lot of time when programming I'll want to search for aVeryLongVariableNameInTheProgram.

In vim you can very easily yank text into a buffer/register and then search for it:

  • Put cursor on first character of word
  • "Byw to yank text aVeryLongVariableNameInTheProgram into buffer B (choose your favorite, I used B)
  • /^RB (slash, Ctrl-R, B) to paste buffer B on the search line

Of course you can also yank to end of line, etc. instead of yanking a single word - I just happen to use the above sequence all the time.

  • 1
    See also: :help CTRL-R_CTRL-W
    – Gebb
    Commented Dec 7, 2023 at 0:37
  • @Gebb - nice! Thank you.
    – Dan7119
    Commented Dec 8, 2023 at 7:21

Additionally, you can paste the contents of any register into the search prompt by pressing Ctrl+R and then the name of the register, e.g., / Ctrl+R 0 Enter.

  • I think you a word.
    – dotancohen
    Commented Dec 26, 2013 at 7:35

Refining your search pattern interactively

(Works when 'incsearch' is active.)

Press /, start typing the search pattern.

  • CTRL-L add the next character of the highlighted match to the search pattern.
  • CRTL-H remove a character from the search pattern.
  • CTRL-G go to (highlight) the next match.
  • CTRL-T go to the previous match.

See :help /_CTRL-L


Is the long string that you're entering a variable name? Or a long string that's in your text? Then hit * to search for the word/string under your cursor.


I found this also useful:

  • :g// will show all lines where last search term occurs
  • :g/pattern same as above but for the given pattern term
  • ]I show lines with word under cursor (only forward)
  • [I show lines with word under cursor (in whole file)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .