首页 > 代码库 > 拾遗:vim 配置(个人适用,仅供参考)

拾遗:vim 配置(个人适用,仅供参考)

~/.vimrc

  1 "===================通用配置======================
  2 
  3 "文件搜索路径
  4 "set path=.,/usr/include,
  5 
  6 " 控制
  7 set nocompatible              "关闭vi兼容
  8 filetype off                  "关闭文件类型侦测,vundle需要
  9 set fileencodings=utf-8       "使用utf-8
 10 syntax on                     "语法高亮
 11 set backspace=2               "退格键正常模式
 12 "set whichwrap=<,>,[,]         "当光标到行首或行尾,允许左右方向键换行
 13 set autoread                  "文件在vim外修改过,自动重载      
 14 set nobackup                  "不使用备份
 15 set confirm                   "在处理未保存或只读文件时,弹出确认消息   
 16 set scrolloff=3               "光标移动到距离顶部或底部开始滚到距离
 17 set history=1000              "历史记录数
 18 set mouse=                    "关闭鼠标
 19 set selection=inclusive       "选择包含最后一个字符
 20 set selectmode=mouse,key      "启动选择模式的方式
 21 "set completeopt=longest,menu  "智能补全,弹出菜单,无歧义时才自动填充
 22 set noswapfile                "关闭交换文件
 23 set hidden                    "允许在有未保存的修改时切换缓冲区
 24 
 25 "显示
 26 colorscheme desert           "选择配色方案
 27 set t_Co=256                  "可以使用的颜色数目
 28 set number                    "显示行号
 29 set laststatus=2              "显示状态行
 30 set ruler                     "显示标尺
 31 set showcmd                   "显示输入的命令
 32 set showmatch                 "高亮括号匹配
 33 set matchtime=1               "匹配括号高亮的时间(十分之一秒)
 34 set matchpairs={:},(:),[:],<:>        "匹配括号"{}""()"...等    
 35 set hlsearch                  "检索时高亮匹配项
 36 set incsearch                 "边检索边显示匹配
 37 "set go-=T                     "去除gvim的toolbar
 38 
 39 "格式
 40 set noexpandtab               "不要将tab转换为空格
 41 set shiftwidth=4              "自动缩进的距离,也是平移字符的距离
 42 set tabstop=4                 "tab键对应的空格数
 43 set autoindent                "自动缩进
 44 set smartindent               "智能缩进
 45 
 46 "===================按键映射======================
 47 
 48 "按键映射的起始字符
 49 let mapleader = \‘             
 50 
 51 "使用Ctrl-l 和 Ctrl+h 切换标签页
 52 nnoremap <C-l> gt            
 53 nnoremap <C-h> gT
 54 nnoremap <C-n> tabnew
 55 
 56 "在行末加上分号
 57 "map! <F9> <Esc>A<Space>;<CR>
 58 
 59 "===================插件管理======================
 60 
 61 " 下载pathogen
 62 " curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
 63 
 64 " 自动配对括号
 65 " git clone git://github.com/jiangmiao/auto-pairs.git ~/.vim/bundle/auto-pairs
 66 
 67 " 目录管理器
 68 " git clone https://github.com/scrooloose/nerdtree.git ~/.vim/bundle/nerdtree
 69 
 70 "tagbar 插件
 71 " git clone https://github.com/majutsushi/tagbar.git ~/.vim/bundle/tagbar
 72 
 73 "gotags:显示 go 的tagbar
 74 "go get -u github.com/jstemmer/gotags
 75 "go install
 76 
 77 " 下载 YCM 及其附属模块源码
 78 "git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
 79 "git submodule update --init --recursive
 80 
 81 " 编译安装全功能 YCM (需要首先安装最新版本的 clang 库:libclang.so);也可以使用自带的脚本安装,如仅安装 go 的语义补全:./install.py  --gocode-completer
 82 "step0: cd $BuildDir \
 83 "step1: cmake -G "Unix Makefiles" -DPATH_TO_LLVM_ROOT=/PATH/TO/LLVM_Root_Dir . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp \
 84 "step2: make
 85 
 86 " YCM 常用命令
 87 "    :YcmRestartServer  重启 YCM 服务器
 88 "    :YcmCompleter  显示可用的子命令
 89 "    :YcmCompleter GetParent  显示父函数、父类等
 90 "    :YcmCompleter GetType  显示类型、参数等信息
 91 "    :YcmCompleter GetDoc  跳转至相关文档(若有)
 92 "    :YcmCompleter GoToDeclaration  跳转至声明处
 93 "    :YcmCompleter GoToDefinition  跳转至定义处
 94 "    :YcmCompleter GoToInclude  跳转至头文件处
 95 
 96 filetype plugin indent on    " required
 97 
 98 "===================插件配置======================
 99 
