"============================================================================
" A more concise, clear and complete vim config for me.
"============================================================================
" Platform: Linux
" vim: set sw=4 ts=4 sts=4 et tw=78 foldmarker={,} foldlevel=0 foldmethod=marker :
" 初始化设置 {
"
" 不兼容vi
set nocompatible
" 使用默认shell
set shell=/bin/sh
" }
" 加载插件相关配置 {
"
if has("multi_byte")
" 设置本地通用编码 utf-8
set encoding=utf-8
" 设置通用文件编码格式 utf-8
setglobal fileencoding=utf-8
" 设置文件可用的编码格式
set fileencodings=ucs-bom,utf-8,utf-16le,cp1252,iso-8859-15
endif
"
" 使用Bundle 管理插件
" 关闭文件类型识别,并确保 vundle 能够工作
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#rc()
""""""""""""""""""""""""""""" Bundles """"""""""""""""""""""""""""
" Vundle 管理 Vundle
Plugin 'gmarik/Vundle.vim'
" Vim 中文帮助文档
Plugin 'yianwillis/vimcdoc'
" 代码片段功能
" snipmate lib
Plugin 'MarcWeber/vim-addon-mw-utils'
" snipmate lib
Plugin 'tomtom/tlib_vim'
Plugin 'garbas/vim-snipmate'
" 该插件中包含了各种语言的代码片段,增强snipmate功能
Plugin 'honza/vim-snippets'
Bundle 'vim-scripts/sessionman.vim'
" 显示当前路径目录树
Bundle 'scrooloose/nerdtree'
" solarized 颜色主题
Bundle 'altercation/vim-colors-solarized'
" 对于环境中的 大小括号,引号,XML标签等进行成对映射处理(删除或添加)
Bundle 'tpope/vim-surround'
" 用于协助解决冲突的工具
" 高亮有冲突标记的位置,跳转到有冲突标记的位置,
" 跳转到冲突块中:开始,分隔符,末尾
Bundle 'rhysd/conflict-marker.vim'
" 成对插入/删除大小括号,引号
Bundle 'jiangmiao/auto-pairs'
" Vim中使用%实现括号间的跳转,该插件可以设置任意想要跳转的标记
Bundle 'matchit.zip'
"仅使用顶端显示 buffer smart tab line功能
Bundle 'vim-airline/vim-airline'
Bundle 'vim-airline/vim-airline-themes'
" 显示命令栏中缓冲区的列表
Bundle 'bling/vim-bufferline'
" 整合vim中的 nerdtree 和 tabs
Bundle 'jistr/vim-nerdtree-tabs'
" 撤销操作树
Bundle 'mbbill/undotree'
" 用于在重新启动vim后自动恢复一个文件的光标位置和折叠信息。
Bundle 'vim-scripts/restore_view.vim'
" 使用Vim的符号列显示diff,在符号栏显示 ! 等标志修改等部分。
Bundle 'mhinz/vim-signify'
" 方便搜索,替换和单词等缩写多个变体
Bundle 'tpope/vim-abolish.git'
" 使用替换时有预览
Bundle 'osyo-manga/vim-over'
" 创建自己的文本对象
Bundle 'kana/vim-textobj-user'
" 用于缩进线条的文本对象
Bundle 'kana/vim-textobj-indent'
" 语法检查
Bundle 'scrooloose/syntastic'
" web 的一些 api 插件接口
" 当前支持的协议:
" Basic HTTP,OAuth,Atompub,SOAP (in progress),XMLRPC,MetaWeblog API
" 包含的库:
" XML Parser,HTML Parser(Hack Way),JSON Parser,BASE64 Hash Algorithm,
" SHA1 Hash Algorithm,HMAC HASH Algorithm,Bit Operation Library,Converter for "UTF-8 to Unicode"
Bundle 'mattn/webapi-vim'
" 快速注释
Bundle 'scrooloose/nerdcommenter'
" 也是注释用插件,默认使用 注释的方式,所以 Python shell 不支持该
" 的注释。
" gcc: 注释当前行(普通模式); gc: 可视模式下注释选中部分;
" gcu: 撤销上次注释的部分; gcgc: 撤销注释当前行和临近的上下两行。
Bundle 'tpope/vim-commentary'
" 文本过滤和对齐,格式化工具
Bundle 'godlygeek/tabular'
" 通过不同的颜色展示不同层次的括号
Bundle 'luochen1990/rainbow'
if executable('ctags')
" 在窗口中显示标签,按范围排序
Bundle 'majutsushi/tagbar'
endif
""""""""" 自动补全
" 根据当前文档,缓存文档等智能自动补全
Bundle 'Shougo/neocomplete.vim.git'
Bundle 'Shougo/neosnippet'
Bundle 'Shougo/neosnippet-snippets'
""""""""" Python
" python-mode 插件,可以帮助使用者通过使用包括
" pylint,rope,pydoc,pyflakes,pep8 和 mccabe 在内的库来快速创建
" python 代码,用于静态分析,重构,折叠,补全,文档等功能。
"Bundle 'python-mode/python-mode'
" 方便编写 Python 脚本的插件,有以下功能:
" 选择一组具有相同缩进的行;
" 选择一个方法,一个类;
" 到达上一个/下一个类/方法;
" 跳转到块的开始或结尾;
" 注释/取消注释的选择;
" 使用相同的缩进跳转到最后/下一行;
" 移动一个块(左/右);
" 创建便于导航的类或方法的列表
Bundle 'yssource/python.vim'
" 该插件重新定义了%的动作,以便它能够循环通过 if/elif/else,
" try/except/catch, for/continue/break 和 while/continue/break 结构。
" 另外两个动作,[% 和 ]% 分别到达当前块的开始和结束。
Bundle 'python_match.vim'
" Pythond 的一些补全功能。
Bundle 'pythoncomplete'
Bundle 'vim-scripts/indentpython.vim'
Bundle 'nvie/vim-flake8'
""""""""" HTML
" 使 vim 支持 css3 的语法
Bundle 'hail2u/vim-css3-syntax'
" 用于在键入颜色的编码后显示对应的颜色背景(如,#fF0000)
Bundle 'gorodinskiy/vim-coloresque'
" 该项目包含与Vim一起提供的Haml,Sass和SCSS的运行时文件。
Bundle 'tpope/vim-haml'
" 提供类似扩展缩写的支持
Bundle 'mattn/emmet-vim'
" Tmux
Bundle 'christoomey/vim-tmux-navigator'
""""""""""""""""""""""""""""" Bundles """"""""""""""""""""""""""""
" }
" 通用设置 {
"
" 暗色背景
set background=dark
" 背景转换触发方法
function! TransformBG()
let s:tbg = &background
" 转换逻辑
if s:tbg == "dark"
set background=light
else
set background=dark
endif
endfunction
" 触发方法
noremap <leader>bg :call TransformBG()<CR>
" 执行了3个动作 filetype on-> filetype plugin on -> filetype indent on
" 开启文件类型检测-> 自动加载相应插件 -> 启用相关缩进插件
filetype plugin indent on
" 语法高亮
syntax on
" 自动使用鼠标,如果使用鼠标复制 粘贴,需要禁用该设置
" 使用Vim时建议尽量少用鼠标
set mouse=a
" 打字时隐藏鼠标光标
set mousehide
" 脚本编码格式 utf-8
scriptencoding utf-8
" Linux 系统一般具有粘贴版:
" unnamed 选择粘贴版,vim 映射到 * 寄存器
" unnamedplus 系统粘贴版,和其其他平台的Ctrl+C,Ctrl+V功能相同,vim映射到 + 寄存器
" 以下设置可以跨平台使用,:reg 查看寄存器详情
if has('clipboard') && has("unnamedplus")
set clipboard=unnamed,unnamedplus
endif
" universal-ctags 替换 exuberant-ctags 并配置
set tags=tags
" 自动切换当前目录为当前编辑文件所在的目录
set autochdir
" 切换到新的文件(新Buffer)后,目录自动切换到当前编辑文件(Buffer)的路径
autocmd BufEnter * if bufname("") !~ "^\[A-Za-z0-9\]*://" | lcd %:p:h | endif
" 启动vim时不显示乌干达的信息
set shortmess=alI
" 虚拟编辑,允许光标定位达到每行最后一个字符之后
set virtualedit=onemore
" 保存更多的编辑历史
set history=1000
" 拼写检查
"set spell
" 允许在不保存的情况下切换编辑buffer
set hidden
" _,@,#,$,-连接的字符作为一个整体,选择、换行不分割
set iskeyword+=_,@,#,$,-
" 编辑 git commit 信息时,编辑光标定位最开始
au FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0])
" 再次打开文件光标恢复到最后编辑的位置
function! ResCur()
if line("'\'") <= line("$")
silent! normal! g`"
return 1
endif
endfunction
augroup resCur
autocmd!
autocmd BufWinEnter * call ResCur()
augroup END
"
" 设置备份
set backup
" 持久的保存当前文件的编辑历史,用于可持久性的撤销操作
" 防止再次打开编辑过的文件无法进行之前操作的撤销动作
if has('persistent_undo')
" 激活撤销
set undofile
" 最大撤销的行数
set undolevels=1000
" 重新加载buffer时能够保存的最大撤销行数
set undoreload=10000
endif
" 初始化 vimbackup, vimviews, vimswap, vimundo 目录
" 并把 backup, view, swap, undo 文件放入相应目录中
function! InitializeDirectories()
let parent = $HOME
let prefix = 'vim'
let dir_list = {
\ 'backup': 'backupdir',
\ 'views': 'viewdir',
\ 'swap': 'directory' }
if has('persistent_undo')
let dir_list['undo'] = 'undodir'
endif
" backup, view, swap, undo 文件放入指定的 vimbackup, vimviews, vimswap, vimundo 目录
let common_dir = parent . '/.vim/' . prefix
for [dirname, settingname] in items(dir_list)
let directory = common_dir . dirname . '/'
if exists("*mkdir")
if !isdirectory(directory)
call mkdir(directory)
endif
endif
if !isdirectory(directory)
echo "Warning: Unable to create backup directory: " . directory
echo "Try: mkdir -p " . directory
else
let directory = substitute(directory, " ", "\\\\ ", "g")
exec "set " . settingname . "=" . directory
endif
endfor
endfunction
call InitializeDirectories()
" avoid -- No newline at end of file
set binary
set noeol
" }
" Vim UI 的设置 {
" 有 vim-colors-solarized 插件时,自定义一些设置
if filereadable(expand("~/.vim/bundle/vim-colors-solarized/colors/solarized.vim"))
let g:solarized_termcolors=256
let g:solarized_termtrans=1
let g:solarized_contrast="normal"
let g:solarized_visibility="normal"
" 加载 solarized 颜色主题
color solarized
endif
" 多标签页的窗口编辑
" 一个标签页容纳一个或多个窗口,标签页间切换容易,这种方式可以使使用者拥有多个窗口集合
" 每个集合做不同的事情,标签页个数不能超过 tabpagemax
set tabpagemax=15
" 显示当前所处模式
set showmode
" 突出显示当前行
set cursorline
" 突出显示当前垂直行
set cursorcolumn
" 标识栏和匹配背景色
highlight clear SignColumn
" 当前行号匹配当前模式的背景颜色
highlight clear LineNr
" Vim 命令行及状态栏的设置
" 命令行的显示设置
if has('cmdline_info')
" 打开状态栏标尺
set ruler
" 设置状态栏标尺格式
set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%)
" 显示输入时的命令,可以直观的查看输入的命令
set showcmd
endif
" 状态栏的显示设置
if has('statusline')
" 总是显示状态栏
set laststatus=2
" 设置状态栏显示常用信息
" %{...} 评估表达式的值,并用值代替
" 显示当前文件的个数编号
set statusline=%<[%n]
" 显示完整文件路径名信息
set statusline+=\ %F
" 仅显示文件名信息(不包括路径)
"set statusline+=\ %f
" %m 当前缓冲被修改标记
" %r 当前缓冲只读标记
" %w 预览缓冲标记
" %h 帮助缓冲标记
set statusline+=%m%r%w%h
" 显示当前文件所在目录
"set statusline+=\ [%{getcwd()}]
" 显示文件类型
set statusline+=\ [TYPE=%Y
" 显示文件格式(unix/mac/dos)
set statusline+=\ FORMAT=%{&ff}
" 显示文件编码格式
set statusline+=\ ENCODING=%{(&fenc==\"\")?&enc:&fenc}%{(&bomb?\",BOM\":\"\")}]
" 显示当前光标所在字符的ASCII编码
set statusline+=\ [ASCII=\%03.3b
" 显示当前光标所在字符编码对应的16进制值
set statusline+=\ HEX=\%02.2B]
" 显示当前光标的坐标位置
set statusline+=\ [POS=%04l,%04v
" 显示当前文件的总行数
set statusline+=\ LEN=%L]
" 显示当前位置所处当前文件的百分比
set statusline+=[%p%%]
endif
" 模仿出一个 backspace
set backspace=indent,eol,start
" 防止两行之间有多余的空格
set linespace=0
" 显示行号
set nu
" 显示匹配的括号
set showmatch
" 增量动态搜索
set incsearch
" 突出显示搜索内容
set hlsearch
" 允许窗口的最小高度为0
set winminheight=0
" 搜索忽略大小写
set ignorecase
" 检索时,智能判断大小写(用于检索键入的内容有大小写区分时)
set smartcase
" 在状态栏上命令行智能列出待选命令并补全
set wildmenu
" wildmenu 的匹配模式及顺训
set wildmode=list:longest,full
" 可以从行首/尾调到另外一行
set whichwrap=b,s,h,l,<,>,[,] " Backspace and cursor keys wrap too
" 控制光标到达窗口顶/底端时,窗口发生滚动的行数
set scrolljump=5
" 光标移动顶/底端,保持设置的距离就开始滚动
set scrolloff=3
" 自动折叠代码
set foldenable
" 设置 list 可以显示 TAB 键
set list
" 突出显示有问题的空白部分
set listchars=tab:›\ ,trail:•,extends:#,nbsp:.
" }
" 格式化显示 {
" 取消自动换行
set nowrap
"set wrap
"
" 自动与上一级保持相同的缩进
set autoindent
" 程序中自动缩进所使用的空白长度的设置
set shiftwidth=4
" 将制表符(Tab)换为空格,避免使用制表符(Tab)
set expandtab
" 定义每个Tab等同的空格长度
set tabstop=4
" 空格数满足设定值整数倍时,这转换为相应倍数个的Tab,否则全部为空格
set softtabstop=4
" 通过设置 joinspaces 可以控制合并两行时的分隔符
" nojoinspaces 用 J 命令合并两行时会用一个空格来分隔;
" joinspaces 用 J 命令合并两行时会用两个空格来分隔;
" 不希望用空格来分隔合并的行,使用命令 gJ
set nojoinspaces
" 将新垂直分割的窗空放置在当前窗口右侧
set splitright
" 将新水平分割的窗空放置在当前窗口下侧
set splitbelow
"set matchpairs+=<:> " Match, to be used with %
" vim中在粘贴剪贴板中的数据时会自动增加缩进
" 设置粘贴模式,在粘贴模式下复制粘贴可以预防出现粘贴时候的缩进
set pastetoggle=<F12>
" 自动格式化注释的部分
set comments=sl:
set fileformat=unix " 文件为unix格式
" 移除末尾的 空白 和 ^M 字符
" 发生在整个缓冲区被写入之前除去末尾的空白
" 根据扩展名识别文件类型
"autocmd FileType c,cpp,java,go,php,javascript,puppet,python,rust,twig,xml,yml,perl,sql autocmd BufWritePre <buffer> call StripTrailingWhitespace()
"autocmd FileType go autocmd BufWritePre <buffer> Fmt
"autocmd BufNewFile,BufRead *.html.twig set filetype=html.twig
"autocmd FileType haskell,puppet,ruby,yml setlocal expandtab shiftwidth=2 softtabstop=2
" preceding line best in a plugin but here for now.
"autocmd BufNewFile,BufRead *.coffee set filetype=coffee
" Workaround vim-commentary for Haskell
"autocmd FileType haskell setlocal commentstring=--\ %s
" Workaround broken colour highlighting in Haskell
"autocmd FileType haskell,rust setlocal nospell
" 标记掉不必要的空格
"au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
"
" }
" 自定义按键映射 {
" 在全局插件中使用 mappleader;
" 在某个插件(例:文件类型插件)中使用 maplocalleader
" mapleader 与 maplocalleader 可以相同,为避免冲突,分别设置他们
let mapleader=','
let maplocalleader='_'
" 正常切换窗口或Tab时,使用 Ctrl+W 触发,然后 h/j/k/l 进行窗口或Tab的跳转
" 以下设置使用 Ctrl+/h/j/k/l 组合键进行切换, 使切换更便捷
map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_
map <C-L> <C-W>l<C-W>_
map <C-H> <C-W>h<C-W>_
" 当一行特别长时出现折行显示(折行没有换行符,其实是一行),这时候如果想用 j/k
" 上下移动到折行的位置会发现光标会直接跳到有换行符的的下一行,进行一下设置可以避免
noremap j gj
noremap k gk
" 代码折叠设置
nmap <leader>f0 :set foldlevel=0<CR>
nmap <leader>f1 :set foldlevel=1<CR>
nmap <leader>f2 :set foldlevel=2<CR>
nmap <leader>f3 :set foldlevel=3<CR>
nmap <leader>f4 :set foldlevel=4<CR>
nmap <leader>f5 :set foldlevel=5<CR>
nmap <leader>f6 :set foldlevel=6<CR>
nmap <leader>f7 :set foldlevel=7<CR>
nmap <leader>f8 :set foldlevel=8<CR>
nmap <leader>f9 :set foldlevel=9<CR>
nmap <leader>f9 :set foldlevel=9<CR>
nmap <leader>f9 :set foldlevel=9<CR>
" 切换搜索突出显示
nmap <silent> <leader>/ :set invhlsearch<CR>
" 查找合并时出现的冲突标记
" }
map <leader>fc /\v^[<\|=>]{7}( .*\|$)<CR>
" 视觉模式下调节缩进时不退出视觉模式
vnoremap < <gv
vnoremap > >gv
" 对于有权限的文件,防止编辑前忘记获取权限,在编辑后无法保存的现象
cmap w!! w !sudo tee % >/dev/null
" 创建映射,以便于在活动窗口中打开相同目录中的文件
cnoremap %% <C-R>=fnameescape(expand('%:h')).'/'<cr>
map <leader>ew :e %%
map <leader>es :sp %%
map <leader>ev :vsp %%
map <leader>et :tabe %%
" 把所有窗口调节相同大小
map <Leader>= <C-w>=
" nowarp 模式下时,zl/zh 使窗口整体左/右移动1字符,
" zL/zH 使窗口整体左/右移动半个窗口
" zl/zh 使用不方便,使 zl/zh 映射到 zL/zH
map zl zL
map zh zH
" Tmux
"let g:tmux_navigator_no_mappings = 1
"nnoremap <silent> <C-J> :TmuxNavigateLeft<cr>
"nnoremap <silent> <C-K> :TmuxNavigateDown<cr>
"nnoremap <silent> <C-L> :TmuxNavigateUp<cr>
"nnoremap <silent> <C-H> :TmuxNavigateRight<cr>
"nnoremap <silent> <C-P> :TmuxNavigatePrevious<cr>
" Cscope 设置 {
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CSCOPE settings for vim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" This file contains some boilerplate settings for vim's cscope interface,
" plus some keyboard mappings that I've found useful.
"
" USAGE:
" -- vim 6: Stick this file in your ~/.vim/plugin directory (or in a
" 'plugin' directory in some other directory that is in your
" 'runtimepath'.
"
" -- vim 5: Stick this file somewhere and 'source cscope.vim' it from
" your ~/.vimrc file (or cut and paste it into your .vimrc).
"
" NOTE:
" These key maps use multiple keystrokes (2 or 3 keys). If you find that vim
" keeps timing you out before you can complete them, try changing your timeout
" settings, as explained below.
"
" Happy cscoping,
"
" Jason Duell jduell@alumni.princeton.edu 2002/3/7
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" This tests to see if vim was configured with the '--enable-cscope' option
" when it was compiled. If it wasn't, time to recompile vim...
if has("cscope")
""""""""""""" Standard cscope/vim boilerplate
" use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'
set cscopetag
" check cscope for definition of a symbol before checking ctags: set to 1
" if you want the reverse search order.
set csto=0
"set cscopeverbose
" add any cscope database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add the database pointed to by environment variable
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
" show msg when any other cscope db added
set cscopeverbose
""""""""""""" My cscope/vim key mappings
"
" The following maps all invoke one of the following cscope search types:
"
" 's' symbol: find all references to the token under cursor
" 'g' global: find global definition(s) of the token under cursor
" 'c' calls: find all calls to the function name under cursor
" 't' text: find all instances of the text under cursor
" 'e' egrep: egrep search for the word under cursor
" 'f' file: open the filename under cursor
" 'i' includes: find files that include the filename under cursor
" 'd' called: find functions that function under cursor calls
"
" Below are three sets of the maps: one set that just jumps to your
" search result, one that splits the existing vim window horizontally and
" diplays your search result in the new window, and one that does the same
" thing, but does a vertical split instead (vim 6 only).
"
" I've used CTRL-\ and CTRL-@ as the starting keys for these maps, as it's
" unlikely that you need their default mappings (CTRL-\'s default use is
" as part of CTRL-\ CTRL-N typemap, which basically just does the same
" thing as hitting 'escape': CTRL-@ doesn't seem to have any default use).
" If you don't like using 'CTRL-@' or CTRL-\, , you can change some or all
" of these maps to use other keys. One likely candidate is 'CTRL-_'
" (which also maps to CTRL-/, which is easier to type). By default it is
" used to switch between Hebrew and English keyboard mode.
"
" All of the maps involving the <cfile> macro use '^$': this is so
" that searches over '#include " return only references to
" 'time.h', and not 'sys/time.h', etc. (by default cscope will return all
" files that contain 'time.h' as part of their name).
" To do the first type of search, hit 'CTRL-\', followed by one of the
"
" cscope search types above (s,g,c,t,e,f,i,d). The result of your cscope
" search will be displayed in the current window. You can use CTRL-T to
" go back to where you were before the search.
"
nmap <C-\>s :cs find s <C-R>=expand("")<CR><CR>
nmap <C-\>g :cs find g <C-R>=expand("")<CR><CR>
nmap <C-\>c :cs find c <C-R>=expand("")<CR><CR>
nmap <C-\>t :cs find t <C-R>=expand("")<CR><CR>
nmap <C-\>e :cs find e <C-R>=expand("")<CR><CR>
nmap <C-\>f :cs find f <C-R>=expand("")<CR><CR>
" 空格必须要有
"nmap <C-\>f :cs find f
nmap <C-\>i :cs find i ^<C-R>=expand("")<CR>$<CR>
nmap <C-\>d :cs find d <C-R>=expand("")<CR><CR>
" Using 'CTRL-spacebar' (intepreted as CTRL-@ by vim) then a search type
" makes the vim window split horizontally, with search result displayed in
" the new window.
"
" (Note: earlier versions of vim may not have the :scs command, but it
" can be simulated roughly via:
" nmap s :cs find s =expand("<cword>")<CR><CR>
nmap <C-@><C-@>s :scs find s <C-R>=expand("")<CR><CR>
nmap <C-@><C-@>g :scs find g <C-R>=expand("")<CR><CR>
nmap <C-@><C-@>c :scs find c <C-R>=expand("")<CR><CR>
nmap <C-@><C-@>t :scs find t <C-R>=expand("")<CR><CR>
nmap <C-@><C-@>e :scs find e <C-R>=expand("")<CR><CR>
nmap <C-@><C-@>f :scs find f <C-R>=expand("")<CR><CR>
nmap <C-@><C-@>i :scs find i ^<C-R>=expand("")<CR>$<CR>
nmap <C-@><C-@>d :scs find d <C-R>=expand("")<CR><CR>
" Hitting CTRL-space *twice* before the search type does a vertical
" split instead of a horizontal one (vim 6 and up only)
"
" (Note: you may wish to put a 'set splitright' in your .vimrc
" if you prefer the new window on the right instead of the left
nmap <C-@>s :vert scs find s <C-R>=expand("")<CR><CR>
nmap <C-@>g :vert scs find g <C-R>=expand("")<CR><CR>
nmap <C-@>c :vert scs find c <C-R>=expand("")<CR><CR>
nmap <C-@>t :vert scs find t <C-R>=expand("")<CR><CR>
nmap <C-@>e :vert scs find e <C-R>=expand("")<CR><CR>
nmap <C-@>f :vert scs find f <C-R>=expand("")<CR><CR>
nmap <C-@>i :vert scs find i ^<C-R>=expand("")<CR>$<CR>
nmap <C-@>d :vert scs find d <C-R>=expand("")<CR><CR>
""""""""""""" key map timeouts
"
" By default Vim will only wait 1 second for each keystroke in a mapping.
" You may find that too short with the above typemaps. If so, you should
" either turn off mapping timeouts via 'notimeout'.
"
"set notimeout
"
" Or, you can keep timeouts, by uncommenting the timeoutlen line below,
" with your own personal favorite value (in milliseconds):
"
"set timeoutlen=4000
"
" Either way, since mapping timeout settings by default also set the
" timeouts for multicharacter 'keys codes' (like <F1>), you should also
" set ttimeout and ttimeoutlen: otherwise, you will experience strange
" delays as vim waits for a keystroke after you hit ESC (it will be
" waiting to see if the ESC is actually part of a key code like <F1>).
"
"set ttimeout
"
" personally, I find a tenth of a second to work well for key code
" timeouts. If you experience problems and have a slow terminal or network
" connection, set it higher. If you don't set ttimeoutlen, the value for
" timeoutlent (default: 1000 = 1 second, which is sluggish) is used.
"
"set ttimeoutlen=100
endif
" }
" }
" 插件的配置 {
" NerdTree {
if isdirectory(expand("~/.vim/bundle/nerdtree"))
map <C-e> <plug>NERDTreeTabsToggle<CR>
map <leader>e :NERDTreeFind<CR>
nmap <leader>nt :NERDTreeFind<CR>
let NERDTreeShowBookmarks=1
let NERDTreeIgnore=['\.py[cd]$', '\~$', '\.swo$', '\.swp$', '^\.git$', '^\.hg$', '^\.svn$', '\.bzr$']
let NERDTreeChDirMode=0
let NERDTreeQuitOnOpen=1
let NERDTreeMouseMode=2
let NERDTreeShowHidden=1
let NERDTreeKeepTreeInNewTab=1
let g:nerdtree_tabs_open_on_gui_startup=0
endif
" }
" Tabularize 格式化工具 {
" 格式化工具 godlygeek/tabular
if isdirectory(expand("~/.vim/bundle/tabular"))
nmap <Leader>a& :Tabularize /&<CR>
vmap <Leader>a& :Tabularize /&<CR>
nmap <Leader>a= :Tabularize /^[^=]*\zs=<CR>
vmap <Leader>a= :Tabularize /^[^=]*\zs=<CR>
nmap <Leader>a=> :Tabularize /=><CR>
vmap <Leader>a=> :Tabularize /=><CR>
nmap <Leader>a: :Tabularize /:<CR>
vmap <Leader>a: :Tabularize /:<CR>
nmap <Leader>a:: :Tabularize /:\zs<CR>
vmap <Leader>a:: :Tabularize /:\zs<CR>
nmap <Leader>a, :Tabularize /,<CR>
vmap <Leader>a, :Tabularize /,<CR>
nmap <Leader>a,, :Tabularize /,\zs<CR>
vmap <Leader>a,, :Tabularize /,\zs<CR>
nmap <Leader>a<Bar> :Tabularize /<Bar><CR>
vmap <Leader>a<Bar> :Tabularize /<Bar><CR>
endif
" }
" Session List 编辑场景工具{
set sessionoptions=blank,buffers,curdir,folds,tabpages,winsize
if isdirectory(expand("~/.vim/bundle/sessionman.vim/"))
nmap <leader>sl :SessionList<CR>
nmap <leader>ss :SessionSave<CR>
nmap <leader>sc :SessionClose<CR>
endif
" }
" Pythond 模式 {
" Pythond 模式
" 禁用该问题,如果不支持python的话
if !has('python') && !has('python3')
let g:pymode = 0
endif
"if isdirectory(expand("~/.vim/bundle/python-mode"))
"let g:pymode_lint_checkers = ['pyflakes']
"let g:pymode_trim_whitespaces = 0
"let g:pymode_options = 0
"let g:pymode_rope = 0
"endif
" }
" TagBar 标签栏工具 {
if isdirectory(expand("~/.vim/bundle/tagbar/"))
nnoremap <silent> <leader>tt :TagbarToggle<CR>
endif
"}
" Rainbow 括号配色方案 {
" 通过以不同的颜色展示不同层次的括号,致力于帮助阅读复杂代码。
if isdirectory(expand("~/.vim/bundle/rainbow/"))
let g:rainbow_active = 1 "0: 不会即时生效,可以调用 :RainbowToggle 使其生效
endif
"}
" neocomplete 自动补全工具 {
let g:acp_enableAtStartup = 0
let g:neocomplete#enable_at_startup = 1
let g:neocomplete#enable_smart_case = 1
let g:neocomplete#enable_auto_delimiter = 1
let g:neocomplete#max_list = 15
let g:neocomplete#force_overwrite_completefunc = 1
" 按键映射 {
" <TAB>: 补全
inoremap <expr><TAB> pumvisible() ? "\" : "\"
inoremap <expr><S-TAB> pumvisible() ? "\" : "\"
function! CleverTab()
if pumvisible()
return "\"
endif
let substr = strpart(getline('.'), 0, col('.') - 1)
let substr = matchstr(substr, '[^ \t]*$')
if strlen(substr) == 0
" 空字符串不匹配
return "\"
else
" 存在的文本匹配
if neosnippet#expandable_or_jumpable()
return "\(neosnippet_expand_or_jump)"
else
return neocomplete#start_manual_complete()
endif
endif
endfunction
imap <expr> <Tab> CleverTab()
" }
" 启用全方位的 omni 补全
if !exists('g:neocomplete#sources#omni#input_patterns')
let g:neocomplete#sources#omni#input_patterns = {}
endif
let g:neocomplete#sources#omni#input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
let g:neocomplete#sources#omni#input_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'
" }
" UndoTree 撤销树工具 {
if isdirectory(expand("~/.vim/bundle/undotree/"))
nnoremap <Leader>u :UndotreeToggle<CR>
" 启用 undotree 与其进行交互
let g:undotree_SetFocusWhenToggle=1
endif
" }
" vim-airline 工具 {
"当运行宏时,不重绘
set lazyredraw
"打开tabline功能,方便查看Buffer和切换,省去了minibufexpl插件
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
"设置切换Buffer快捷键"
nnoremap <C-G> :bn<CR>
nnoremap <C-B> :bp<CR>
if isdirectory(expand("~/.vim/bundle/vim-airline-themes/"))
if !exists('g:airline_theme')
"let g:airline_theme="solarized"
let g:airline_theme="base16_solarized"
endif
endif
" }
" }
" 自定义的一些方法 {
" F9 获取当前编辑文件的路径 {
" 一键获取当前编辑文件绝对路径
function GetCurFilePath()
let cur_dir = getcwd()
let cur_file_name = getreg('%')
let cur_dir_file_name = cur_dir . '/' . cur_file_name
call setreg("+", cur_dir_file_name)
endfunction
nnoremap <silent> <F9> : call GetCurFilePath()<cr>
" }
" Strip whitespace {
function! StripTrailingWhitespace()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" do the business:
%s/\s\+$
" clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
" }
" }