vim配置编辑器 今天又花了一段时间来配置vim的编辑器,发现我自己在这个上面花的时间实在是有一点点多的了,感觉有必要花一些时间将vim的配置好好整理一遍的说。
" vim 配置
set nocompatible
filetype off
map <silent> <F7> :NERDTreeToggle<CR>
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
"Plugin 'https://github.com/kien/ctrlp.vim.git'
Plugin 'https://github.com/scrooloose/nerdtree.git'
Plugin 'https://github.com/Valloric/YouCompleteMe.git'
"Plugin 'https://github.com/aperezdc/vim-template.git'
call vundle#end()
filetype plugin indent on
set nu
set autoindent
set cindent
syntax on
set tabstop=2
set softtabstop=2
set shiftwidth=2
set backspace=2
" tab
set expandtab
set cino=g0,:0
set hlsearch
" letters
set ignorecase
set encoding=utf-8
set fileencoding=utf-8
set termencoding=utf-8
set ambiwidth=double
set nobackup
set incsearch
set showcmd
"set nocompatible
set history=50
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set laststatus=2 " Always display the status line
set autowrite " Automatically :write before running commands
set confirm " Need confrimation while exit
set fileencodings=utf-8,gb18030,gbk,big5
set cursorline
set cursorcolumn
" code folder up
set fdm=indent
" code add header
autocmd BufNewFile *.cpp,*.c,*.h,*.sh,*.java,*.hpp,*.py exec ":call SetTitle()"
func SetTitle()
if expand("%:e") == 'cpp'
call setline(1,"#include <iostream>")
call append(line("."), "#include <cstdio>")
call append(line(".")+1, "#include <algorithm>")
call append(line(".")+2, "#include <string>")
call append(line(".")+3, "")
call append(line(".")+4, "using namespace std;")
call append(line(".")+5, "int main()")
call append(line(".")+6, "{")
call append(line(".")+7, "")
call append(line(".")+8, " return 0;")
call append(line(".")+9, "}")
endif
if expand("%:e") == 'sh'
call setline(1,"#!/bin/sh")
call append(line("."), "")
call append(line(".")+1, "if [ $# -lt 3 ];then")
call append(line(".")+2, " echo \"usage: $0 input output\"")
call append(line(".")+3, " exit -1")
call append(line(".")+4, "fi")
endif
if expand("%:e") == 'py'
call setline(1,"#!/usr/bin/env python")
call append(line("."), "")
call append(line(".")+1, "import os")
call append(line(".")+2, "import sys")
call append(line(".")+3, "import string")
call append(line(".")+4, "import re")
call append(line(".")+5, "")
call append(line(".")+6, "class GetObject(object):")
call append(line(".")+7, " def __init__(self, input_str, output_str):")
call append(line(".")+8, " self.input_str = input_str")
call append(line(".")+9, " self.output_str = output_str")
call append(line(".")+10, "")
call append(line(".")+11, " def Process(self):")
call append(line(".")+12, " print \'Process here\'")
call append(line(".")+13, " return")
call append(line(".")+14, "")
call append(line(".")+15, "if __name__ == \'__main__\':")
call append(line(".")+16, " if len(sys.argv) != 3:")
call append(line(".")+17, " print \'usage: %s input output\' % (sys.argv[0])")
call append(line(".")+18, " sys.exit(-1)")
call append(line(".")+19, " handle = GetObject(sys.argv[1], sys.argv[2])")
call append(line(".")+20, " handle.Process()")
call append(line(".")+21, "")
call append(line(".")+22, "")
endif
if expand("%:e") == 'c'
call setline(1,"#include <stdio.h>")
call append(line("."), "#include <stdlib.h>")
call append(line(".")+1, "")
call append(line(".")+2, "")
call append(line(".")+3, "int main()")
call append(line(".")+4, "{")
call append(line(".")+5, "")
call append(line(".")+6, "")
call append(line(".")+7, " return 0;")
call append(line(".")+8, "}")
endif
if expand("%:e") == 'h'
call setline(1,"#ifndef _".toupper(expand("%:t:r"))."_H")
call append(line("."), "#define _".toupper(expand("%:t:r"))."_H")
call append(line(".")+1, "")
call append(line(".")+2, "")
call append(line(".")+3, "")
call append(line(".")+4, "")
call append(line(".")+5, "#ifdef __cplusplus")
call append(line(".")+6, "extern \"C\"")
call append(line(".")+7, "{")
call append(line(".")+8, "#endif")
call append(line(".")+9, "")
call append(line(".")+10, "#ifdef __cplusplus")
call append(line(".")+11, "}")
call append(line(".")+12, "#endif")
call append(line(".")+13, "")
call append(line(".")+14, "#endif //".toupper(expand("%:t:r"))."_H")
endif
if expand("%:e") == 'hpp'
call setline(1,"#ifndef _".toupper(expand("%:t:r"))."_HPP")
call append(line("."), "#define _".toupper(expand("%:t:r"))."_HPP")
call append(line(".")+1, "")
call append(line(".")+2, "")
call append(line(".")+3, "")
call append(line(".")+4, "")
call append(line(".")+5, "#ifdef __cplusplus")
call append(line(".")+6, "extern \"C\"")
call append(line(".")+7, "{")
call append(line(".")+8, "#endif")
call append(line(".")+9, "")
call append(line(".")+10, "#ifdef __cplusplus")
call append(line(".")+11, "}")
call append(line(".")+12, "#endif")
call append(line(".")+13, "")
call append(line(".")+14, "#endif //".toupper(expand("%:t:r"))."_HPP")
endif
autocmd BufNewFile * normal G
endfunc
" python
" autocmd FileType python set expandtab
autocmd FileType python setlocal tabstop=2 shiftwidth=2 softtabstop=2
"""
inoremap ( ()<ESC>i
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap { {<CR>}<ESC>O
inoremap } <c-r>=ClosePair('}')<CR>
inoremap [ []<ESC>i
inoremap ] <c-r>=ClosePair(']')<CR>
"inoremap " ""<ESC>i
"inoremap ' ''<ESC>i
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction
" taglist start
let Tlist_Ctags_Cmd='/usr/bin/ctags'
set tags=tags
set tags+=/home/jucai/.vim/tags_cpp
set autochdir
map <silent> <F6> :!ctags -R . --c++-kinds=+p --fields=+iaS --extra=+q<CR>
let Tlist_Auto_Open=1
let Tlist_Show_One_File=1
let Tlist_WinWidth=30
let Tlist_Exit_OnlyWindow=1
let Tlist_Use_Right_Window=1
map <silent> <F8> :TlistToggle<cr>
" taglist end
" nerdtree
let g:NERDTreeWinPos="left"
let g:NERDTreeWinSize=25
let g:NERDTreeShowLineNumbers=1
let g:neocomplcache_enable_at_startup=1
" nerdtree end
" OmniCppComplete
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
let OmniCpp_MayCompleteDot = 1 " autocomplete after.
let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
set completeopt=menuone,menu,longest,preview
" OmniCppComplete end
filetype on
filetype plugin on
filetype indent on
这个里面包含以下三个插件,代码折叠,文件头等等函数
taglist 代码索引nerdtree 文件树结构OmniCppComplete 代码补全
简要说明: taglist 这个比较简单,直接下载最新的taglist,将其 .doc .vim 文件拷贝到 ~/.vim/doc ~/.vim/plugin 中即可。 nerdtree上面是通过bundle来管理的。 OmniCppComplete 这个会涉及到ctags,这里的ctags注意需要生成以下,然后在加入到tags中。 上面主要的参考的链接是
nerdtree
nerdtree的插件安装,直接参考网页 https://blog.csdn.net/qq_33862644/article/details/80545654
ctags https://blog.csdn.net/u013445530/article/details/46726109taglist plugin/taglist.vim – taglist插件 doc/taglist.txt - taglist帮助文件
百度网盘地址 链接:https://pan.baidu.com/s/1iIakgHst4PoRj78A-bHKmw
提取码:d3nn
上面的地址基本解压就可以直接用。