Linux下vim的配置

一、安装vim插件管理工具Vundle

1、创建文件夹

mkdir -p ~/.vim/bundle

2、克隆Vundle到bundle目录下

git clone [email protected]:VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

二、创建vimrc(vim的配置文件)

可以直接克隆我的vim配置文件到你的本地

git clone [email protected]:Tangugo/vim.git

.vimrc 配置文件拷贝到 ~/目录下

cp vim/.vimrc ~/

注:前面带点.的文件是隐藏文件,需 ls -la 才能查看到

vim配置文件一般分为以下四部分:

  • 加载vim的相关插件(vim插件大全)
  • vim的常规设置
  • vim插件的设置
  • 键盘中一些键的功能重新映射其他键或组合键上(例如Esc退出插入模式映射到jj组合键)

三、安装插件让.vimrc配置文件生效

按以下步骤操作

cd ~/.vim/bundle
vim
:BundleInstall

安装插件需要一定的时间,跟网速有关,喝杯茶等待

四、Vim 自动补全插件 YouCompleteMe 安装与配置

可以参考 http://howiefh.github.io/2015/05/22/vim-install-youcompleteme-plugin/

1、安装

确保Vim版本至少是7.3.584,并且支持python2脚本

cd ~/.vim/bundle/YouCompleteMe
./install.py

需要支持C语言的话

./install.py –clang-completer

2、拷贝配置文件

cp third_party/ycmd/cpp/ycm/.ycm_extra_conf.py ~/

3、修改配置文件,在flags部分后添加如下内容:

‘-isystem’,
‘/usr/include’,

.vimrc中设定 YouCompleteMe配置(第二部克隆vimrc文件,该vimrc已指定了)

let g:ycm_global_ycm_extra_conf = ‘~/.ycm_extra_conf.py’

五、安装完后我的补全遇到如下问题:

在写代码时,每当输入 . 就提示 ConnectionError 错误提示(如输入: os.),到 /tmp/ycm_temp 目录下查看日志文件,提示如下错误:

Traceback (most recent call last):
  File "/home/zhu/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/jedihttp.py", line 23, in 
    from waitress import serve
ImportError: No module named waitress

发现报错源,顺藤摸瓜,于是到PyPi(几乎所有python的第三方库在此处都能找到)查找waitress模块,下载安装后,完美解决了代码补全出现的问题

waitress安装:

tar -zxvf waitress-1.0a2.tar.gz
cd waitress-1.0a2
python setup.py install # 注:非root用户需在命令前加上 sudo

安装完后vim就变得无比强大绚丽了,看截图
Linux下vim的配置_第1张图片


以下是我的vimrc配置文件

" ************* Vundle 配置 ****************
filetype off     " 侦测文件类型
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" Vundle.vim : vim的一个非常好用的插件管理器
Bundle 'gmarik/Vundle.vim'

" 更酷的启动界面
"Bundle 'mhinz/vim-startify'

" 协作编程
"Bundle 'FredKSchott/CoVim'

" 代码补全
Bundle 'Valloric/YouCompleteMe'
Bundle 'SirVer/ultisnips'
Bundle 'honza/vim-snippets'
Bundle 'YanhaoMo/snippets'

" Python代码补全
"Bundle 'Pydiction'

" 符号自动补全
Bundle 'Raimondi/delimitMate'

" 文件搜索
Bundle 'kien/ctrlp.vim'
Bundle 'Shougo/unite.vim'
Bundle 'scrooloose/nerdtree'
Bundle 'vim-scripts/mru.vim'

" 静态语法检查
Bundle 'scrooloose/syntastic'

" 代码浏览
Bundle 'majutsushi/tagbar'

" git支持
Bundle 'tpope/vim-fugitive'
Bundle 'airblade/vim-gitgutter'

