vim常用命令
一、vim命令快速查询图
二、常用命令
打开多个文件 vim file1 file2
文件切换 :ctrl+^
显示行号:nu
显示隐藏字符:set invlist
还原:set nolist
/word 向下查找word
?word 向上查找word
n 重复前一次查找
N 重复前一次查找,反向进行
:n1,n2s/word1/word2/g n1,n2为数字,从n1到n2行,将word1替换为word2
:1,$s/word1/word2/g 从第一行到最后一行,将word1替换为word2
:1,$s/word1/word2/gc 替换前确认confirm是否需要替换。
复制到最后一行 yG p粘贴
:%d 或者ggdG 删除所有内容
:set tapstop=4 设置tab为4个空格
三、一些小技巧
设置自己的签名
[root@localhost ~]# cat .vimrc map <F4> ms:call AddAuthor()<cr>'s function AddAuthor() let n=1 while n < 5 let line = getline(n) if line =~'^\s*\*\s*\S*Last\s*modified\s*:\s*\S*.*$' call UpdateTitle() return endif let n = n + 1 endwhile call AddTitle() endfunction function UpdateTitle() normal m' execute '/* Last modified\s*:/s@:.*$@\=strftime(": %Y-%m-%d %H:%M")@' normal " normal mk execute '/* Filename\s*:/s@:.*$@\=": ".expand("%:t")@' execute "noh" normal 'k echohl WarningMsg | echo "Successful in updating the copy right." | echohl None endfunction function AddTitle() call append(0,"#!/bin/bash") call append(1,"#==========================================================") call append(2,"# Author : bianjiang") call append(3,"# Email : bianjianjiangjiang@gmail.com") call append(4,"# Last modified : ".strftime("%Y-%m-%d %H:%M")) call append(5,"# Filename : ".expand("%:t")) call append(6,"# Description : You know what i mean,hehe") call append(7,"#==========================================================") echohl WarningMsg | echo "Successful in adding the copyright." | echohl None endfunction