自己整理的VIM/GVIM入门操作

VIM具有强大功能,本人是IC小白,刚接触Linux,我也正在逐渐学习中,学成了会继续更新,此文章现记录自己整理的VIM的入门操作和配置。

如有错误请您及时指出,如果您有指导意见也请留言。

VIM基本操作汇总:v

(vim命令是区分大小写的,命令用大写时按住shift或者按大写锁定)
i = insert (before)
a = insert (after)

ESC = quit the insert mode

: = insert command

:w = save
:w filename = save filename

:q! = quit without saving
ZZ = quit without saving
:wq = save and quit

x = delete (current)删除当前光标选中的字符,字符全部删除完了不会删除一行,只会空着一行
X = delete (left)删除当前光标选中字符左边的字符
dd = delete line直接删除光标所在行的全部字符,同时删除空白的一行,下面的行网上移
S = delete line and insert直接删除一行的全部字符并进入insert模式

yy = copy line
y = copy in block用v选择block后使用的copy

p = paste (after)
P = paste (before)
r =repalce

o = insert a new line (after)
O = insert a new line (before)

. = repeat last command
u = undo last command撤销
ctrl+r = recover last undo反撤销

ctrl+g = info of line

w = next word到下一个单词
b = last word到最后一个单词

^ = line head行首
$ = line tail行尾

gg = first line
G = last line
xG = x line

{ = paragraph head
} = paragraph tail

v = select block 按v再配合方向键能够选择出一块字符
ctrl+v = select block选择矩形区域
y = copy in block
I = insert (before)使用场景:在行首插入#,先用ctrl+v选中行首,然后按I,再输入#,再按ESC即可

:set nu = set number

/ = search forward向下寻找,如果要取消高亮就直接/safafjrioeghriegh(乱七八糟的字符)
? = search backward向上寻找
n = next search
N = last search

J = join two lines 假如有两行想要合并,那就在第一行的任意位置按J即可

:s/1/2 = search 1, replace to 2 1是要替换的字符,2是要替换为的字符,且只替换当前行
:s/1/2/g = search 1, replace to 2, all in line/block只在选中过的block或者行中替换,要先用v或者ctrl+v选中,然后按冒号s/1/2替换
:%s/1/2/g = search 1, replace to 2, all in file 整个文档全部替换

:split filename 打开另一个文件在同一个窗口中横向显示
:vsplit filename打开拎一个文件在同一个窗口种纵向显示(同一个文件也可以在两个窗口中打开,可以打开4个窗口)
ctrl+ww光标移动到另一个文件窗口

qa + ... + q = record commands 先按qa进去记录模式记录所有在记录模式期间的操作,然后按q退出记录模式
@a = do recorded commands 执行记录模式下记录的操作

修改vim的配置文件可以实现很多显示上和输入上的良好体验,以下是我个人的配置:

首先在自己用户文件目录下创建.vimrc文件(gvim .vimrc)

:set number " line number
:set tabstop=2 " number of visual spaces per tab
:set softtabstop=2 " number of spaces in tab when editing
:set shiftwidth=2 " number of spaces when vim autotab for you
":set expandtab " tabs are spaces
:syntax enable " enable syntax processing
:set list
:set listchars=tab:\|\ 
:set background=dark " dark background
:set showmatch " highlight matching {[()]}
:set incsearch " search as characters are entered
:set hlsearch " highlight matches

posted @ 2020-07-16 10:21  yllGoHard  阅读(299)  评论(0)    收藏  举报