" 美化主题
Bundle 'tomasr/molokai'
Bundle 'morhetz/gruvbox'
Bundle 'kien/rainbow_parentheses.vim'
Bundle 'bling/vim-airline'
"Bundle 'vim-airline-themes'
Bundle 'nathanaelkane/vim-indent-guides'
Bundle 'solarized'
Bundle 'jpo/vim-railscasts-theme'
"Bundle 'altercation/vim-colors-solarized.git'
"Bundle 'fholgado/minibufexpl.vim'

" 代码bug追踪
Bundle 'ZenCoding.vim'

" 编辑增强
" 多光标操作
Bundle 'terryma/vim-multiple-cursors'
" 成对符号编辑
Bundle 'tpope/vim-surround'
Bundle 'tpope/vim-unimpaired'

" 快速注释
Bundle 'scrooloose/nerdcommenter'
" 自动对齐
Bundle 'godlygeek/tabular'
" 快速移动
Bundle 'Lokaltog/vim-easymotion'
" 代码块对齐用
Bundle 'Yggdroot/indentLine'
" 增强状态栏
Bundle 'rstatusline'

" tmux支持
Bundle 'benmills/vimux'

" c/c++
Bundle 'vim-scripts/a.vim'
Bundle 'vim-scripts/c.vim'

" org-mode
Bundle 'jceb/vim-orgmode'
Bundle 'tpope/vim-speeddating'

" markdown
Bundle 'plasticboy/vim-markdown'
" 可以通过浏览器实时预览,但是要安装额外依赖,详见官网
"Bundle 'suan/vim-instant-markdown'

" 网页开发
Bundle 'mattn/emmet-vim'

" pyhon
Bundle 'klen/python-mode'
"Bundle 'python-imports.vim'

" js
Bundle 'coolwanglu/vim.js'

" golang
"Bundle 'fatih/vim-go'

" 用ack代替grep搜索
Bundle 'mileszs/ack.vim'
"bundle 'vimwiki/vimwiki'
"Bundle 'vim-scripts/bufexplorer.zip'
"Bundle 'terryma/vim-smooth-scroll'

call vundle#end()
filetype plugin on                                              " 载入文件类型插件
filetype indent on                                              " 为特定文件类型载入相关缩进文件


" *************** gvim配置 ***************
if has("gui_running")
    let $LANG='en'      "设置gvim菜单栏始终显示为英文
    set langmenu=en
    source $VIMRUNTIME/delmenu.vim
    source $VIMRUNTIME/menu.vim
    "set guifont=DejaVu\ Sans\ Mono\ for\ Powerline\ Book\ 10
    set guifont=Source\ Code\ Pro\ for\ Powerline\ Regular\ 10
    set guioptions-=e
    set guioptions-=m
    set guioptions-=T
    set guioptions-=L
    set guioptions-=r
    set guioptions-=B
    set guioptions-=0
    set go=
    winpos 1000 0
    "set lines=100 columns=150      " 开启时的窗口默认大小
endif