100 "-----pathogen-----
101 execute pathogen#infect() 
102 
103 "-----NERDTree-----
104 let g:NERDTreeCaseSensitiveSort = 1
105 let g:NERDTreeWinSize = 32
106 let g:NERDTreeWinPos = "left"
107 nnoremap <F5> :NERDTreeToggle<CR> 
108 "nnoremap <Leader>o :NERDTreeFind<CR>
109 
110 let g:tagbar_type_go = { 
111     \ ctagstype : go,
112     \ kinds     : [ 
113         \ p:package,
114         \ i:imports:1,
115         \ c:constants,
116         \ v:variables,
117         \ t:types,
118         \ n:interfaces,
119         \ w:fields,
120         \ e:embedded,
121         \ m:methods,
122         \ r:constructor,
123         \ f:functions
124     \ ],
125     \ sro : .,
126     \ kind2scope : { 
127         \ t : ctype,
128         \ n : ntype
129     \ },
130     \ scope2kind : { 
131         \ ctype : t,
132         \ ntype : n 
133     \ },
134     \ ctagsbin  : gotags,
135     \ ctagsargs : -sort -silent
136 \ } 
137 
138 "-----tagbar-------
139 let g:tagbar_width=32
140 let g:tagbar_autofocus=1
141 nnoremap <F6> :TagbarToggle<CR>
142 
143 "-----YouCompleteMe-----
144 let g:ycm_server_python_interpreter= /usr/bin/python
145 let g:ycm_global_ycm_extra_conf = ~/.ycm_extra_conf.py "默认配置文件
146 "let g:ycm_key_invoke_completion = ‘<C-Tab>‘         "跨文件补全
147 let g:ycm_confirm_extra_conf = 0                    "关闭加载配置文件提示
148 let g:ycm_cache_omnifunc = 0                        "关闭补全缓存
149 let g:ycm_enable_diagnostic_signs = 0               "关闭诊断提示符
150 let g:ycm_enable_diagnostic_highlighting = 1        "关闭诊断高亮
151 "let g:ycm_show_diagnostics_ui = 0                   "关闭诊断ui
152 let g:ycm_min_num_of_chars_for_completion = 2       "n字符开始自动补全
153 
154 "跳转至定义或声明处
155 nnoremap <Leader>d :YcmCompleter GoToDefinitionElseDeclaration<CR>
156 "获取变量/函数类型
157 nnoremap <Leader>t :YcmCompleter GetType<CR>
158 
159 "极简风格的 ~/.ycm_extra_conf.py 文件,此处仅作助记用,以下内容不应解除注释
160 "def FlagsForFile( filename, **kwargs ):
161 "   return {
162 "     ‘flags‘: [ ‘-x‘, ‘c‘, ‘-Wall‘, ‘-Wextra‘, ‘-Werror‘, ‘-std=c11‘, ‘-isystem‘, ‘/usr/include‘, ‘-I../inc‘ ],
163 "   } 

