Quantcast
Channel: GoLinuxHub
Viewing all articles
Browse latest Browse all 392

How to do a case sensitive search inside vi editor in Linux

$
0
0
VI editor can sometimes be very tricky and irritating if you are not fully aware of those small arguments which could make your life much easier while working on the editor. One such thing when are trying to search a string and you want the search to be case sensitive.

Let me tell you some special arguments which can be used for this purpose

How to search a string in vi editor?

  • Exit the editing mode i.e. INSERT mode by pressing "Esc" from your keyboard
  • Then press Forward Slash "/"
  • Next type the string you want to search which should appear at the lower left bottom of the editor
  • Hit Enter

If the searched string exists in the file, then it would be  highlighted  in some color.

To perform a Case sensitive search

Using the above method the search is normal and not case sensitive so there is a probability that you might miss out any word with a different case. To make sure you get everything as required follow the below steps

  • Press "Esc" to exit the INSERT mode
  • Then type ":set smartcase"

Now if you search for "The" string then you will get all the words having "The" with capital "T" and others would be skipped i.e. "the".

To remove a case sensitive search


  • Press "Esc" to exit the INSERT mode.
  • Then type ":set ignorecase"

Using this if you search "THE", then all the words ir-respective of their case would be highlighted

You can also use ":set ic" to set ignore space and ":set noic" to set smartcase.

NOTE: Once all the search strings are highlighted you can go the next matched word by pressing "n" and in case you want to search backward then press "N". To go the first search in the file press "ggn"

I hope this article was useful.

Related Articles:
10 practical examples to use USERADD command in linux
10 Practical Examples for using FIND Command in Linux
10 examples to help you understand top command usage in Unix/Linux
15 tips to enhance security of your Linux machine


Follow the below links for more tutorials

How to configure iscsi target using Red Hat Linux
What are the different types of Virtual Web Hosting in Apache
Comparison and Difference between VMFS 3 and VMFS 5
How to configure PXE boot server in Linux using Red Hat 6
How to secure Apache web server in Linux using password (.htaccess)
How to register Red Hat Linux with RHN (Red Hat Network )
How does a DNS query works when you type a URL on your browser?
How to create password less ssh connection for multiple non-root users
How to create user without useradd command in Linux
How to give normal user root privileges using sudo in Linux/Unix
How to do Ethernet/NIC bonding/teaming in Red Hat Linux
How to install/uninstall/upgrade rpm package with/without dependencies
Why is Linux more secure than windows and any other OS
What is the difference between "su" and "su -" in Linux?
What is the difference/comparison between Unix and Linux ?
RAID levels 0, 1, 2, 3, 4, 5, 6, 0+1, 1+0 features explained in detail


Viewing all articles
Browse latest Browse all 392

Trending Articles