最适合自己的vim高级完美配置

前提:
vim插件中最主要的就是vundle了,vundle用来管理vim的其它插件。
项目地址https://github.com/VundleVim/Vundle.vim。
首先看~/.vim/bundle目录是否存在,不存在则创建目录:

cd ~
mkdir .vim
cd .vim
mkdir bundle

然后进入到bundle目录下,下载源码:

cd ~/.vim/bundle/
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

下载好后,将下列配置放在.vimrc文件的开头:

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()
 
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
 
" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

如果想下载某个插件,比如自动缩进indentpython.vim插件,需要将

Plugin 'vim-scripts/indentpython.vim'

置于call vundle#begin()和call vundle#end()之间,保存配置后在vim中执行

:PluginInstall

即可以自动下载indentpython.vim插件了。

完整的配置:

"""""""""""""""""""""""""""""""""""""
"Vundle
"""""""""""""""""""""""""""""""""""""
set nocompatible
filetype off

"set the runtime path to include Vundle and initialaze
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
"let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
""""""""""""""""""""""""""""
"代码补全 snipMate
Plugin 'MarcWeber/vim-addon-mw-utils'
Plugin 'tomtom/tlib_vim'
Plugin 'garbas/vim-snipmate'
"Optional:
Plugin 'honza/vim-snippets'
""""""""""""""""""""""""""""
"缩进提示线
Plugin 'Yggdroot/indentLine'
""""""""""""""""""""""""""""
"编程提示 jedi-vim
"Plugin 'davidhalter/jedi-vim'
""""""""""""""""""""""""""""
"自动补全括号和引号 auto-pairs
Plugin 'jiangmiao/auto-pairs'
""""""""""""""""""""""""""""
"solarized配色方案
"Plugin 'altercation/vim-colors-solarized'
"Plugin 'rakr/vim-one'
"Plugin 'vim-scripts/peaksea'
Plugin 'morhetz/gruvbox'
syntax enable
if has('gui_running')
    set background=light
else
    set background=dark
	"set t_Co=256
	"set term=xterm-256color
	set termguicolors
endif
"let g:solarized_termtrans=1
"let g:solarized_termcolors=256
"let g:solarized_termctrans=1
"let g:airline_theme='one'
"colorscheme solarized
"colorscheme desert
colorscheme gruvbox
"colorscheme peaksea 
""""""""""""""""""""""""""""
"nerdtree树形目录
Plugin 'scrooloose/nerdtree'
"Ctrl+n可以开启目录
map -n> :NERDTreeToggle
"设置忽略.pyc文件
let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$']
let g:NERDTreeDirArrowExpandable = '▸'
let g:NERDTreeDirArrowCollapsible = '▾'
"let NERDTreeMinimalUI = 1
"let NERDTreeDirArrows = 1
"用tab键操作
Plugin 'jistr/vim-nerdtree-tabs'
""""""""""""""""""""""""""""
"美化状态栏
Plugin 'Lokaltog/vim-powerline'
""""""""""""""""""""""""""""
"flake8代码风格检查
"Plugin 'nvie/vim-flake8'
Plugin 'tell-k/vim-autopep8'
autocmd FileType python noremap   :call Autopep8()
""""""""""""""""""""""""""""
"自动保存
"Plugin 'vim-scripts/vim-auto-save'
"let g:auto_save = 1
"let g:auto_save_events = ["InsertLeave", "TextChanged", "TextChangedI", "CursorHoldI", "CompleteDone"]
""""""""""""""""""""""""""""
"All of your Plugins must be added before the following line
call vundle#end()
filetype plugin indent on


"""""""""""""""""""""""""""""""""""""
"my config
"""""""""""""""""""""""""""""""""""""
set nu
"syntax on
set tabstop=4
set softtabstop=4
set shiftwidth=4
set autoindent
set showmatch
set completeopt=preview,menu
set autowriteall
"set autoread

"当代码行数很多的时候,代码折叠是很必须的
"使用zc按键来创建折叠,使用za来打开或者关闭折叠。
"za经常会误输入,可以用空格键来替代za
set foldmethod=indent
set foldlevel=99
nnoremap  za

map  I#
map  0x
map  I//

map [1;5C :bn
map [1;5D :bp

ab my163 syd2285734649@163.com
ab myqq 2285734649@qq.com

set fileencodings=utf-8,chinese,latin1
set termencoding=utf-8
set encoding=utf-8

"每过十秒自动保存文件
"set updatetime=10000
"autocmd CursorHoldI * silent w

"""""""""""""""""""""""""""""""""""""
"Quickly Run
"""""""""""""""""""""""""""""""""""""
map  :call CompileRunGcc()
func! CompileRunGcc()
    exec "w"
    if &filetype == 'c'
        exec "!g++ % -o %<"
        exec "!time ./%<"
    elseif &filetype == 'cpp'
        exec "!g++ % -o %<"
        exec "!time ./%<"
    elseif &filetype == 'java'
        exec "!javac %"
        exec "!time java %<"
    elseif &filetype == 'sh'
        :!time bash %
    elseif &filetype == 'python'
        exec "!time python3 %"
    elseif &filetype == 'html'
        exec "!firefox %&"
    elseif &filetype == 'go'
        exec "!time go run %"
    elseif &filetype == 'mkd'
        exec "!~/.vim/markdown.pl % > %.html &"
        exec "!firefox %.html &"
    endif
endfunc

"""""""""""""""""""""""""""""""""""""
"Syntastic
"""""""""""""""""""""""""""""""""""""
execute pathogen#infect()
set statusline+=%#warningmsg#
set statusline+=%{
     SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_python_checkers = ['pylint']

**可能的错误: ** Cannot find color scheme 'solarized' 或者 Cannot find color scheme 'one'或者是其他。

解决方案:
没有~/.vim/colors/就创建。

cp ~/.vim/bundle/vim-colors-solarized/colors/solarized.vim ~/.vim/colors/

参考文章:
https://www.cnblogs.com/linxiyue/p/7834817.html
https://www.zhihu.com/question/20271508
https://www.cnblogs.com/linxiyue/p/7834817.html
https://zhuanlan.zhihu.com/p/58188561?from_voters_page=true

你可能感兴趣的:(自动化脚本,git,python,vim)