Ubuntu - Vim - 基本命令

vim基本命令

 

$vimtutor
可以查看基本的vim操作

1

h (left) j(down) k(up) l(right)
q! wq
i: insert before the cursor (insert) 插队嘛,肯定在光标前面
A: append after the line (appending)

2

dw: 删除一个单词,保留光标前面部分
d$:删除光标之后的同行所有部分
dd:删除一行


2w: 当前光标之后第2个单词词首
3e:当前光标之后第3个单词词首
0:行首
$: 行尾
e: 跳到一个单词结尾,可以联系点击

u: to undo previoud actions
U: to undo all the changes on a line
ctrl+r: to undo the undo's

 

3

p(paste)
r(replace)
rx:replace with x

c(change)
ce: change until the end of a word
c$: change until the end of a line
c + number + motion

4

ctrl+g:显示文件名和当前光标所在的行数
G:去最后一行
number+G:去指定number行
gg:去第一行

/word enter n:向下 N:向上
?word enter 默认向上查找
ctrl+o:repeat to go back further
crrl+i:go forward

%:matching parenthese search,匹配(, [, or { } ] )

:s/old/new/g to substitute 'new' for 'old'.
type :#,#s/old/new/g where #,# are the line numbers of the range
of lines where the substitution is to be done.
Type :%s/old/new/g to change every occurrence in the whole file.
Type :%s/old/new/gc to find every occurrence in the whole file,
with a prompt whether to substitute or not.

5

:! shell command # 使用:!可以执行外部shell命令
:w TEST # 将当前文件保存为TEST文件,而当前的文件名仍然不变
:!rm TEST or del TEST # 删除TEST文件
:v 通过jk选择内容之后,在使用:w TEST将选中的内容保存到文件中,然后通过:!dir或:!ls或:!cat TEST查看
同时,通过v选中的内容,然后按d,可以删除对应的选中内容
同时,通过v选中的内容,然后按d,可以删除对应的选中内容,通过p来复制刚刚删除的内容
:r TEST 在光标所在的下一行并入文件TEST的内容
:r !ls 在光标所在的下一行并入ls的内容,而!表示执行外部shell命令

 

6


o:Open command, 在光标下面打开文件
O:在光标上面打开文件
a:在光标所在处追加,i是在前面插队,A是行尾追加

连续替换
R:光标下连续替换,而r只是替换一个字符

复制和粘贴
y:复制(yank),然后p(put pastes)进行粘贴,前提是在v的情况下,进行yank,然后找到合适的位置进行p
j$:复制到行尾

设置选项:set option
设置高亮搜索设置:set hls is # hlsearch incsearch
取消高亮设置:set nohlsearch
在进行搜索之后,可以通过设置忽略大小写,高亮设置,方便搜索
/word
set ic # ignore case
set noic
set hls is # heightligt search / increase search
结束的时候:可以使用set nohlsearch

7help

 

相关文章

解决方案:解决linux下vim乱码的情况:(修改vimrc的内容)全...
Linuxvi/vim所有的UnixLike系统都会内建vi文书编辑器,其他的...
      vim正则匹配:空行:/^$/  /^[\t]*$/注释...
$select-editorSelectaneditor.Tochangelater,run'sele...
上次手贱忘了保存,这次就简单做个备忘吧,把踩过的坑记一下...
Linux之文本编译器小结vim的优势所有的UNIX-LIKE习通都会内置...