记录一下自己的VIM配置文件
本人确实抽出一定的时间去研究 vim。不过我对它的使用依然仅限于在终端操作 linux 系统时,对文本文件的编辑,例如修改配置文件。就算使用 vim 写代码,也只是写一些很简单的代码。在我看来,它是没有一些成熟的 IDE 好用的。所以这篇记录自己 vim 的配置文件的博客就不单独开一个关于 vim 的分类了。发表在我的日志,方便自己查找即可。
.vimrc
文件
"---------------------------------------- vim 包管理工具 ----------------------------------------
" 使用Vundle进行包管理
" 导入配置
source ~/.vim/VundleVim.vim
"---------------------------------------- vim 基本设置 ----------------------------------------
" 导入 vim 的示例配置
source $VIMRUNTIME/vimrc_example.vim
" 配置文件格式识别
filetype plugin indent on
" 语法高亮显示
" syntax on
" 开启语义分析
syntax enable
" 设置背景颜色
set bg=dark
" 设置字体主题颜色
set t_Co=256
let g:gruvbox_italic=1
colorscheme gruvbox
" 文件格式化
set fileformat=unix
" 横向切分窗口后新窗口在下方
set splitbelow
" 纵向切分窗口时新窗口在右面
set splitright
" 显示匹配
set showmatch
" 开启英文拼写检查
" set spell
" set spelllang=en
" 标记行号
set number
" 设置文件编码
set enc=utf-8
" 设置 vim 不需要和 vi 兼容
set nocompatible
" 不产生备份文件
set nobackup
" 设置撤销文件路径
set undodir=~/.vim/undodir
" 启动标尺
set ruler
" 启动时不显示援助乌干达儿童的提示
set shortmess=atI
set modeline
" 显示输入的命令
set showcmd
" 设置制表符为4个空格
set tabstop=4
set softtabstop=4
set shiftwidth=4
" 浅色高亮当前行
auto InsertEnter * se cul
" 如果撤销文件路径不存在就创建
if !isdirectory(&undodir)
call mkdir(&undodir,'p',0700)
endif
" 鼠标支持
if has('mouse')
if has('gui_running') || (&term =~ 'xterm' && !has('max'))
set mouse=a
else
set mouse=nvi
endif
endif
"---------------------------------------- vim 搜索 ----------------------------------------
" 关闭搜索高亮
set nohlsearch
" 增量搜索
set incsearch
" 忽略大小写
set ignorecase
" 智能匹配大小写
set smartcase
"---------------------------------------- vim UI ----------------------------------------
" 配置光标颜色
if &term =~ "xterm"
" INSERT MODE
let &t_SI = "\<Esc>[5 q" . "\<Esc>]12;white\x7"
" REPLACE MODE
let &t_SR = "\<Esc>[3 q" . "\<Esc>]12;black\x7"
" NORMAL MODE
let &t_EI = "\<Esc>[2 q" . "\<Esc>]12;salmon\x7"
endif
" 配置 airline
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
let g:airline#extensions#tabline#overflow_marker = '...'
let g:airline#extensions#tabline#show_tab_nr = 0
" 配置 Matrix
nnoremap <leader>m :Matrix<CR>
"---------------------------------------- vim 搜索 ----------------------------------------
" 在插入模式或者命令模式中,使用 ctrl 来移动
inoremap <C-h> <Left>
inoremap <C-j> <Down>
inoremap <C-k> <Up>
inoremap <C-l> <Right>
cnoremap <C-h> <Left>
cnoremap <C-j> <Down>
cnoremap <C-k> <Up>
cnoremap <C-l> <Right>
" 配置复制粘贴
vnoremap <C-c> "*y
vnoremap <C-v> "*p
nnoremap <C-c> "*y
nnoremap <C-v> "*p
" 配置返回至 normal 模式的快捷键
inoremap jj <Esc>
vnoremap jj <Esc>
cnoremap jj <Esc>
" 配置 NERDTreeToggle
nnoremap <C-t> :NERDTreeToggle<CR>
" 配置文件树的位置
let NERDTreeWinPos="left"
" 配置括号自动补全
" 花括号自动格式化,首行一个tab
autocmd FileType cpp,c,java inoremap { {<CR>}<ESC>kA<CR>
" 括号匹配
inoremap ( ()<ESC>i
inoremap [ []<ESC>i
inoremap ' ''<ESC>i
inoremap " ""<ESC>i
.vim/VundleVim.vim
文件
" 插件管理的文件
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
"Plugin 'ycm-core/YouCompleteMe' " 代码自动完成
Plugin 'preservim/nerdtree' " 展示文件树
Plugin 'vim-airline/vim-airline' " 状态显示更丰富
Plugin 'uguu-org/vim-matrix-screensaver' " 没啥大用
Plugin 'morhetz/gruvbox' " 配色方案
Plugin 'qpkorr/vim-renamer' " 文件批量更名
Plugin 'tpope/vim-fugitive' " git 工具
" Plugin 'iamcco/markdown-preview.nvim' " markdown 预览工具
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
" Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
" Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
" Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
" Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line