# ~/.vimrc 配置文件
" "是注释符号
syntax on
filetype plugin indent on
set t_Co=235 " 设置背景颜色,https://jonasjacek.github.io/colors/
"color molokai " 选择颜色主题,可选koehler,Solarized
syntax enable
set expandtab
set showmatch
set tabstop=8 " 设置制表符宽度为8
set softtabstop=4 " 设置软制表符宽度为4
set autoindent " 使能换行自动缩进功能
set shiftwidth=2 " 设置缩进空格数为2
set mouse=a " 鼠标可移动
set ai!
"set mouse-=a " 开启鼠标粘贴复制
"set cursorline " 光标对齐
"set cursorcolumn
set nu " 设置行号
set relativenumber " 设置相对行号
set hlsearch " 选中高亮
set wrap " 设置自动换行缩进
set paste " 设置多行粘贴自动去除最前面空格,可能需要在粘贴前手动设置.之后set nopaste去除.
set guitablabel=%t " 设置按tab显示文件
set backspace=indent,eol,start # vim中使能backspace来删除功能
:set virtualedit+=onemore # go to last character enable
hi Search ctermbg=Grey " 高亮背景色,会覆盖上面设置的color schema
"hi Search ctermfg=Red " 高亮前景色
"set fillchars=vert:* " 设置分割为符号*
set tags=./tags,tags; " 设置tags的路径
set is hls " 设置全局搜索替换高亮
set wildmenu " vim内指令自动补全
set background=dark. " comment is gray
nnoremap 0 $ # map将0映射成$功能
nnoremap 9 0
nnoremap ;; <C-w>w # 用;;替换ctrl+ww切换分页
" 用F5案件来代替运行:source ...vimscript.vim脚本。<CR>换行
noremap <F5> :source ~/.vim/config/vimscript.vim <CR>
highlight LineNr ctermfg=DarkGrey " 设置行号颜色
" 配置cpp高亮:https://github.com/octol/vim-cpp-enhanced-highlight
highlight Comment ctermfg=DarkGrey " 设置注释行的颜色,但是必须在设置背景色之后才能生效
highlight CursorLineNr ctermfg=Grey " 设置当前光标行的背景色
highlight VertSplit ctermfg=235 ctermbg=240 " 设置分割线前后背景色
highlight StatusLineNC ctermfg=235 ctermbg=240 " 设置横向分割线颜色
highlight StatusLine ctermfg=235 ctermbg=208 " 设置状态栏颜色
# 配色
wombat256.vim - Wombat for 256 color xterms : vim online 下载
sudo mv wombat256.vim /usr/share/vim/vim74/colors/
在vimrc里添加 color wombat256
https://www.slant.co/topics/480/~best-vim-color-schemes
**vim plugin插件**
# vim plug
https://github.com/junegunn/vim-plug
## NERDTree
mkdir -p ~/.vim/pack/vendor/start
git clone --depth 1 https://github.com/preservim/nerdtree.git ~/.vim/pack/vendor/start/nerdtree
# 或者
Plug 'preservim/nerdtree'
# 在vim中输入:NERDTree即可使用tree插件
# Gblame插件,参考https://github.com/tpope/vim-fugitive
mkdir -p ~/.vim/pack/tpope/start
cd ~/.vim/pack/tpope/start
git clone https://tpope.io/vim/fugitive.git
vim -u NONE -c "helptags fugitive/doc" -c q
# 在vim输入:Gblame即可看到log信息
# 同理,其他plugin插件一样安装
# fzf需要用plug-vim安装,参考https://github.com/junegunn/vim-plug/wiki/tutorial
# command:
# :F 然后输入Enter
# cpp等高亮参考vim awesome:https://vimawesome.com/plugin/vim-cpp-enhanced-highlight
# log文件高亮: https://github.com/MTDL9/vim-log-highlighting
# 更改~/.vim/plugged/vim-log-highlighting/ftdetect/log.vim文件可以添加其他后缀文件作为log文件风格
# grep: https://github.com/mhinz/vim-grepper
# ack: https://github.com/mileszs/ack.vim
# 系统先安装ack:apt-get install ack-grep 然后找到ack.ag等位置是否在/usr/bin目录下
# ~/.vimrc: let g:ackprg = "/usr/bin/ag --vimgrep --color --color-line-number --color-match"
# 或者映射grep : let g:ackprg = "grep -Hrn"
# command:
# :Ack 'PATTERNS' dir
# :Ack 'PATTERNS' dir | grep things
# vim command
vim -O file1 file2 # 同时左右分屏打开两个文件
vim -d file1 file2 # 比较两个文件内容
# tag
使用tag自动跳转功能前,需要先对工程使用ctags -R XXX # 对XXX整个工程使用tag功能
command in vim:
# 符号含义
p # 粘贴
y # 复制
d # 剪切
u # 撤回
b # before
w # go to begin of next word
e # go to end of current word
^ # go to first word of line
$ # 最后一个字符
0 # 第0个字符
gg # 回到第一行
G # 回到最后一行
:wq # 保存退出 当然要先按esc退出编辑模式
:q! # 不保存退出
:b Tab # 快速索引打开之前打开过的文件,比如:b a.cpp
:10,20d # 删除第10到20行内容
5dd # 删除当前行之后的5行
:5,15s/dog/cat/g # 将5到15行中的dog替换未cat
:%s/dog/cat/g # 全局替换
:Gblame # 查看文件修改信息
:e ../a.cpp # vim中打开某个文件
:pwd # 查看当前路径,terminal命令
:ls # 查看当前目录文件
:e % + Tab # 显示打开当前文件的路径
di" # 鼠标到某一行,然后运行。删除这一行中""之间的内容。delete in "
:f or ctrl+g # 查看当前文件名称
g # 帮组菜单
dt} # 删除当前光标到下一个}符号之间的内容, d: delete, t: to
df} # 删除到},包含}. f: forward
dip # 删除当前段落 p: paragraph
diw # 删除整个单词
ciw # 删除整个单词并同时进去insert模式
w # 跳到下一个word
b # 跳到上一个word
gj # go to next line
gk # go to last line
^ # 跳到本行第一个单词开头
yw # 从当前光标处开始复制单词
byw # 如果光标在单词中间,可以复制整个word. b: before,加上光标只之前的word.
CTRL+^ # go back to previous file
viwp # replace this word with yanked word
Ctrl+v+G+I+// #注释到最低行
H # 光标移动到当前屏幕最上面
L # 光标移动到当前屏幕最下面
M # 光标移动到当前屏幕中间位置
zz # 将光标位置移到窗口中间
dG # 删除当前行到最后一行
R/r # replace mode
A # jump to end of line and open insert mode
Ctrl+p # 字符自动补全
f; # f: find 找到符号;的位置
:a # 在当前字符后面进入insert模式
% # 括号匹配跳转
ya( # 复制()内内容,包含()符号 (可以变成任意字符
]} # 跳转到匹配的}大括号地方
zz # move current line to the middle of the screen
zt # move current line to the top of the screen
zb # move current line to the bottom of the screen
ctrl + b # Moves screen up one page, cursor to last line
ctrl + y # Moves screen down one page, cursor to first line
4>> # 后面4行自动向右缩进, >> 向右移动
4<< # 后面4行自动向左缩进
4== # 后面四行自动对齐
. # 重复上一步执行的操作
ahjd [2] ajdhg
dghfu [1] ahkjhf
dhfvifg [0] jhjdhf
:sort r /[.\+]/ # 对文本按照[]内的内存进行正则排序,这样可以用vim处理excel等文件
选中任意区域zf创建一个折叠,zo打开折叠。zfi{折叠{}内内容
) # 跳到下一个空行处
:undolist # 显示文本改动
:earlier 5s # Go to older text state about 5 seconds before.
:Sex # 打开当前文件所在的目录
:terminal # vim中打开一个终端界面
/abc... # 全局搜索字符abc ...表示abc后面三个字符通配任意字符
# vim宏录制
步骤:
qa # 开示录制宏,名字是a
.... # 执行某一个操作
q # 结束宏录制
10@a # 重复10次宏的操作
例子:在文本里输入1到100
1 # 先输入一个基准数1
qa # 开始录制
yy # 复制当前的行
p # 粘贴
Ctrl + a # ctrl +a在vim中可表示将数字加1,即新的一行数据变成2
q # 推出录制
98@a # 在重复98次则得到100个数
当然这里多个数之间也可插入逗号等操作
例子:在每一行某位插入符号;
// code
abc
line1
line2
// 操作:
首先光标要在abc的上一行
qa
j
A
;
Esc
q
10@a