" *************** vim常用的基本设置 ***************
set nocompatible                                                " 不使用vi的键盘模式,而是vim自己的
"syntax enable                                                   " 开启语法高亮功能
syntax on                                                       " 语法高亮支持
set nu                                                          " 显示行号
set rnu                                                         " 显示相对行号
set wrap                                                        " 当一行文字很长时换行
"set nowrap                                                      " 当一行文字很长时取消换行
set showmatch                                                   " 当光标移动到一个括号时高亮显示对应的另一个括号
set showcmd                                                     " 回显输入的命令
set showmode                                                    " 显示当前的模式
set clipboard+=unnamed                                          " 关联系统的剪贴板
set ruler                                                       " 在编辑过程中右下角显示光标的行列信息
set nocp                                                        " 让Vim工作在不兼容模式下
set shortmess=atI                                               " 启动时不显示捐助乌干达儿童的提示
set so=6                                                        " 上下滚行时空余6行
set autoindent                                                  " 自动套用上一行的缩进方式
set smartindent                                                 " 智能缩进
set mouse=a                                                     " 开启鼠标支持
set laststatus=2                                                " 总是显示状态行
set backspace=indent,eol,start                                  " 对退格键提供更好的支持
set ts=4                                                        " 设置tab长度为4
set sts=4                                                       " 设置制表符宽度
set shiftwidth=4                                                " 设置缩进空格数
set expandtab                                                   " 用空格代替tab键
set smarttab                                                    " 更加智能的tab键
set hid                                                         " 当buffer被丢弃时隐藏它
set encoding=utf-8                                              " 默认使用utf-8编码格式
set fileencodings=utf-8,cp936,gb18030,big5,euc-kr,latin1        " 自动判断编码时 依次尝试一下编码
set ffs=unix,dos,mac                                            " 设置文件类型
set hlsearch                                                    " 高亮搜索内容
set ignorecase                                                  " 搜索模式里忽略大小写
set smartcase                                                   " 如果搜索字符串里包含大写字母,则禁用 ignorecase
set incsearch                                                   " 显示搜索的动态匹配效果
set lazyredraw                                                  " 解决某些类型的文件由于syntax导致vim反应过慢的问题
set ttyfast                                                     " 平滑地变化
set cc=80                                                       "80字符处显示分隔符
set foldmethod=indent                                           " 折叠方式
set nofoldenable                                                " 不自动折叠
set foldcolumn=1                                                " 在行号前空出一列的宽度
set t_Co=256                                                    " 设置256真彩色
set history=1000                                                " 设置历史记录条数
"set autoread                                                   " 当文件在外部被修改时自动载入
"set cindent                                                    " 使用c语言的缩进格式
"set whichwrap+=<,>,h,l                                         " 允许backspace和光标键跨越行边界
"set cmdheight=2                                                " 显示两行命令行

set list lcs=tab:\♠\ ,trail:•                                   " 显示tab键为♠,并且显示每行结尾的空格为'•'
" 一些备用字符:›┆┇┊┋♠♦•

" 格式化状态行显示的内容
set statusline=[%t]\ %y\ %m%=%{&fileencoding}\ [%{&ff}]\ [%l,\ %c]\ [%L]\ [%p%%]

" 打开一个文件自动定位到上一次退出的位置
if has("autocmd")
    au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

" 保存.vim文件后不用退出即可生效
"autocmd BufWritePost $MYVIMRC source $MYVIMRC
"au! bufwritepost .vimrc source %


" ************** 备份设置 ****************
"set nobackup                                                   " 不进行备份
"set nowb                                                       " 重新载入文件时不要备份
"set noswapfile                                                 " 不使用swf文件,可能导致错误无法恢复


" *************** 关闭错误声音 **************
set noerrorbells
set novisualbell
set  t_vb=


" **************** 设置vim主题外观 ***************
"set background=light                                           " 设置vim背景为浅色
set background=dark                                             " 设置vim背景为深色
set cursorline                                                  " 突出显示当前行
set cursorcolumn                                                " 突出显示当前列

"colorscheme molokai                                             " 设置molokai高亮主题
"colorscheme desert                                              " 设置desert高亮主题
"let g:solarized_termcolors=256
"colorscheme solarized                                           " 设置solarized高亮主题
"let g:gruvbox_termcolors=16
colorscheme gruvbox                                             " 设置gruvbox高亮主题


" ************** vim的配色 **************
"hi CursorLine cterm=NONE ctermbg=237 ctermfg=NONE
"hi CursorColumn cterm=NONE ctermbg=237 ctermfg=NONE
hi vertsplit ctermbg=bg guibg=bg
hi GitGutterAdd ctermbg=bg guibg=bg
hi GitGutterChange ctermbg=bg guibg=bg
hi GitGutterDelete ctermbg=bg guibg=bg
hi GitGutterChangeDelete ctermbg=bg guibg=bg
hi SyntasticErrorSign ctermbg=bg guibg=bg
hi SyntasticWarningSign ctermbg=bg guibg=bg
hi FoldColumn ctermbg=bg guibg=bg


