今天把电脑里面的Vim直接remove –purge了, 把之前wget的Vim配置全部删了重新来:
1 2 |
rm -rf ~/.vim rm -f .vimrc |
删干净过后就开始自己折腾了:
包管理插件Vundle
从学长那给推荐过来的, 是个包管理插件, 就是用来管理插件的.
安装
1 |
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundleVundle.vim |
然后编辑你的.vimrc文件, 把以下配置内容加进去:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
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 'gmarik/Vundle.vim' " 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 https://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/'} " Avoid a name conflict with L9 Plugin 'user/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 |
然后启动Vim, 运行:
1 |
:PluginInstall |
或者在终端下直接运行
1 |
vim +PluginInstall +qall |
使用
接下来如果需要装插件的话, 只需要在.vimrc文件里的”call vundle#rc()”和”filetype plugin indent on”之间添加 Plugin xxx
- 如果是GitHub上的repo, 那么直接
1 |
Plugin 'username/RepoName' |
不需要添加url链接,
1 |
'username/RepoName' 就等价于 'https://github.com/username/RepoName' |
- 如果是https://vim-scripts.org/vim/scripts.html上面的插件那么直接输入名字即可
1 |
Plugin 'L9' |
- 未存储在GitHub上的git插件
1 |
Plugin 'git://git.wincent.com/command-t.git' |
- 本地的插件
1 |
Plugin 'file:///home/username/...' |
即直接输入插件的本地绝对地址即可
修改完.vimrc文件过后进入Vim输入
1 |
:PluginInstall |
就可以安装了
Statusbar高亮插件airline
安装
直接用Vundle安装插件, 在.vimrc文件里添加:
1 |
Plugin 'bling/vim-airline' |
然后进入Vim输入
1 |
:PluginInstall |
安装好了过后进入Vim可能不会看到任何不同, 这是因为在buffer为小于2的时候默认是不显示的, 要想在buffer为1的时候显示, 就需要在.vimrc文件里面加入:
1 |
set laststatus=2 |
配置
这样的一进入Vim就可以看见效果了, 但是是看不见彩色的, 还需要继续配置字体.
首先下载powerline-fonts:
1 2 3 4 |
mkdir .fonts cd .fonts git clone https://github.com/Lokaltog/powerline-fonts fc-cache -vf ~/.fonts |
然后再在.vimrc里面激活字体
1 2 |
let g:airline_powerline_fonts = 1 set guifont=Ubuntu Mono derivate Poweline 13 //for gvim |
注意还要把终端的字体也设置成选择的.vimrc的字体一样的字体.
再就是主题, 可以选择默认的, 也可以自己安装.
1 2 3 4 5 6 7 |
//安装主题 cd ~/.vim/bundle git clone https://github.com/paranoida/vimairlineis.git //进入Vim :PluginInstall //修改.vimrc文件, 添加 let g:airline_theme = 'airlineish' |
然后这个时候进入Vim还是看不见效果, 是因为终端的是8色, 需要设置为256色才行, 为了这个东西折腾了半天, 后来是还是一只萌学长帮我google到的一个原repo里面的issue, 这个插件的作者在里面给出了解决方案: 在.vimrc文件里面添加
1 |
set t_Co=256 |
接下来就可以看见彩色了.
显示当前git branch vim-fugitive
1 2 3 4 |
//安装 git clone https://github.com/tpope/vim-fugitive ~/.vim/bundle/ //进入Vim :PluginInstall |
然后在.vimrc里面添加:
1 |
let g:airline#extensions#branch#enabled=1 |
即可
Plus:
之所以叫airline是因为这是作者在飞机上写出来的, 我也是醉了= =
General configuration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
"DIY part syntax on //语法高亮 set cul "highlight cursor line //下划线高亮显示当前行 set cuc "col //高亮显示当前列 color ron //设置主题 "color torte set hlsearch "highlight search result //高亮搜索结果 set incsearch filetype on "spy on file type "autocmd InsertEnter * se cuc //用浅色高亮 "set ruler set showcmd set foldenable //手动折叠 set foldmethod=manual set autoindent //自动缩进 set cindent "The width of Tap set tabstop=4 //Tab键 set softtabstop=4 set shiftwidth=4 set number //设置行号 |
新建文件自动插入Title, ACMer专用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
"new file title autocmd BufNewFile *.cpp,*.c,*.sh exec ":call SetTitle()" func SetTitle() if &filetype == 'sh' call setline(1, "#!/bin/bash") call append(line("."), "") else call setline(1, "/*************************************************************************") call append(line("."), " > File Name: ".expand("%")) call append(line(".")+1, " > Author: razrLeLe") call append(line(".")+2, " > Mail: razrlele@outlook.com ") call append(line(".")+3, " > Personal homepage: https://yueyu.io ") call append(line(".")+4, " > Created Time: ".strftime("%c")) call append(line(".")+5, " ************************************************************************/") call append(line(".")+6, "") endif if &filetype == 'cpp' call append(line(".")+7, "#include<vector>") call append(line(".")+8, "#include<list>") call append(line(".")+9, "#include<map>") call append(line(".")+10, "#include<set>") call append(line(".")+11, "#include<deque>") call append(line(".")+12, "#include<queue>") call append(line(".")+13, "#include<stack>") call append(line(".")+14, "#include<bitset>") call append(line(".")+15, "#include<algorithm>") call append(line(".")+16, "#include<functional>") call append(line(".")+17, "#include<numeric>") call append(line(".")+18, "#include<utility>") call append(line(".")+19, "#include<sstream>") call append(line(".")+20, "#include<iostream>") call append(line(".")+21, "#include<iomanip>") call append(line(".")+22, "#include<cstdio>") call append(line(".")+23, "#include<cmath>") call append(line(".")+24, "#include<cstdlib>") call append(line(".")+25, "#include<cctype>") call append(line(".")+26, "#include<string>") call append(line(".")+27, "#include<cstring>") call append(line(".")+28, "#include<ctime>") call append(line(".")+29, "#include<string.h>") call append(line(".")+30, "") call append(line(".")+31, "using namespace std;") call append(line(".")+32, "#define INF 0x3f3f3f3f") endif endfunc autocmd BufNewFile * normal G |