The use of vim in Linux and its high efficiency skills

Philosophy of life 2020-11-07 20:19:19
use vim linux high efficiency


One . About vim Editor

Vim Is a similar to Vi The famous and powerful 、 Highly customizable text editor , stay Vi Many features have been improved and added .VIM It's free software .vim Can be viewed as

vi Updated version of , He can display special information in a variety of colors .

[root@node5 ~]# rpm -qf `which vim`
vim-enhanced-7.4.160-5.el7.x86_64
[root@node5 ~]# rpm -qf `which vi`
vim-minimal-7.4.160-2.el7.x86_64
# You can see from the output ,vim yes vi Added version of , The most obvious difference is vim Grammar can be highlighted , It's fully compatible vi

Two .vim Editor Mode

1.vim The editor has three modes , The first entry is in general mode , In the lower left corner “Insert” It's editing mode , Input : It's command line mode .

  • ​ How to switch from edit mode to command line mode ? Edit mode ->esc-> General pattern ->: -> Command mode
  • ​ How does general mode enter editing mode ? Press a or i or o or A or I or O
image-20201010173449952

image-20201010173559526

2. summary :vim How to enter other modes ?

  • ​ a A o O i I All of them can be inserted , Edit mode
  • ​ : Enter command line mode
  • ​ v Enter visual mode
  • ​ ctrl+v Enter visual block mode
  • ​ V Enter visual line mode
  • ​ R erase 、 rewrite , Go to replace mode
  • ​ When you enter the above mode , Want to quit , Press esc

3、 ... and . Basic operations in general mode

i Insert... Before the current character ( In front of the cursor )
I Insert... At the beginning of the line ( Head of line )
a Insert... After the current character ( After the cursor )
A Insert at the end of the line ( At the end of the line )
o Insert... In the next line ( Another line )
O Insert... In the previous line ( Insert... In the previous line )
x Delete one character back Equate to delete
X Delete a character forward
u Undo one step Cancel every time you press
r Replace , "r" Command is not an operator command . It waits for you to type the next character to replace the character under the current cursor ."r" A command count before a command is to replace multiple characters with the character to be entered . To replace a character with a newline character, use "r". It will delete a character and insert a newline character . Using command counting here will only delete the specified number of characters :"4r" Will put 4 Replace characters with a newline character .
# Cursor positioning
hjkl Lower left, upper right
0 and home Key to switch to the beginning of the line , $ and end Key to switch to end of line
gg Quickly navigate to the first line of the document , G Go to no line
3gg perhaps 3G Fast track to 3 That's ok
/string( character string ) ----- Find or locate the word or content you are looking for , If there are more matches , We can go through N、n To search up and down , also vi Will highlight what you find , Cancel using :noh
/^d ----^ What does the meaning begin with ,, Look for letters d Content at the beginning
/t$ -----$ What is the end of meaning ,, Look for letters t Ending content
vim + a.txt After opening the file , The cursor will automatically be on the last line of the file
# Edit the text
# Delete 、 Copy 、 Paste 、 revoke
y Copy ( In characters ): Means to copy a single character , If you want to copy the whole line , use yy( Behavior unit ),"y" The operator command copies the text to a register 3 in . And then you can use "p" Order it back . because "y" It's an operator command , So you can use "yw" To make a copy of word. You can also use the command to count . In the following example "y2w" Command to copy two word,"yy" Command to copy a whole line ,"Y" It's also copying the entire line , The command to copy the current cursor to the end of a line is "y$".
Copy N That's ok : Nyy , such as : 2yy , Represents replication 2 That's ok
dd( Delete , Behavior unit , Delete the current cursor line )
Delete N That's ok : Ndd , such as : 2dd , Said to delete 2 That's ok
p : P Paste
shear : dd
x Deletes the character where the cursor is located
D Delete from cursor to end of line
u Cancel the operation
ctrl+r Restore undone operations , Restore the undo operation back to , That is to say, what is it like before the cancellation , What would it look like again
r Replace , Or to modify a character , "r" Command is not an operator command . It waits for you to type the next character to replace the character under the current cursor ."r" A command count before a command is to replace multiple characters with the character to be entered . To replace a character with a newline character, use "r". It will delete a character and insert a newline character . Using command counting here will only delete the specified number of characters :"4r" Will put 4 Replace characters with a newline character .

Four .V Pattern ( Column mode ) Basic operation of

1. Get into v Pattern Move the cursor to select the area , The steps of making multi line comments when programming :

  • ​ ctrl+v Enter column edit mode
  • ​ Move the cursor down or up , Put the need to comment on 、 Select the beginning of the edit line
  • ​ If you need to delete , Just type x Key to delete
  • ​ If you want to add content , Just press in capitals I
  • ​ Then insert the comment or the symbol you need to insert , such as "#"
  • ​ Press again Esc, It's all annotated or added

2. Delete : Press again ctrl+v Enter column edit mode ; Move the cursor down or up ; Select the comment section , Then press d, It will delete the comment symbol .

5、 ... and . Basic operations in command mode

:w preservation save
:w! Force save
:q No changes have been made , sign out quit
:q! Revised , Do not save , Forced exit
:wq Save and exit
:wq! Force save and exit
:x Save and exit
# Call an external file or command
hypothesis : I want to write to my network card MAC Address , I want to check , The current in vim Edit document , Copywriting . It's so troublesome .
Operate in command line mode :
:!ifconfig Invoking system commands
!+ command
Read other files .( Append the contents of other files to the current document )
:r /etc/hosts
# Text substitution
# Format : Range ( among % All contents ) s Separator Old content Separator New content ( Separators can be customized )
# Default is the first qualified word in each line (/g All )
:1,3 s/bin/xuegod # Replacement section 1 To 3 The first one in the line bin Replace with xuegod
:1,3 s/bin/xuegod/g # Replacement section 1 To 3 Find all the bin Replace with xuegod
:3 s/xue/aaaaa # Just put the 3 The line is replaced by
:% s/do/xuegod/g # Put all the do Replace with xuegod
:% s/do/xuegod/gi # Put all the do Replace with xuegod, And ignore do The case of
:% s@a@b@g # Put all the a Replace with b

6、 ... and . Customize vim Environmental Science

You can customize it according to your preference vim Environmental Science .

# Temporary settings vim Environmental Science
:set nu # set nu
:set nonu # Unset line number
:noh # set nohlsearch
# Permanent settings vim Environmental Science
[root@node5 ~]#vim /etc/vimrc # After setting, it will affect all users of the system
[root@node5 ~]#vim ~/.vimrc # In the user's home directory , Create a .vimrc. This only affects one user , I didn't build one myself
example :
[root@node5 ~]# cat /root/.vimrc
set nu

7、 ... and .vim Open multiple files at the same time

1. Above and below , Open two documents , Use ctrl+ww Switch editing between two documents

# Lowercase o Split up and down
[root@node5 ~]#vim -o /etc/passwd /etc/hosts

2. Open two documents left and right , Use ctrl+ww Switch editing between two documents

# Capitalization O Left and right split screen
[root@node5 ~]#vim -O /etc/passwd /etc/hosts

8、 ... and . Compare the contents of the two files

There are two ways to compare the contents of two files :diff and vimdiff.

[root@node5 ~]#cp /etc/passwd mima.txt
[root@node5 ~]#echo aaa >> mima.txt
[root@node5 ~]#diff /etc/passwd mima.txt
40a41
> aaa
[root@node5 ~]#vimdiff /etc/passwd mima.txt
版权声明
本文为[Philosophy of life]所创,转载请带上原文链接,感谢

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云