vim command
vim and vi are almost the same, the only difference is that when editing a text, using vi will not display the color, while using vim will display the color.
vim has three modes: general mode, editing mode, and command mode.
The vim command is not installed when the system is minimally installed, and you need to use yum to install it yourself:
[root@cham2 ~]# yum install -y vim-enhanced
Move the cursor in normal mode
Added:
Spacebar: move one alphanumeric '0' to the right and shift+6: move the cursor to the beginning of the line
shift+4: move the cursor to the end of the line
Enter: set nu to view the line number
Cut, copy, paste in normal mode
Supplement: Ctrl+r reverses the previous operation
enter edit mode
Return to normal mode "Esc" from edit mode
command mode
Order
/dnsmasq
?dnsmasq
1,100s/dnsmasq/chamlinux/g
1,$s/chamlinux/dnsmasq/g
"nohl"=no high light No highlight, cancel the highlight mark
"x" in the content: save and exit, the difference from wq is that when a file is entered and not edited, using this command will not change the atime of the file.
Find and replace command in edit mode
- eg1: Find abc and replace it with ABC (replace all within a certain range)
'/1,100s/abc/ABC/g' That is: replace all abc in lines 1 to 100 with ABC. (s: replace; g:=global, all. If g is not added, only the first abc of each line will be replaced), '/' can be replaced with # or @. - eg2: Find /etc/hosts and replace it with chamlinux.com.
If you use '/' to execute the command, it will conflict with the replaced object, so use # to execute the command (this method is commonly used), if you still use '/' ' To execute the command, the following operations are required:
'/ \ /etc \ /hosts\/chamlinux.com/g' Here, '\' is a traverser, which means that the following characters are not recognized
vim practice