Vim package is one of open source text editor on terminal in Linux system, this tutorial will explain how to use this tool on your terminal.
Searching word :
/pattern - Search a patten continuing from TOP position
?pattern - Search a patten continuing from BOTTOM position
n - repeat forward search (If press n)
N - repeat backward search (If press N)
Search and Replace:
If you need to Search and update a specific word or line for example would like to change the value to VALUE
#!/bin/sh
echo"Enter the value"
read value
echo "Output is $value"
echo "no-output"
Open the file, press ESC, enter the below command,
:%s/value/VALUE/g
or do you want to remove the line (echo "no-output")
:%s/echo "no-output"//g
Text Selection, Copy:
If you want to do the same thing in your file like collection of lines, cut, copy, format. First, need to select the text or lines. Leave from insert mode, enter the one of the below options then move up or down the cursor you can see few seclection lines.
v - you can selects range of text
V - you can selects entire lines on that page
ctrl-v - you can selects columns on that page
gv - reselect block
After selecting the text,
Use d - To delete selected lines
Use y - To copy selected lines
Use :s/match/replace/ - To match and replace the lines or :center, or !sort
Comments (0)