The Vim learning of Linux

Source: Internet
Author: User

Vim is divided into three modes: General mode, edit mode, command mode

1. General mode

General mode can move cursor, delete, paste copy and other operations
Move Cursor Action

h或向左箭头:光标左移动一个字符j或向下箭头:光标下移动一个字符k或向上箭头:光标上移动一个字符l或向右箭头:光标右移动一个字符30j:光标下移动30DownDown(常用)ctrl+d:屏幕向下移动半页ctrl+u:屏幕向上移动半页n<space>右移动n个字符0或home键:移动到最前面字符处(常用)H:移动到屏幕的最上方那一行的第一个字符M:移动到屏幕的中央那一行的第一个字符L:移动到屏幕的最下方的第一个字符G:移动到文件的最后一行(常用)nG:移动到文件的第n行gg:移动到文件的第一行,相当于1G(常用)n[Enter]:向下移动n行(常用)

Search and replace

/word:向光标之下搜索word的字符串?word:向光标之上搜索word的字符串n:继续向下搜索N:继续想上搜索n1,n2s/word1/word2/g:在n1到n2行搜索word1这个字符串并将字符串替代为word2(常用)1,$s/word1/word2/g:在1到最后一行搜索word1这个字符串并将字符串替代为word2(常用)1,$s/word1/word2/gc:在1到最后一行搜索word1这个字符串并将字符串替代为word2!且在取代之前显示提示字符给用户确认是够需要取代(常用)

Delete, copy and paste on

x,X:在第一行当中,x为向后删除一个字符,X为向前删除一个字符(常用)nx:向后删除n个字符dd:删除光标所在一行ndd:删除光标所在n行d1G:删除光标所在到第一行的所有数据dG:删除光标所在到最后一行的所有数据d$:删除光标所在到该行的最后一个字符d0:删除光标所在到该行的最前面的一个字符yy:复制光标所在的那一行(常用)nyy:复制光标向下的n行(常用)y1G:复制光标所在列到第一行的所有数据yG:复制光标所在列到最后一行的所有数据y0:复制光标所在字符到该行行首的所有数据y$:复制光标所在字符到该行行首的所有数据p,P:p将已复制的数据在光标下一行贴上,P贴在光标上一行J:将光标所在行与下一行的数据结合成同一行u:撤销上一个动作(常用)ctrl+r:重做上一个动作(常用).:(小数点)重做前一个动作(常用)
2. Edit mode

General mode switch to edit mode

i,I:i为从目前光标所在处插入,I为目前所在行的第一个非空格处开始插入a,A:a为进入目前光标所在处的下一个字符处开始插入,A为光标所在行的最后一个字符处开始插入o,O:a为进入目前光标所在处的下一行开始插入,A为光标所在行的上一行开始插入r,R:进入取代模式,r会取代所在的那一个字符一次;R会一直取代光标所在的文字,直到按下ESC为止
3. Command-line mode
w:写入wq:保存后离开q!:不存储离开w [filename]:另存为filenamer [filename]:将filename这个文件的内容加到光标所在行的后面n1,n2 w [filename]:将n1行到n2行的内容另存为filename文件!command:暂时离开vim到指令下查看commmad执行的显示结果,如!ls /home 即可在vim下查看/home下的输出信息set nu:设置数字set nonu:与上向反
4. Additional features of Vim 1. Block selection See


2. Multi-file editing

Vim can open several files at the same time, the content of one file can be effectively assigned to another file

n:编辑下一个文件N:编辑上一个文件files:列出目前这个vim的开启文件
3. Multi-Window function
sp {fielname}:开启一个新窗口,如果有加filename,表示在新窗口中加入一个新文件;否则表示两个窗口为同一个档案显示(同步显示)其中filename要是不填写的话,则同一个文件出现在两个窗口ctrl+w+↓(j):窗口向下移动,先按下ctrl+w,然后按下j即可ctrl+w+↑(k):...

It is really convenient to copy and consult.

4.vim environment Setting and logging: ~/.vimrc,~/.viminfo

The ~/.viminfo file automatically generates and records your actions in Vim.

Vim common environment settings see



Common configuration file to specify the VIM operating environment, the overall Vim setting value is in the/ETC/VIMRC file, but not recommended modification, you can modify the ~/.VIMRC this file (if it does not exist, can be created by itself)

The Vim learning of Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.