~/.vim/colors/desert.vim

  1 " Vim color file
  2 " Maintainer:    Hans Fugal <hans@fugal.net>
  3 " Last Change:    $Date: 2003/07/24 00:57:11 $
  4 " Last Change:    $Date: 2003/07/24 00:57:11 $
  5 " URL:        http://hans.fugal.net/vim/colors/desert.vim
  6 " Version:    $Id: desert.vim,v 1.7 2003/07/24 00:57:11 fugalh Exp $
  7 
  8 " cool help screens
  9 " :he group-name
 10 " :he highlight-groups
 11 " :he cterm-colors
 12 
 13 set background=dark
 14 if version > 580
 15     " no guarantees for version 5.8 and below, but this makes it stop
 16     " complaining
 17     hi clear
 18     if exists("syntax_on")
 19     syntax reset
 20     endif
 21 endif
 22 let g:colors_name="desert"
 23 
 24 hi Normal    guifg=White guibg=grey20
 25 
 26 " highlight groups
 27 hi Cursor    guibg=indianred guifg=khaki
 28 "hi CursorIM
 29 "hi Directory
 30 "hi DiffAdd
 31 "hi DiffChange
 32 "hi DiffDelete
 33 "hi DiffText
 34 "hi ErrorMsg
 35 hi VertSplit    guibg=#c2bfa5 guifg=grey50 gui=none
 36 hi Folded    guibg=grey30 guifg=gold
 37 hi FoldColumn    guibg=grey30 guifg=tan
 38 hi IncSearch    guifg=slategrey guibg=khaki
 39 "hi LineNr
 40 hi ModeMsg    guifg=goldenrod
 41 hi MoreMsg    guifg=SeaGreen
 42 hi NonText    guifg=LightBlue guibg=grey30
 43 hi Question    guifg=springgreen
 44 hi Search    guibg=olivedrab guifg=wheat
 45 hi SpecialKey    guifg=yellowgreen
 46 hi StatusLine    guibg=#c2bfa5 guifg=black gui=none
 47 hi StatusLineNC    guibg=#c2bfa5 guifg=grey50 gui=none
 48 hi Title    guifg=indianred
 49 hi Visual    gui=none guifg=khaki guibg=olivedrab
 50 "hi VisualNOS
 51 hi WarningMsg    guifg=salmon
 52 "hi WildMenu
 53 "hi Menu
 54 "hi Scrollbar
 55 "hi Tooltip
 56 
 57 " syntax highlighting groups
 58 hi Comment    guifg=SkyBlue
 59 hi Constant    guifg=#ffa0a0
 60 hi Identifier    guifg=palegreen
 61 hi Statement    guifg=khaki
 62 hi PreProc    guifg=indianred
 63 hi Type        guifg=darkkhaki
 64 hi Special    guifg=navajowhite
 65 "hi Underlined
 66 hi Ignore    guifg=grey40
 67 "hi Error
 68 hi Todo        guifg=orangered guibg=yellow2
 69 
 70 " color terminal definitions
 71 hi SpecialKey    ctermfg=darkgreen
 72 hi NonText    cterm=bold ctermfg=darkblue
 73 hi Directory    ctermfg=darkcyan
 74 hi ErrorMsg    cterm=bold ctermfg=7 ctermbg=1
 75 hi IncSearch    cterm=NONE ctermfg=yellow ctermbg=green
 76 hi Search    cterm=NONE ctermfg=grey ctermbg=blue
 77 hi MoreMsg    ctermfg=darkgreen
 78 hi ModeMsg    cterm=NONE ctermfg=brown
 79 hi LineNr    ctermfg=3
 80 hi Question    ctermfg=green
 81 hi StatusLine    cterm=bold,reverse
 82 hi StatusLineNC cterm=reverse
 83 hi VertSplit    cterm=reverse
 84 hi Title    ctermfg=5
 85 hi Visual    cterm=reverse
 86 hi VisualNOS    cterm=bold,underline
 87 hi WarningMsg    ctermfg=1
 88 hi WildMenu    ctermfg=0 ctermbg=3
 89 hi Folded    ctermfg=darkgrey ctermbg=NONE
 90 hi FoldColumn    ctermfg=darkgrey ctermbg=NONE
 91 hi DiffAdd    ctermbg=4
 92 hi DiffChange    ctermbg=5
 93 hi DiffDelete    cterm=bold ctermfg=4 ctermbg=6
 94 hi DiffText    cterm=bold ctermbg=1
 95 hi Comment    ctermfg=darkcyan
 96 hi Constant    ctermfg=brown
 97 hi Special    ctermfg=5
 98 hi Identifier    ctermfg=6
 99 hi Statement    ctermfg=3
100 hi PreProc    ctermfg=5
101 hi Type        ctermfg=2
102 hi Underlined    cterm=underline ctermfg=5
103 hi Ignore    cterm=bold ctermfg=7
104 hi Ignore    ctermfg=darkgrey
105 hi Error    cterm=bold ctermfg=7 ctermbg=1
106 
107 
108 "vim: sw=4

...

拾遗:vim 配置(个人适用,仅供参考)