" *********** NERDTree插件配置 ***********
let NERDTreeChDirMode=2                                         " 设置当前目录为nerdtree的起始目录
let NERDChristmasTree=1                                         " 使得窗口有更好看的效果
let NERDTreeMouseMode=1                                         " 双击鼠标左键打开文件
let NERDTreeWinSize=25                                          " 设置窗口宽度为25
let NERDTreeQuitOnOpen=1                                        " 打开一个文件时nerdtree分栏自动关闭


" *********** ctags插件配置 ***********
set tags+=/usr/include/tags


" ********* cscope插件配置 **********
if has("cscope")
    "set csprg=/usr/bin/cscope
    set csto=0
    set cst
    set nocsverb
    set cscopequickfix=s-,c-,d-,i-,t-,e- "在quickfix窗口中显示搜索结果


    " add any database in current directory
    if filereadable("cscope.out")
        cs add cscope.out
        " else add database pointed to by environment
    elseif $CSCOPE_DB != ""
        cs add $CSCOPE_DB
    endif
    set csverb
endif


" *********** nerdcommenter快速注释插件配置 **********
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
" Use compact syntax for prettified multi-line comments
let g:NERDCompactSexyComs = 1
" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign = 'left'
" Set a language to use its alternate delimiters by default
let g:NERDAltDelims_java = 1
" Add your own custom formats or override the defaults
let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } }
" Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDCommentEmptyLines = 1
" Enable trimming of trailing whitespace when uncommenting
let g:NERDTrimTrailingWhitespace = 1


" *********** syntastic插件配置 ***********
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 = 1
let g:syntastic_error_symbol = '✗'
let g:syntastic_warning_symbol = '⚡'
"let g:syntastic_cpp_include_dirs = ['/usr/include/qt']
"let g:syntastic_cpp_compiler_options = '-std=gnu++11 -Wall'
let g:syntastic_mode_map = { 'mode': 'passive', 'active_filetypes': [],'passive_filetypes': [] }


" ********** pydiction补全设置 **********
"let g:pydiction_location = '~/.vim/bundle/Pydiction/complete-dict'
""defalut g:pydiction_menu_height == 15
"let g:pydiction_menu_height = 10


" ********** youcompleteme自动补全配置 ***********
let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
"let g:ycm_python_binary_path = 'python'
set completeopt=longest,menu    "让Vim的补全菜单行为与一般IDE一致(参考VimTip1228)
autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口
inoremap         pumvisible() ? "\" : "\"    "回车即选中当前项
"上下左右键的行为 会显示其他信息
inoremap       pumvisible() ? "\" : "\"
inoremap         pumvisible() ? "\" : "\"
inoremap   pumvisible() ? "\\\" : "\"
inoremap     pumvisible() ? "\\\" : "\"
" 跳转到定义处
nnoremap jd :YcmCompleter GoToDefinitionElseDeclaration
nnoremap  :YcmForceCompileAndDiagnostics    "force recomile with syntastic
" nnoremap lo :lopen    "open locationlist
" nnoremap lc :lclose   "close locationlist
inoremap  


" 不显示开启vim时检查ycm_extra_conf文件的信息  
let g:ycm_confirm_extra_conf=0
" 开启基于tag的补全,可以在这之后添加需要的标签路径  
let g:ycm_collect_identifiers_from_tags_files=1
"注释和字符串中的文字也会被收入补全
let g:ycm_collect_identifiers_from_comments_and_strings = 0
" 输入第2个字符开始补全
let g:ycm_min_num_of_chars_for_completion=2
" 禁止缓存匹配项,每次都重新生成匹配项
let g:ycm_cache_omnifunc=0
" 开启语义补全
let g:ycm_seed_identifiers_with_syntax=1    
"在注释输入中也能补全
let g:ycm_complete_in_comments = 1
"在字符串输入中也能补全
let g:ycm_complete_in_strings = 1
" 设置在下面几种格式的文件上屏蔽ycm
let g:ycm_filetype_blacklist = {
      \ 'tagbar' : 1,
      \ 'nerdtree' : 1,
      \}
