先看代码后BiBi
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'scrooloose/nerdtree' " 显示目录结构
Plugin 'scrooloose/nerdcommenter' " 注释
Plugin 'Valloric/YouCompleteMe' " 提示
Plugin 'vim-airline/vim-airline' " 底栏
Plugin 'tomasr/molokai' " 主题
Plugin 'python-mode/python-mode' " 代码检查
Plugin 'vim-latex/vim-latex' " LaTex
Plugin 'godlygeek/tabular' " 对齐
Plugin 'plasticboy/vim-markdown' " Markdown
Plugin 'tyru/open-browser.vim' " previm需要,vim内打开浏览器
Plugin 'previm/previm' " Markdown预览
Plugin 'mattn/emmet-vim' " HTML,CSS
Plugin 'luochen1990/rainbow' " 括号层级显示
Plugin 'ap/vim-css-color' " 显示CSS颜色
Plugin 'yggdroot/indentline' " 显示缩进指示线
Plugin 'pangloss/vim-javascript' " JavaScript
Plugin 'posva/vim-vue' " Vue
Plugin 'tpope/vim-surround' " 快速添加、修改和删除括号、引号、HTML标签、XML标签等
Plugin 'terryma/vim-multiple-cursors' " 多光标操作
call vundle#end()
filetype plugin indent on
set encoding=utf-8
set nu
set mouse=a
set cursorline
set cursorcolumn
syntax on
color molokai
if has("gui_running")
set lines=100 columns=200
endif
set guifont=Monaco\ 10
set guioptions-=m " 隐藏菜单栏
set guioptions-=T " 隐藏工具栏
set guioptions-=r " 隐藏右侧滚动条
set guioptions-=L " 隐藏左侧滚动条
set guioptions-=b " 隐藏底部滚动条
" NERDTree
autocmd vimenter * NERDTree " 自动开启NERDTree
" 关闭NERDTree
map :NERDTreeToggle
" NERDCommenter
let g:NERDSpaceDelims=1 " 于注释符后添加一个空格
" let g:NERDDefaultAlign= 'start' " 注释符左对齐
let g:NERDDefaultAlign= 'left' " 注释符左对齐
let g:NERDCommentEmptyLines=1 " 允许注释空行
let g:NERDTrimTrailingWhitespace=1 " 去掉注释时,去掉多余空格
let g:NERDToggleCheckAllLines=1 " 注释时检查所选行是否已被注释
" 注释或反注释快捷键
map ci
" YouCompleteMe
autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口
let g:ycm_complete_in_comments = 1 "在注释输入中也能补全
let g:ycm_collect_identifiers_from_comments_and_strings = 0 "注释和字符串中的文字也会被收入补全
let g:ycm_autoclose_preview_window_after_completion = 0 " 补全后自动关闭preview窗口
let g:ycm_extra_conf_globlist = ['~/Workspace/*'] " 载入该路径下的.ycm_extra_conf.py前不会弹出提示框
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py' " 默认库路径
" vim-airline
let g:airline#extensions#tabline#enabled=1
" python-mode
let g:pymode_warnings=0 " 允许插件警告
let g:pymode_python='python3' " 设置pymode是用的Python版本
let g:pymode_virtualenv=1 " 支持自动检测virtualenv
let g:pymode_run_bind='' " 设置为运行代码快捷键
let g:pymode_lint_sort=['E','W','C','I'] " 报错等显示顺序
let g:pymode_lint_ignore = ["E116"] " 不显示E116报错,即注释缩进报错
" vim-latex
let g:tex_flavor='latex'
let g:Tex_DefaultTargetFormat='pdf'
let g:Tex_CompileRule_pdf='xelatex -interaction=nonstopmode $*'
let g:Tex_ViewRule_pdf='xreader'
" open-browser.vim
let g:previm_open_cmd='firefox'
" rainbow
let g:rainbow_active=1
let g:rainbow_conf={
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
\ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
\ 'operators': '_,_',
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
\ 'separately': {
\ '*': {},
\ 'tex': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
\ },
\ 'vim': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
\ },
\ 'html': {
\ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#\z1># fold'],
\ },
\ 'css': 0,
\ }
\}
" 括号自动补齐
inoremap ( ()i
inoremap [ []i
inoremap { {}i
inoremap ' ''i
inoremap " ""i
" 自动代码折叠
set foldmethod=indent
nnoremap za
" 插入头部
func AddTitlePY()
call append(0,"# -*- coding=utf8 -*-")
call append(1,"#")
call append(2,"# Author : Painter")
call append(3,"# Created Time : ".strftime("%Y-%m-%d %a %H:%M:%S"))
call append(4,"# Filename : ".expand("%:t"))
call append(5,"# Email : [email protected]")
call append(6,"")
call append(7,"")
endfunc
func AddTitleC()
call append(0,"/*=======================================")
call append(1," *")
call append(2," * Author : Painter")
call append(3," * Created Time : ".strftime("%Y-%m-%d %a %H:%M:%S"))
call append(4," * Filename : ".expand("%:t"))
call append(5," * Email : [email protected]")
call append(6," *")
call append(7," *=======================================*/")
call append(8,"")
call append(9,"")
endfunc
func AddTitleTeX()
call append(0,"%")
call append(1,"% Author : Painter")
call append(2,"% Created Time: ".strftime("%Y-%m-%d %a %H:%M:%S"))
call append(3,"% Filename : ".expand("%:t"))
call append(4,"% Email : [email protected]")
call append(5,"%")
call append(6,"")
call append(7,"")
endfunc
au BufNewFile *.py,*.pyw call AddTitlePY()
au BufNewFile *.c,*.cpp,*.h call AddTitleC()
au BufNewFile *.tex call AddTitleTeX()
" Python C C++
highlight BadWhitespace ctermbg=red guibg=darkred
au BufNewFile,BufRead *.py,*.pyw,*.c,*.cpp,*.h
\ set tabstop=4 |
\ set softtabstop=4 |
\ set shiftwidth=4 |
\ set expandtab |
\ set autoindent |
\ set fileformat=unix |
\ match BadWhitespace /\s\+$/
au BufNewFile,BufRead *.c,*.cpp,*.h
\ set cindent |
\ set colorcolumn=80
au BufNewFile,BufRead *.tex,*.htm,*.html
\ set tabstop=2 |
\ set softtabstop=2 |
\ set shiftwidth=2 |
\ set expandtab |
\ set fileformat=unix
" func AutoRun()
" if &filetype=="python"
" let mp=&makeprg
" setlocal makeprg=python\ -u
" silent make %
" copen
" let &makeprg=mp
" endif
" endfunc
" map :w :call AutoRun()
auto BufEnter * if 0==len(filter(range(1,winnr('$')), 'empty(getbufvar(winbufnr(v:val), "&bt"))')) | qa! | endif " 若无可编辑窗口,则自动关闭其余窗口
Git一下:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
在.vimrc
中粘贴如下内容:
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
" 按照上面这句的形式,在这块写需要安装的插件
call vundle#end()
filetype plugin indent on
安装:
:PluginInstall
或者指定安装某个插件:
:PluginInstall 'VundleVim/Vundle.vim'
若要删除插件,则在配置文件中删除该插件的相关代码,然后执行:
:PluginClean
这个插件有个浪漫的名字,用于代码补全。但是,相比其他插件,它是最不好装的插件。安装该插件需要先安装cmake。
按照YouCompleteMe的Github上的步骤,用Vundle install好该插件后,进入插件所在路径,执行命令:
若需要支持C、C++、Objective-C等语言的补全,使用如下命令:
cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer
若不需要支持C、C++、Objective-C等语言的补全。如果只是编辑Python的话,选择这个命令:
cd ~/.vim/bundle/YouCompleteMe
./install.py
若需要支持其他语言的补全,详细见Github。若懒得挑选,就用下面这个命令:
cd ~/.vim/bundle/YouCompleteMe
./install.py --all
很多人用Vundle install好YouCompleteMe之后,会看到报错:
ycmd server SHUT DOWN
就是因为没有执行以上./install.py
有两种方法,详见https://github.com/valloric/youcompleteme#python-semantic-completion,我选用头一种。
在项目根目录下创建文件.ycm_extra_conf.py
,写入:
def Settings( **kwargs ):
return {
'interpreter_path': '/path/to/virtual/environment/python'
}
例如,有个conda环境叫tf
,那么这么写:
def Settings( **kwargs ):
return {
'interpreter_path': '~/anaconda3/envs/tf/bin/python'
}
补全的时候反映有点慢。
并不是安装时选择了--clang-completer
就万事大吉了。默认情况下,YouCompleteMe还不知道怎么补全C/C++呢!
所以就有了这一句:
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'
在上面的代码中已经有了。
NERDCommenter的配置有两处需要注意一下。一处是对齐方式使用start
,而不是left
,才能真正的左对齐。另一处是需要改动源文件~/.vim/bundle/nerdcommenter/plugins/NERD_commenter.vim
:
\ 'python': { 'left': '#', 'leftAlt': '#'}
即删掉一个空格,这样在注释的时候不会自动添加两个空格,而是按照配置要求添加一个或零个。
需要安装rst2html.py
:
pip install docutils