{"id":4613,"date":"2023-07-22T10:24:16","date_gmt":"2023-07-22T10:24:16","guid":{"rendered":"https:\/\/arzhost.com\/blogs\/?p=4613"},"modified":"2025-09-16T15:54:29","modified_gmt":"2025-09-16T10:54:29","slug":"find-a-word-in-vim-or-vi-text-editor","status":"publish","type":"post","link":"https:\/\/arzhost.com\/blogs\/find-a-word-in-vim-or-vi-text-editor\/","title":{"rendered":"How to Search to Find a Word in Vim or Vi Text Editor?"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Overview of Vim\/Vi Editor: Importance of Efficient Searching<\/h2>\n\n\n\n<p>Text editors like <span style=\"color: #000000;\"><strong>How to Search to Find a Word in Vim or Vi Text Editor?<\/strong><\/span> and its predecessor Vi are extensively used. They may be found on the majority of Linux and macOS distributions and are both open-source (free).<\/p>\n\n\n\n<p>Finding terms or patterns to search for in <strong><a href=\"https:\/\/www.vim.org\/\">Vim<\/a>\/Vi<\/strong> is a typical activity that makes it simple to browse through huge files.<\/p>\n\n\n\n<p>This lesson from our <a href=\"https:\/\/arzhost.com\/blogs\/\"><strong>Blog<\/strong><\/a> uses real-world examples to demonstrate how to search in Vim\/Vi.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Basic Vim\/Vi Searching: Navigating Search Results<\/strong><\/h2>\n\n\n\n<p><u>In the Vim\/Vi text editor, there are two ways to look for a pattern of numbers or letters.<\/u><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Look ahead for the desired pattern<\/li>\n\n\n\n<li>Look for the specified pattern going backwards<\/li>\n<\/ol>\n\n\n\n<p>About the cursor point, the direction is decided.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Looking for a Word\u2019s Next Result: Searching Forward in Vim\/Vi<\/strong><\/h2>\n\n\n\n<p><u>Use the command: to advance the search.<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>\/pattern<\/code><\/li>\n<\/ul>\n\n\n\n<p>Put the item(s) you want to find instead of a pattern.<\/p>\n\n\n\n<p>For instance, to find all occurrences of the pattern &#8220;root,&#8221; you would:<\/p>\n\n\n\n<p><u>1: To make sure Vim\/Vi is in regular mode, use Esc.<\/u><\/p>\n\n\n\n<p><u>2:&nbsp; Enter this command:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>\/root<\/code><\/li>\n<\/ul>\n\n\n\n<p>The first occurrence of the pattern after the cursor is highlighted in the text editor. You can see that the outcome is a word&#8217;s worth of text that includes the desired pattern in the image below.<\/p>\n\n\n\n<p><u>This is so because searching for complete words is not specified by the command.<\/u><\/p>\n\n\n\n<p><u>Choose Enter from this position, then:<\/u><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>N will advance you to the following instance of the pattern in the same direction<\/li>\n\n\n\n<li>N will advance you to the following instance of the pattern in the opposite direction.<\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-aaa58f13 wp-block-button uag-blocks-common-selector\" style=\"--z-index-desktop:479;;--z-index-tablet:undefined;;--z-index-mobile:undefined;\"><div class=\"uagb-cta__wrap\"><h2 class=\"uagb-cta__title\"><a href=\"https:\/\/arzhost.com\/wordpress-hosting\/\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\/wordpress-hosting\/\">Take Your WordPress Site to New Heights\u2014Sign Up and Save Big!<\/a><\/h2><p class=\"uagb-cta__desc\">Optimized for WordPress\u2014Get Your Hosting Plan at just <strong>$0.99\/month!<\/strong><\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/arzhost.com\/wordpress-hosting\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_self\" rel=\"noopener noreferrer\">Read More<\/a><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Searching for a Word Backward: Commands for Backward Search<\/strong><\/h2>\n\n\n\n<p><u>How to Search to Find a Word in Vim or Vi Text Editor? Type the following in the search box to go backward:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>? pattern<\/code><\/li>\n<\/ul>\n\n\n\n<p>Put the item(s) you want to find instead of a pattern.<\/p>\n\n\n\n<p><u>For instance, if you wanted to find every instance of the pattern &#8220;nologin,&#8221; you would:<\/u><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"536\" src=\"https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2025\/09\/commands-for-backward-search-1024x536.jpg\" alt=\"commands for backward search\" class=\"wp-image-13215\" srcset=\"https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2025\/09\/commands-for-backward-search-1024x536.jpg 1024w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2025\/09\/commands-for-backward-search-300x157.jpg 300w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2025\/09\/commands-for-backward-search-768x402.jpg 768w, https:\/\/arzhost.com\/blogs\/wp-content\/uploads\/2025\/09\/commands-for-backward-search.jpg 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">commands for backward search<\/figcaption><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p><u>1: To make sure Vim\/Vi is in regular mode, use Esc.<\/u><\/p>\n\n\n\n<p><u>2: Enter this command:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>? nologin<\/code><\/li>\n<\/ul>\n\n\n\n<p>Before the cursor, Vim\/Vi highlights the first occurrence of the chosen pattern.<\/p>\n\n\n\n<p><u>To confirm the search, press Enter. So you can:<\/u><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>go to the following occurrence of the pattern while keeping n constant.<\/li>\n\n\n\n<li>hop with N to the following pattern instance in the opposite way.<\/li>\n<\/ol>\n\n\n\n<p><strong>Related Article: <a href=\"https:\/\/arzhost.com\/blogs\/how-to-run-a-bash-script-in-terminal\/\">Run a Bash Script in Terminal<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Looking for a New Word<\/strong>: Changing Search Terms Efficiently<\/h2>\n\n\n\n<p>The word where the cursor is situated is the current word.<\/p>\n\n\n\n<p>Move the cursor to a word and tell Vim\/Vi to look for the next instance of that word rather than describing the pattern and asking it to find it.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Check that normal mode is selected by hitting Esc.<\/li>\n\n\n\n<li>Next, position the pointer over the desired word.<\/li>\n\n\n\n<li>You can: from here\n<ul class=\"wp-block-list\">\n<li>Use * to find the following occurrence of the word.<\/li>\n\n\n\n<li>Look for the word&#8217;s prior occurrence using #<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>Each time you press * or # the cursor moves to the next\/previous instance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Searching for Whole Words Only: Avoiding Partial Matches<\/strong><\/h2>\n\n\n\n<p><u>How to Search to Find a Word in Vim or Vi Text Editor? To search for whole words, use the command:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>\/\\<\/code><\/li>\n<\/ul>\n\n\n\n<p>The text editor only highlights the first whole word precisely as specified in the command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Steps to Open Files Directly at a Word: Practical Use Cases<\/strong><\/h2>\n\n\n\n<p>Vim (and Vi) can open files at a specified word allowing you to skip a step and go directly to the searched term.<\/p>\n\n\n\n<p><u>To open a file at a specific word, use the command:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>vim +\/word [file_name]<\/code><\/li>\n\n\n\n<li><code>or<\/code><\/li>\n\n\n\n<li><code>vi +\/word [filename]<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>For example, to open the \/etc\/passed file where it first uses the term &#8220;root&#8221;, use the command:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>vim +\/root \/etc\/passed<\/code><\/li>\n<\/ul>\n\n\n\n<p>The first line that the text editor shows when it opens the file and displays the word &#8220;root&#8221; is shown in the illustration below.<\/p>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-af73b687 wp-block-button uag-blocks-common-selector\" style=\"--z-index-desktop:479;;--z-index-tablet:undefined;;--z-index-mobile:undefined;\"><div class=\"uagb-cta__wrap\"><h2 class=\"uagb-cta__title\"><a href=\"https:\/\/arzhost.com\/rdps\/\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\/rdps\/\">Remote Work Made Easy \u2013 Sign Up now &amp; Save Big Today!<\/a><\/h2><p class=\"uagb-cta__desc\">Secure &amp; Fast Window VPS by <strong><a href=\"https:\/\/arzhost.com\/\" data-type=\"link\" data-id=\"https:\/\/arzhost.com\/\">ARZ Host<\/a><\/strong>\u2013 Start for Just $18\/month with Our Limited-Time Offer!<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/arzhost.com\/rdps\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_self\" rel=\"noopener noreferrer\">Read More<\/a><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Performing Case-Insensitive Searches: Benefits and Use Cases<\/strong><\/h2>\n\n\n\n<p>When searching within the file, Vi(m) defaults to treating the case differently. For instance, when you search for the term &#8220;user,&#8221; results without the capital U are not displayed (i.e., User).<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Case insensitivity can be achieved in Vim\/Vi in a number of ways.<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>Use the following command to conduct a case-insensitive search for a certain word:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>\/\\&lt;word\\&gt;\\c<\/code><\/li>\n<\/ul>\n\n\n\n<p><u>How to Search to Find a Word in Vim or Vi Text Editor? Vi(m) is told to ignore case and display all results thanks to the c property.<\/u><\/p>\n\n\n\n<p><iframe title=\"YouTube video player\" src=\"https:\/\/www.youtube.com\/embed\/L5ewyLIlY-0\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n\n\n\n<p><u>Vim can be configured to ignore case for all searches across the entire session as an alternative. Run the following command to do so:<\/u><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>: set disregard case<\/code><\/li>\n<\/ul>\n\n\n\n<p>The configuration file can also be changed to make the text editor disregard the case permanently. Add the line: set ignore-case to the. vimrc file by opening it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Featured Search Results<\/strong>: Highlighting Important Matches<\/h2>\n\n\n\n<p>The nice feature in Vi(m) that emphasizes search results in the file is quite helpful. Enter the following command in the text editor to enable highlighting:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>hlsearch set<\/code><\/li>\n<\/ul>\n\n\n\n<p>Run: to turn off this functionality.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>set to \"hlsearch\"<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Understanding Search History in Vim\/Vi<\/strong><\/h2>\n\n\n\n<p>Vi (m) records the search commands used throughout the session. Use the up and down keys along with the characters. or \/ to navigate through previously used commands.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>After reading this tutorial, &#8220;How to Search to Find a Word in Vim or Vi Text Editor?&#8221; you will see many possibilities for using Vim to search for and find words.<\/p>\n\n\n\n<p>Once the search term has been located, you can continue by text-cutting, copying, or pasting.<\/p>\n\n\n\n<p><strong>Read More:<\/strong><\/p>\n\n\n<ul class=\"wp-block-latest-posts__list wp-block-latest-posts\"><li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/how-to-fix-403-forbidden-error-wordpress\/\">How To Fix 403 Forbidden Error WordPress<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/how-to-get-the-most-out-of-claude-ai\/\">How To Get The Most Out Of Claude Ai<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/bad-gateway-error-502-the-ultimate-guide-to-quick-fixes\/\">Bad Gateway Error (502): The Ultimate Guide to Quick Fixes<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/a-deep-dive-into-todays-best-linux-distros\/\">A Deep Dive Into Today\u2019s Best Linux Distros<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/arzhost.com\/blogs\/domain-investor-terms-powerful-strategy\/\">Domain Investor Terms: Expert Insight on Powerful Strategy<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Overview of Vim\/Vi Editor: Importance of Efficient Searching Text editors like How to Search to Find a Word in Vim or Vi Text Editor? and its predecessor Vi are extensively used. They may be found on the majority of Linux and macOS distributions and are both open-source (free). Finding terms or patterns to search for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6156,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"class_list":["post-4613","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/4613","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/comments?post=4613"}],"version-history":[{"count":5,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/4613\/revisions"}],"predecessor-version":[{"id":13216,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/4613\/revisions\/13216"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/media\/6156"}],"wp:attachment":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/media?parent=4613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/categories?post=4613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/tags?post=4613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}