• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Searching in Vim

Thumbnail for Neeran GulNeeran Gul

Neeran Gul

Staff Site Reliability Engineer, Mozn

Published: 1/31/2024

About Terminus

To search in vim, open up your file with vim vim myfile.txt, and press ESC to switch to normal mode. Type / followed by the word you are searching for. For example, if we want to search for ‘ERROR’ in our file. We type /ERROR. This will take us to the first occurrence of the word.

To find the next occurrence, simply type n. And to go back to the previous occurrence, type N. To stop searching press ESC to go normal mode.

To search backwards in a file, open up the file, vim myfile.txt, and press ESC to switch to normal mode. Type ? followed by the word. If we are searching for the word ‘INFO’ backwards, we type ?INFO. Type N to search backwards and n to search forwards. To stop searching press ESC to go normal mode.

Find current word

It is possible to find the current word the cursor is currently on. Open up a file in normal mode. Put the cursor on a word, then press * to find the next occurrence and # for the previous occurrence. On the bottom left corner, we can see the word that is being searched.

To ignore the case whilst searching, type / followed by a word, followed by \c. Let’s go through some examples, /Linux is case sensitive, /Linux\C is case sensitive, /Linux\c is case insensitive. It is also possible to set case sensitive search off in your vim config or the current file, by running :set ignorecase in normal mode.

To highlight search matches, set the hlsearch option by running :set hlsearch in normal mode or inside ~/.vimrc. Now try searching for a word and it will be highlighted everywhere in the file. To clear search highlighting, run :set nohlsearch in normal mode.

Search for any line starting with a word

Starting with ‘def’: /^def

Search for any line ending with a word

Ending with ‘return': /return$

Escaping special characters

Find ‘[0]’: /\[0\]

Find tabs in file

Use /^], to insert the “tab” character, do not type ^], rather after typing / press the tab key.

Written by

Thumbnail for Neeran GulNeeran Gul

Neeran Gul

Staff Site Reliability Engineer, Mozn

Filed Under

Related Articles

Vim Find And Replace

You can use either the substitute command or the slash and dot method to search for patterns and replace with different values.

VimVi
Thumbnail for Glory KimGlory Kim

Vim Modes

Learn about seven of Vim’s modes

VimVi
Thumbnail for Razvan LudosanuRazvan Ludosanu

Vim / Vi Page Up and Down Controls

Quick reference for Vim's page up and down controls

VimVi
Thumbnail for Glory KimGlory Kim

Copy & Paste in Vim / Vi

Copy (Yank), Paste (Put) and Cut (Delete) in Vim

VimVi
Thumbnail for Jessica WangJessica Wang

Undo & Redo in Vim / Vi

Keyboard shortcuts and summary of how Vim tracks changes

VimVi
Thumbnail for Jessica WangJessica Wang

Show & Hide Line Numbers in Vim / Vi

Toggle absolute and relative line numbers

VimVi
Thumbnail for Amber ChenAmber Chen

Select all in Vim / Vi

Select all and copy, paste, or delete the contents

VimVi
Thumbnail for Glory KimGlory Kim

Go To End of File in Vim / Vi

Select and delete to the end of a file in Vim

VimVi
Thumbnail for Preston Tunnell WilsonPreston Tunnell Wilson

How to delete lines in Vim / Vi

The best answer depends on which mode you use

VimVi
Thumbnail for Andrew CarlsonAndrew Carlson

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Request demo
Thumbnail for null