"youcompleteme  默认tab  s-tab 和 ultisnips 冲突
let g:ycm_key_list_select_completion = ['']
let g:ycm_key_list_previous_completion = ['']
" 修改对C函数的补全快捷键,默认是CTRL + space,修改为ALT + ;
let g:ycm_key_invoke_completion = ''

" SirVer/ultisnips 代码片断
" Trigger configuration. Do not use  if you use https://github.com/Valloric/YouCompleteMe.
let g:UltiSnipsExpandTrigger=""
let g:UltiSnipsJumpForwardTrigger=""
let g:UltiSnipsJumpBackwardTrigger=""
let g:UltiSnipsListSnippets=""
"定义存放代码片段的文件夹,使用自定义和默认的,将会的到全局,有冲突的会提示
let g:UltiSnipsSnippetDirectories=["~/.vim/bundle/vim-snippets/UltiSnips"]

" 参考https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-62941322
" 解决ultisnips和ycm tab冲突,如果不使用下面的办法解决可以参考
" https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-63205056的配置
" begin
" let g:ycm_key_list_select_completion=['', '']
" let g:ycm_key_list_previous_completion=['', '']
" let g:UltiSnipsExpandTrigger=""
" let g:UltiSnipsJumpForwardTrigger=""                                           
" let g:UltiSnipsJumpBackwardTrigger=""
" end
" UltiSnips completion function that tries to expand a snippet. If there's no
" snippet for expanding, it checks for completion window and if it's
" shown, selects first element. If there's no completion window it tries to
" jump to next placeholder. If there's no placeholder it just returns TAB key 
function! g:UltiSnips_Complete()
    call UltiSnips#ExpandSnippet()
    if g:ulti_expand_res == 0
        if pumvisible()
            return "\"
        else
            call UltiSnips#JumpForwards()
            if g:ulti_jump_forwards_res == 0
               return "\"
            endif
        endif
    endif
    return ""
endfunction

au BufEnter * exec "inoremap  " . g:UltiSnipsExpandTrigger . " =g:UltiSnips_Complete()"

" Expand snippet or return
let g:ulti_expand_res = 1
function! Ulti_ExpandOrEnter()
    call UltiSnips#ExpandSnippet()
    if g:ulti_expand_res
        return ''
    else
        return "\"
endfunction

" Set  as primary trigger
inoremap  =Ulti_ExpandOrEnter()


" ********** indentLine插件 **********
let g:indentLine_char = ''                                     "代码块对齐用┊符号


" *********** UltiSnips插件配置 **********
let g:UltiSnipsExpandTrigger=""
""let g:UltiSnipsJumpForwardTrigger=""
""let g:UltiSnipsJumpBackwardTrigger=""
let g:UltiSnipsEditSplit = "vertical"
"let g:UltiSnipsSnippetDirectories = ["UltiSnips", "bundle/snippets"]
let g:UltiSnipsSnippetDirectories = ["bundle/snippets"]


" ********** rainbow_parentheses插件配置 ***********
let g:rbpt_colorpairs = [
            \ ['brown',       'RoyalBlue3'],
            \ ['Darkblue',    'SeaGreen3'],
            \ ['darkgray',    'DarkOrchid3'],
            \ ['darkgreen',   'firebrick3'],
            \ ['darkcyan',    'RoyalBlue3'],
            \ ['darkred',     'SeaGreen3'],
            \ ['darkmagenta', 'DarkOrchid3'],
            \ ['brown',       'firebrick3'],
            \ ['gray',        'RoyalBlue3'],
            \ ['black',       'SeaGreen3'],
            \ ['darkred',     'DarkOrchid3'],
            \ ['darkmagenta', 'DarkOrchid3'],
            \ ['Darkblue',    'firebrick3'],
            \ ['darkgreen',   'RoyalBlue3'],
            \ ['darkcyan',    'SeaGreen3'],
            \ ['red',         'firebrick3'],
            \ ]
