• Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Search in Vim / Vi

Written by Rahul, Updated on February 16, 2021

vi (visual editor) is the best command line text file editor for Unix-like operating systems. Vim is an improved version of the vi text editor used on modern systems. This is a highly configurable text editor.

This tutorial will help you search for text, string or pattern in Vi(m) text editor.

How to Search in Vi(m) Editor

To start searching in the Vi(m) editor, first press the ESC key to switch to command mode in the editor. Then press “/” and then press the search text.

  1. Press ESC
  2. Type “/”
  3. Type the search pattern
  4. Press Enter or Return key perform search
/pattern

How to search in Vim

This will move the cursor to the first match of the searched string. Then use the shortcut keys to navigate to the previous or next search string, as shown below:

  • Press n (in small letter) to search for next occurrences
  • Press N (in capital letter) to search for previous occurrences

Case Insensitive Search in Vim

Default vim searches for case sensitive matches. To search for pattern in all cases, you need to disable case using set command in vim.

Type the following command in vim to disable case sensitive searches.

:set ignorecase

Search vim with ignore case (case insensitive search)

Next, again do search for some text, you will find that search selection is ignoring the case.

You can revert the above changes by using noignorecase with set command.

:set noignorecase

Now, vim will again do the case sensitive searches.

Search Whole World Only

You can also search for pattern matches whole world only. Which means the search do not matches substring of string.

/\<pattern\>

View Search History

Vim keeps all the search history performed in current session. To view the previous searches, press / and use up and down keys

Conclusion

In this tutorial, you have learned about searching in vim/vi text editor in Linux command line.

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply Cancel reply

Popular Posts

  • How To Install Python 3.9 on Debian 10
  • Download Ubuntu 20.04 LTS – DVD ISO Images
  • Linux Run Commands As Another User
  • How to Check PHP Version (Apache/Nginx/CLI)
  • How To Install and Configure GitLab on Ubuntu 20.04
  • How to Install PyCharm on Ubuntu 20.04
  • How to Check Ubuntu Version with Command or Script
  • How to Set all directories to 755 And all files to 644
© 2013-2021 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy