
正文
Linux command ------ vi / vim
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
EDIT mode to GENERAL mode: press ESCGeneral mode: operate file
:q! :force to close the file but not save(file has been modified)
:wq! :force to save and close the file
:q : close the file but not save(file hasn't been modified)
:wq : save and close the file
:w:save file
General mode to edit mode
i :insert a charactor before cursor, and enter EDIT mode
a : insert a charactor after cursor, and enter EDIT mode
o : insert a new line backward, and enter EDIT mode
General mode: move cursor
) :cursor move to the end of line
( :cursor move to the beginning of line
G : cursor move to the last line of the file
gg : cursor move to the first line of the file
General mode: delete
dd :delete(cut) the line where cursor is
D : delete the charactors in the back of cursor in a line, include the character of cursor
x,X:in the character of a line, x means "delete the character of cursor", X means "delete the character before cursor
General mode: OTHERS
u :cancel the last operation
:/linux : search linux, then tap 'n' to search the next one
:?linux: search linux, then tap 'n' to search the next one
p : paste the stuff after the line of cursor
P : paste the stuff before the line of cursor
set nu:show row number
General mode: execute cmd without exit vi/vim
:!cmd
不退出vim 执行命令 cmd
:r !cmd
不退出vim执行命令cmd,并将cmd的输出内容插入当前文本中。
:shell
切换到shell里(此时并没有退出vim,可以理解成vim转入后台),你可以在shell中做任何操作,退出shell(比如用exit)后,会切换回原来的vim中
vim 的一些设置
linux环境下vim的初始化配置文件为.vimrc, 通常有两个,分别是系统版本和用户版本,前者不同发行版linux会有不同,一般位于/etc/vimrc,是整个系统vim的默认配置;后者位于~/.vimrc,是当前用户的vim配置,会覆盖系统配置。
vim ~/.vimrc
set tabstop= " 设置当前用户 vim 使用中 tab 是四个空格"set fencs=utf-,GB18030,ucs-bom,default,latin1 " 显示中文字符"set nocompatible "关闭vi兼容模式,可以启用方向键和Backspace"syntax on "自动语法高亮(对于编程语言中的关键字高亮需要下载相应的编程语言对应的"配色方案.vim文件""colorscheme industry "选择industry.vim配色方案,文件在/usr/share/vim/vimxx/colors,推荐 industry、slate、murphy"
不需要执行 source ~/.vimrc 即可生效(执行了反而提示某些指令找不到,比如 syntax)