let g:rbpt_max = 16
let g:rbpt_loadcmd_toggle = 0
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces


" ********** vim-multiple-cursors插件配置 ***********
let g:multi_cursor_use_default_mapping=0
let g:multi_cursor_next_key=''
let g:multi_cursor_prev_key=''
let g:multi_cursor_skip_key=''
let g:multi_cursor_quit_key=''


" ********** airline插件配置 ***********
let g:airline_powerline_fonts=1     "配置airline使用powerline字体
"let g:airline#extensions#tabline#enabled = 1
"let g:airline#extensions#tabline#left_sep = ' '
"let g:airline#extensions#tabline#left_alt_sep = '|'


" *********** vimwiki插件配置 ***********
"let g:vimwiki_list = [{'path' : '~/.vimwiki/',
"        \'template_path' : '~/.vimwiki/template/',
"        \'template_default' : 'default_template',
"        \'template_ext' : '.html',
"        \'path_html': '~/.vimwiki/html/'}
"        \]


" ********** mru插件配置 **********
let MRU_Auto_Close = 1
let MRU_Max_Entries = 40


" ************ pythom-mode *********
let g:pymode_lint_on_write = 0
let g:pymode_lint_signs = 0
let g:pymode_rope_lookup_project = 0
let g:pymode_rope = 0
let g:pymode_floding = 0


" *********** 重新映射一些键 **********
" 设置以空格打开和关闭折叠
nmap  @=((foldclosed(line('.'))<0)?'zc':'zo')

" 当一行很长时把分开的段行当作一行来移动
map j gj
map k gk

" 将Esc键映射到jj,zz
im jj 
im JJ 
im zz 
im ZZ 
map zz 
map ZZ 

" quickfix相关的一些快捷键
map cop :copen
map ccl :cclose
map cn :cn
map cp :cp

" emacs式的行内跳转
map  ^
map  $
imap  ^i
imap  $a

" ff跳转到文件末尾
map ff G

" visual模式下快速对齐
vnoremap <  >gv

" 关闭打开目录树
map  :NERDTreeToggle
imap   :NERDTreeToggle
" 打开树状文件目录
map  \be

" 生成ctags
map  :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .
im  :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .
nmap go g
nmap bk 

nmap s :cs find s =expand("")
nmap g :cs find g =expand("")
nmap c :cs find c =expand("")
nmap t :cs find t =expand("")
nmap e :cs find e =expand("")
nmap f :cs find f =expand("")
nmap i :cs find i ^=expand("")$
nmap d :cs find d =expand("")

" 编译运行
:autocmd BufRead,BufNewFile *.dot map  :w:!dot -Tjpg -o %<.jpg % && eog %<.jpg   && exec "redr!"
" C,C++ 按F5编译运行
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 python2.7 %"
    elseif &filetype == 'html'
        exec "!firefox % &"
    elseif &filetype == 'go'
    "        exec "!go build %<"
        exec "!time go run %"
    elseif &filetype == 'mkd'
        exec "!~/.vim/markdown.pl % > %.html &"
        exec "!firefox %.html &"
    endif
endfunc

" C,C++的调试
map  :call Rungdb()
func! Rungdb()
    exec "w"
    exec "!g++ % -g -o %<"
    exec "!gdb ./%<"
endfunc

" 语法检查
map  :SyntasticCheck
im  :SyntasticCheck

