Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»How to Search in Vim / Vi

    How to Search in Vim / Vi

    By RahulFebruary 16, 20212 Mins Read

    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.

    Advertisement

    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.

    vi vim
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Split Large Archives in Linux using the Command Line

    System.out.println() Method in Java: A Beginner’s Guide

    sleep Command in Linux with Examples

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Split Large Archives in Linux using the Command Line
    • System.out.println() Method in Java: A Beginner’s Guide
    • Split Command in Linux With Examples (Split Large Files)
    • Test Your Internet Speed from the Linux Terminal
    • 11 Practical Example of cat Command in Linux
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.