my usual vim command
command
常用的命令
| shortcuts | |
|---|---|
| J | 将下一行拼接到当前行 |
| i + ctrl + j | 分割成两行 |
| y | 复制到寄存器 |
| p | 从寄存器粘贴 |
| yy | 复制当前行到寄存器 |
| n+yy | 复制从当前行开始的n行到寄存器 |
| x | del |
| X | del before |
| dd | 删除当前行 |
| ^ | 光标移动到行首 |
| $ | 光标移动到行末 |
| gg | 光标移动到文件头 |
| GG | 光标移动到文件末行 |
| u | undo |
| ctrl+r | redo |
| :q | quit |
| :q! | quit forcely |
| :wq | save and quit |
| ZZ | save and quit |
| . | replace last command |
command with num
| command with num | |
|---|---|
| ndd | del n line |
| d1G | del words from current to the head of file |
| dG | del words from current to the end of file |
| d$ | del words form current to the end of line |
| d0 | del words form current to the head of line |
| yy | |
| nyy | |
| y1G | |
| yG | |
| y$ | |
| y0 |
还可以在block mode和line mode的情况下使用这些命令.进而对选中块或者选中的行做操作.
replace words
| replace words | |
|---|---|
| :s/xx/yy/g | use yy instead of xx once |
| :%s/xx/yy/g | use yy instead of xx all |
| :n1,n2s/xx/yy/g | use yy instead of xx bewtean line n1 and line n2 |
| :s/xx/yy/gc | use yy instead of xx once needed user confirm |
mode
| change mode | |
|---|---|
| a, A, i, I, o, O | insert mode |
| r | replace one |
| R | replace mode |
多文件编辑
| edit mutil files | |
|---|---|
| :bn | 编辑下一个文件 |
| :bN | 编辑上一个文件 |
| :E | 浏览文件列表 |
| :files | 浏览打开的文件列表 |
多窗口功能
| 多窗口功能快捷键 | |
|---|---|
| :sp {filename} | 新窗口打开文件 |
| ctrl + w + j | 移动到下面窗口 |
| ctrl + w + ↓ | |
| ctrl + w + k | 移动到上面窗口 |
| ctrl + w + ↑ |
环境变量设置
| vim 的环境设置参数 | |
|---|---|
| :set nu | 设置行号 |
| :set nonu | 取消行号 |
| :set hlsearch | 高亮搜索结果 |
| :set nohlsearch | |
| :set autoindent | 启动自动缩排 |
| :set noautoindent | |
| :set backup | auto backup |
| :set ruler | 右下角状态栏(行号,列号,百分比) |
| :set showmode | show mode on lower left corner |
| :set backspace=(0 1 2) | insert mode 下通过backspace来删除时候的限制. |
| :set all | show all environment args |
| :set | show all environment args different with default |
| :syntax on | 是否依据程序相关的语法显示不同的颜色 |
| :syntax off | |
| :set bg=dark | 显示不同的色调 |
| :set bg=light | default |
不建议直接修改/etc/vimrc
而是修改~/.vimrc,这样不会影响其他用户.
~/.vimrc中,$set$前面可以不见冒号.
DOS和LINUX的换行符
使用cat -A查看Windows的文本文件.可以看到Windows的换行符是^M$,称之为CR和LF
而在LINUX下仅使用LF($)作为换行符.
:set ff=unix 强制将文件转化为unix格式.
项目下建立tags
ctags -R .
| vim ctags plugin | |
|---|---|
| :ctrl + ] | 跳转到函数定义 |
| :ctrl + o/t | 跳转到之前 |
| :ta name | 跳转到变量定义 |
recovery
vim打开的文件,异常退出.再次打开,可以从.xxx.swap中恢复.恢复后,退出然后需要手动删除swap文件.这样下次就不会打开就不会提示需要修复.