"" 代码格式优化化
"map  :call FormartSrc()
"" 定义FormartSrc()
"func FormartSrc()
"    exec "w"
"    if &filetype == 'c'
"        exec "!astyle --style=ansi -a --suffix=none %"
"    elseif &filetype == 'cpp' || &filetype == 'hpp'
"        exec "r !astyle --style=ansi --one-line=keep-statements -a --suffix=none %> /dev/null 2>&1"
"    elseif &filetype == 'perl'
"        exec "!astyle --style=gnu --suffix=none %"
"    elseif &filetype == 'py'||&filetype == 'python'
"        exec "r !autopep8 -i --aggressive %"
"    elseif &filetype == 'java'
"        exec "!astyle --style=java --suffix=none %"
"    elseif &filetype == 'jsp'
"        exec "!astyle --style=gnu --suffix=none %"
"    elseif &filetype == 'xml'
"        exec "!astyle --style=gnu --suffix=none %"
"    else
"        exec "normal gg=G"
"        return
"    endif
"    exec "e! %"
"endfunc

" 更新cscope文件
map  :!cscope -Rbq
im  :!cscope -Rbq

" 修改的键盘映射
nmap ' 
" 当按下\+Enter时取消搜索高亮
map   :noh

" Unite插件配置
map b :Unite -winheight=10 buffer
map r :MRU
map f :NERDTreeToggle

" Tagbar插件配置
let g:tagbar_autoclose=1
map t :TagbarToggle
" 设置文件类型辅助
map s :setfiletype
" 更方便的窗口间跳转
map j j
map k k
map l l
map h h
map  j
map  k
map  l
map  h

" vimux插件配置
map e :VimuxPromptCommand
map x :VimuxCloseRunner
map vl :VimuxRunLastCommand
map vi :VimuxInspectRunner
" 更方便的页滚动
map  
map  

map ,,j (easymotion-w)
map ,,k (easymotion-b)
map ,,s (easymotion-s)


"********** 新建.c,.h,.sh,.java文件,自动插入文件头 **********
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.rb,*.java,*.py exec ":call SetHead()"
"" 定义函数SetHead,自动插入文件头
func! SetHead()
    if &filetype == 'sh'
        call setline(1,"\#!/bin/bash")
        call append(line("."), "")
    elseif &filetype == 'python'
        call setline(1,"#!/usr/bin/env python")
        call append(line("."),"# -*- coding=utf-8 -*-")
        call append(line(".")+1, "")
    elseif &filetype == 'ruby'
        call setline(1,"#!/usr/bin/env ruby")
        call append(line("."),"# encoding: utf-8")
        call append(line(".")+1, "")
"    elseif &filetype == 'mkd'
"        call setline(1,"")
    else
        call setline(1, "/*************************************************************************")
        call append(line("."), "    > File Name: ".expand("%"))
        call append(line(".")+1, "  > Author: ")
        call append(line(".")+2, "  > Mail: ")
        call append(line(".")+3, "  > Created Time: ".strftime("%c"))
        call append(line(".")+4, " ************************************************************************/")
        call append(line(".")+5, "")
    endif

    if expand("%:e") == 'cpp'
        call append(line(".")+6, "#include")
        call append(line(".")+7, "using namespace std;")
        call append(line(".")+8, "")
    endif

    if &filetype == 'c'
        call append(line(".")+6, "#include")
        call append(line(".")+7, "")
    endif

    if expand("%:e") == 'h'
        call append(line(".")+6, "#ifndef _".toupper(expand("%:r"))."_H")
        call append(line(".")+7, "#define _".toupper(expand("%:r"))."_H")
        call append(line(".")+8, "#endif")
    endif

    if &filetype == 'java'
        call append(line(".")+6,"public class ".expand("%:r"))
        call append(line(".")+7,"")
    endif
    " 新建文件后,自动定位到文件末尾
endfunc
autocmd BufNewFile * normal G


" ********* 实用设置 *********
if has("autocmd")
      autocmd BufReadPost *
          \ if line("'\"") > 0 && line("'\"") <= line("$") |
          \   exe "normal g`\"" |
          \ endif
endif

" 当打开vim且没有文件时自动打开NERDTree
autocmd vimenter * if !argc() | NERDTree | endif
" 只剩 NERDTree时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif

" quickfix模式
autocmd FileType c,cpp map   :w:make

你可能感兴趣的:(Vim)