课程表

vim 命令手册

Vimscript 编程参考

工具箱
速查手册

Vim配置.vimrc方案2

当前位置:免费教程 » 软件/图像 » Vim
  1. " Modeline and Notes {
  2. " vim: set sw=4 ts=4 sts=4 et tw=78 foldmarker={,} foldlevel=0 foldmethod=marker spell:
  3. "
  4. " __ _ _____ _
  5. " ___ _ __ / _/ |___ / __ __(_)_ __ ___
  6. " / __| '_ \| |_| | |_ \ _____\ \ / /| | '_ ` _ " \__ \ |_) | _| |___) |_____|\ V / | | | | | | |
  7. " |___/ .__/|_| |_|____/ \_/ |_|_| |_| |_|
  8. " |_|
  9. "
  10. " This is the personal .vimrc file of Steve Francia.
  11. " While much of it is beneficial for general use, I would
  12. " recommend picking out the parts you want and understand.
  13. "
  14. " You can find me at http://spf13.com
  15. "
  16. " Copyright 2014 Steve Francia
  17. "
  18. " Licensed under the Apache License, Version 2.0 (the "License");
  19. " you may not use this file except in compliance with the License.
  20. " You may obtain a copy of the License at
  21. "
  22. " http://www.apache.org/licenses/LICENSE-2.0
  23. "
  24. " Unless required by applicable law or agreed to in writing, software
  25. " distributed under the License is distributed on an "AS IS" BASIS,
  26. " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  27. " See the License for the specific language governing permissions and
  28. " limitations under the License.
  29. " }
  30. " Environment {
  31. " Identify platform {
  32. silent function! OSX()
  33. return has('macunix')
  34. endfunction
  35. silent function! LINUX()
  36. return has('unix') && !has('macunix') && !has('win32unix')
  37. endfunction
  38. silent function! WINDOWS()
  39. return (has('win32') || has('win64'))
  40. endfunction
  41. " }
  42. " Basics {
  43. set nocompatible " Must be first line
  44. if !WINDOWS()
  45. set shell=/bin/sh
  46. endif
  47. " }
  48. " Windows Compatible {
  49. " On Windows, also use '.vim' instead of 'vimfiles'; this makes synchronization
  50. " across (heterogeneous) systems easier.
  51. if WINDOWS()
  52. set runtimepath=$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after
  53. endif
  54. " }
  55. " Arrow Key Fix {
  56. " https://github.com/spf13/spf13-vim/issues/780
  57. if &term[:4] == "xterm" || &term[:5] == 'screen' || &term[:3] == 'rxvt'
  58. inoremap <silent> <C-[>OC <RIGHT>
  59. endif
  60. " }
  61. " }
  62. " Use before config if available {
  63. if filereadable(expand("~/.vimrc.before"))
  64. source ~/.vimrc.before
  65. endif
  66. " }
  67. " Use bundles config {
  68. if filereadable(expand("~/.vimrc.bundles"))
  69. source ~/.vimrc.bundles
  70. endif
  71. " }
  72. " General {
  73. set background=dark " Assume a dark background
  74. " Allow to trigger background
  75. function! ToggleBG()
  76. let s:tbg = &background
  77. " Inversion
  78. if s:tbg == "dark"
  79. set background=light
  80. else
  81. set background=dark
  82. endif
  83. endfunction
  84. noremap <leader>bg :call ToggleBG()<CR>
  85. " if !has('gui')
  86. "set term=$TERM " Make arrow and other keys work
  87. " endif
  88. filetype plugin indent on " Automatically detect file types.
  89. syntax on " Syntax highlighting
  90. set mouse=a " Automatically enable mouse usage
  91. set mousehide " Hide the mouse cursor while typing
  92. scriptencoding utf-8
  93. if has('clipboard')
  94. if has('unnamedplus') " When possible use + register for copy-paste
  95. set clipboard=unnamed,unnamedplus
  96. else " On mac and Windows, use * register for copy-paste
  97. set clipboard=unnamed
  98. endif
  99. endif
  100. " Most prefer to automatically switch to the current file directory when
  101. " a new buffer is opened; to prevent this behavior, add the following to
  102. " your .vimrc.before.local file:
  103. " let g:spf13_no_autochdir = 1
  104. if !exists('g:spf13_no_autochdir')
  105. autocmd BufEnter * if bufname("") !~ "^\[A-Za-z0-9\]*://" | lcd %:p:h | endif
  106. " Always switch to the current file directory
  107. endif
  108. "set autowrite " Automatically write a file when leaving a modified buffer
  109. set shortmess+=filmnrxoOtT " Abbrev. of messages (avoids 'hit enter')
  110. set viewoptions=folds,options,cursor,unix,slash " Better Unix / Windows compatibility
  111. set virtualedit=onemore " Allow for cursor beyond last character
  112. set history=1000 " Store a ton of history (default is 20)
  113. set spell " Spell checking on
  114. set hidden " Allow buffer switching without saving
  115. set iskeyword-=. " '.' is an end of word designator
  116. set iskeyword-=# " '#' is an end of word designator
  117. set iskeyword-=- " '-' is an end of word designator
  118. " Instead of reverting the cursor to the last position in the buffer, we
  119. " set it to the first line when editing a git commit message
  120. au FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0])
  121. " http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session
  122. " Restore cursor to file position in previous editing session
  123. " To disable this, add the following to your .vimrc.before.local file:
  124. " let g:spf13_no_restore_cursor = 1
  125. if !exists('g:spf13_no_restore_cursor')
  126. function! ResCur()
  127. if line("'\"") <= line("$")
  128. silent! normal! g`"
  129. return 1
  130. endif
  131. endfunction
  132. augroup resCur
  133. autocmd!
  134. autocmd BufWinEnter * call ResCur()
  135. augroup END
  136. endif
  137. " Setting up the directories {
  138. set backup " Backups are nice ...
  139. if has('persistent_undo')
  140. set undofile " So is persistent undo ...
  141. set undolevels=1000 " Maximum number of changes that can be undone
  142. set undoreload=10000 " Maximum number lines to save for undo on a buffer reload
  143. endif
  144. " To disable views add the following to your .vimrc.before.local file:
  145. " let g:spf13_no_views = 1
  146. if !exists('g:spf13_no_views')
  147. " Add exclusions to mkview and loadview
  148. " eg: *.*, svn-commit.tmp
  149. let g:skipview_files = [
  150. \ '\[example pattern\]'
  151. \ ]
  152. endif
  153. " }
  154. " }
  155. " Vim UI {
  156. if !exists('g:override_spf13_bundles') && filereadable(expand("~/.vim/bundle/vim-colors-solarized/colors/solarized.vim"))
  157. let g:solarized_termcolors=256
  158. let g:solarized_termtrans=1
  159. let g:solarized_contrast="normal"
  160. let g:solarized_visibility="normal"
  161. color solarized " Load a colorscheme
  162. endif
  163. set tabpagemax=15 " Only show 15 tabs
  164. set showmode " Display the current mode
  165. set cursorline " Highlight current line
  166. highlight clear SignColumn " SignColumn should match background
  167. highlight clear LineNr " Current line number row will have same background color in relative mode
  168. "highlight clear CursorLineNr " Remove highlight color from current line number
  169. if has('cmdline_info')
  170. set ruler " Show the ruler
  171. set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%) " A ruler on steroids
  172. set showcmd " Show partial commands in status line and
  173. " Selected characters/lines in visual mode
  174. endif
  175. if has('statusline')
  176. set laststatus=2
  177. " Broken down into easily includeable segments
  178. set statusline=%<%f\ " Filename
  179. set statusline+=%w%h%m%r " Options
  180. if !exists('g:override_spf13_bundles')
  181. set statusline+=%{fugitive#statusline()} " Git Hotness
  182. endif
  183. set statusline+=\ [%{&ff}/%Y] " Filetype
  184. set statusline+=\ [%{getcwd()}] " Current dir
  185. set statusline+=%=%-14.(%l,%c%V%)\ %p%% " Right aligned file nav info
  186. endif
  187. set backspace=indent,eol,start " Backspace for dummies
  188. set linespace=0 " No extra spaces between rows
  189. set number " Line numbers on
  190. set showmatch " Show matching brackets/parenthesis
  191. set incsearch " Find as you type search
  192. set hlsearch " Highlight search terms
  193. set winminheight=0 " Windows can be 0 line high
  194. set ignorecase " Case insensitive search
  195. set smartcase " Case sensitive when uc present
  196. set wildmenu " Show list instead of just completing
  197. set wildmode=list:longest,full " Command <Tab> completion, list matches, then longest common part, then all.
  198. set whichwrap=b,s,h,l,<,>,[,] " Backspace and cursor keys wrap too
  199. set scrolljump=5 " Lines to scroll when cursor leaves screen
  200. set scrolloff=3 " Minimum lines to keep above and below cursor
  201. set foldenable " Auto fold code
  202. set list
  203. set listchars=tab:›\ ,trail:•,extends:#,nbsp:. " Highlight problematic whitespace
  204. " }
  205. " Formatting {
  206. set nowrap " Do not wrap long lines
  207. set autoindent " Indent at the same level of the previous line
  208. set shiftwidth=4 " Use indents of 4 spaces
  209. set expandtab " Tabs are spaces, not tabs
  210. set tabstop=4 " An indentation every four columns
  211. set softtabstop=4 " Let backspace delete indent
  212. set nojoinspaces " Prevents inserting two spaces after punctuation on a join (J)
  213. set splitright " Puts new vsplit windows to the right of the current
  214. set splitbelow " Puts new split windows to the bottom of the current
  215. "set matchpairs+=<:> " Match, to be used with %
  216. set pastetoggle=<F12> " pastetoggle (sane indentation on pastes)
  217. "set comments=sl:/*,mb:*,elx:*/ " auto format comment blocks
  218. " Remove trailing whitespaces and ^M chars
  219. " To disable the stripping of whitespace, add the following to your
  220. " .vimrc.before.local file:
  221. " let g:spf13_keep_trailing_whitespace = 1
  222. autocmd FileType c,cpp,java,go,php,javascript,puppet,python,rust,twig,xml,yml,perl,sql autocmd BufWritePre <buffer> if !exists('g:spf13_keep_trailing_whitespace') | call StripTrailingWhitespace() | endif
  223. "autocmd FileType go autocmd BufWritePre <buffer> Fmt
  224. autocmd BufNewFile,BufRead *.html.twig set filetype=html.twig
  225. autocmd FileType haskell,puppet,ruby,yml setlocal expandtab shiftwidth=2 softtabstop=2
  226. " preceding line best in a plugin but here for now.
  227. autocmd BufNewFile,BufRead *.coffee set filetype=coffee
  228. " Workaround vim-commentary for Haskell
  229. autocmd FileType haskell setlocal commentstring=--\ %s
  230. " Workaround broken colour highlighting in Haskell
  231. autocmd FileType haskell,rust setlocal nospell
  232. " }
  233. " Key (re)Mappings {
  234. " The default leader is '\', but many people prefer ',' as it's in a standard
  235. " location. To override this behavior and set it back to '\' (or any other
  236. " character) add the following to your .vimrc.before.local file:
  237. " let g:spf13_leader='\'
  238. if !exists('g:spf13_leader')
  239. let mapleader = ','
  240. else
  241. let mapleader=g:spf13_leader
  242. endif
  243. if !exists('g:spf13_localleader')
  244. let maplocalleader = '_'
  245. else
  246. let maplocalleader=g:spf13_localleader
  247. endif
  248. " The default mappings for editing and applying the spf13 configuration
  249. " are <leader>ev and <leader>sv respectively. Change them to your preference
  250. " by adding the following to your .vimrc.before.local file:
  251. " let g:spf13_edit_config_mapping='<leader>ec'
  252. " let g:spf13_apply_config_mapping='<leader>sc'
  253. if !exists('g:spf13_edit_config_mapping')
  254. let s:spf13_edit_config_mapping = '<leader>ev'
  255. else
  256. let s:spf13_edit_config_mapping = g:spf13_edit_config_mapping
  257. endif
  258. if !exists('g:spf13_apply_config_mapping')
  259. let s:spf13_apply_config_mapping = '<leader>sv'
  260. else
  261. let s:spf13_apply_config_mapping = g:spf13_apply_config_mapping
  262. endif
  263. " Easier moving in tabs and windows
  264. " The lines conflict with the default digraph mapping of <C-K>
  265. " If you prefer that functionality, add the following to your
  266. " .vimrc.before.local file:
  267. " let g:spf13_no_easyWindows = 1
  268. if !exists('g:spf13_no_easyWindows')
  269. map <C-J> <C-W>j<C-W>_
  270. map <C-K> <C-W>k<C-W>_
  271. map <C-L> <C-W>l<C-W>_
  272. map <C-H> <C-W>h<C-W>_
  273. endif
  274. " Wrapped lines goes down/up to next row, rather than next line in file.
  275. noremap j gj
  276. noremap k gk
  277. " End/Start of line motion keys act relative to row/wrap width in the
  278. " presence of `:set wrap`, and relative to line for `:set nowrap`.
  279. " Default vim behaviour is to act relative to text line in both cases
  280. " If you prefer the default behaviour, add the following to your
  281. " .vimrc.before.local file:
  282. " let g:spf13_no_wrapRelMotion = 1
  283. if !exists('g:spf13_no_wrapRelMotion')
  284. " Same for 0, home, end, etc
  285. function! WrapRelativeMotion(key, ...)
  286. let vis_sel=""
  287. if a:0
  288. let vis_sel="gv"
  289. endif
  290. if &wrap
  291. execute "normal!" vis_sel . "g" . a:key
  292. else
  293. execute "normal!" vis_sel . a:key
  294. endif
  295. endfunction
  296. " Map g* keys in Normal, Operator-pending, and Visual+select
  297. noremap $ :call WrapRelativeMotion("$")<CR>
  298. noremap <End> :call WrapRelativeMotion("$")<CR>
  299. noremap 0 :call WrapRelativeMotion("0")<CR>
  300. noremap <Home> :call WrapRelativeMotion("0")<CR>
  301. noremap ^ :call WrapRelativeMotion("^")<CR>
  302. " Overwrite the operator pending $/<End> mappings from above
  303. " to force inclusive motion with :execute normal!
  304. onoremap $ v:call WrapRelativeMotion("$")<CR>
  305. onoremap <End> v:call WrapRelativeMotion("$")<CR>
  306. " Overwrite the Visual+select mode mappings from above
  307. " to ensure the correct vis_sel flag is passed to function
  308. vnoremap $ :<C-U>call WrapRelativeMotion("$", 1)<CR>
  309. vnoremap <End> :<C-U>call WrapRelativeMotion("$", 1)<CR>
  310. vnoremap 0 :<C-U>call WrapRelativeMotion("0", 1)<CR>
  311. vnoremap <Home> :<C-U>call WrapRelativeMotion("0", 1)<CR>
  312. vnoremap ^ :<C-U>call WrapRelativeMotion("^", 1)<CR>
  313. endif
  314. " The following two lines conflict with moving to top and
  315. " bottom of the screen
  316. " If you prefer that functionality, add the following to your
  317. " .vimrc.before.local file:
  318. " let g:spf13_no_fastTabs = 1
  319. if !exists('g:spf13_no_fastTabs')
  320. map <S-H> gT
  321. map <S-L> gt
  322. endif
  323. " Stupid shift key fixes
  324. if !exists('g:spf13_no_keyfixes')
  325. if has("user_commands")
  326. command! -bang -nargs=* -complete=file E e<bang> <args>
  327. command! -bang -nargs=* -complete=file W w<bang> <args>
  328. command! -bang -nargs=* -complete=file Wq wq<bang> <args>
  329. command! -bang -nargs=* -complete=file WQ wq<bang> <args>
  330. command! -bang Wa wa<bang>
  331. command! -bang WA wa<bang>
  332. command! -bang Q q<bang>
  333. command! -bang QA qa<bang>
  334. command! -bang Qa qa<bang>
  335. endif
  336. cmap Tabe tabe
  337. endif
  338. " Yank from the cursor to the end of the line, to be consistent with C and D.
  339. nnoremap Y y$
  340. " Code folding options
  341. nmap <leader>f0 :set foldlevel=0<CR>
  342. nmap <leader>f1 :set foldlevel=1<CR>
  343. nmap <leader>f2 :set foldlevel=2<CR>
  344. nmap <leader>f3 :set foldlevel=3<CR>
  345. nmap <leader>f4 :set foldlevel=4<CR>
  346. nmap <leader>f5 :set foldlevel=5<CR>
  347. nmap <leader>f6 :set foldlevel=6<CR>
  348. nmap <leader>f7 :set foldlevel=7<CR>
  349. nmap <leader>f8 :set foldlevel=8<CR>
  350. nmap <leader>f9 :set foldlevel=9<CR>
  351. " Most prefer to toggle search highlighting rather than clear the current
  352. " search results. To clear search highlighting rather than toggle it on
  353. " and off, add the following to your .vimrc.before.local file:
  354. " let g:spf13_clear_search_highlight = 1
  355. if exists('g:spf13_clear_search_highlight')
  356. nmap <silent> <leader>/ :nohlsearch<CR>
  357. else
  358. nmap <silent> <leader>/ :set invhlsearch<CR>
  359. endif
  360. " Find merge conflict markers
  361. map <leader>fc /\v^[<\|=>]{7}( .*\|$)<CR>
  362. " Shortcuts
  363. " Change Working Directory to that of the current file
  364. cmap cwd lcd %:p:h
  365. cmap cd. lcd %:p:h
  366. " Visual shifting (does not exit Visual mode)
  367. vnoremap < <gv
  368. vnoremap > >gv
  369. " Allow using the repeat operator with a visual selection (!)
  370. " http://stackoverflow.com/a/8064607/127816
  371. vnoremap . :normal .<CR>
  372. " For when you forget to sudo.. Really Write the file.
  373. cmap w!! w !sudo tee % >/dev/null
  374. " Some helpers to edit mode
  375. " http://vimcasts.org/e/14
  376. cnoremap %% <C-R>=fnameescape(expand('%:h')).'/'<cr>
  377. map <leader>ew :e %%
  378. map <leader>es :sp %%
  379. map <leader>ev :vsp %%
  380. map <leader>et :tabe %%
  381. " Adjust viewports to the same size
  382. map <Leader>= <C-w>=
  383. " Map <Leader>ff to display all lines with keyword under cursor
  384. " and ask which one to jump to
  385. nmap <Leader>ff [I:let nr = input("Which one: ")<Bar>exe "normal " . nr ."[\t"<CR>
  386. " Easier horizontal scrolling
  387. map zl zL
  388. map zh zH
  389. " Easier formatting
  390. nnoremap <silent> <leader>q gwip
  391. " FIXME: Revert this f70be548
  392. " fullscreen mode for GVIM and Terminal, need 'wmctrl' in you PATH
  393. map <silent> <F11> :call system("wmctrl -ir " . v:windowid . " -b toggle,fullscreen")<CR>
  394. " }
  395. " Plugins {
  396. " GoLang {
  397. if count(g:spf13_bundle_groups, 'go')
  398. let g:go_highlight_functions = 1
  399. let g:go_highlight_methods = 1
  400. let g:go_highlight_structs = 1
  401. let g:go_highlight_operators = 1
  402. let g:go_highlight_build_constraints = 1
  403. let g:go_fmt_command = "goimports"
  404. let g:syntastic_go_checkers = ['golint', 'govet', 'errcheck']
  405. let g:syntastic_mode_map = { 'mode': 'active', 'passive_filetypes': ['go'] }
  406. au FileType go nmap <Leader>s <Plug>(go-implements)
  407. au FileType go nmap <Leader>i <Plug>(go-info)
  408. au FileType go nmap <Leader>e <Plug>(go-rename)
  409. au FileType go nmap <leader>r <Plug>(go-run)
  410. au FileType go nmap <leader>b <Plug>(go-build)
  411. au FileType go nmap <leader>t <Plug>(go-test)
  412. au FileType go nmap <Leader>gd <Plug>(go-doc)
  413. au FileType go nmap <Leader>gv <Plug>(go-doc-vertical)
  414. au FileType go nmap <leader>co <Plug>(go-coverage)
  415. endif
  416. " }
  417. " TextObj Sentence {
  418. if count(g:spf13_bundle_groups, 'writing')
  419. augroup textobj_sentence
  420. autocmd!
  421. autocmd FileType markdown call textobj#sentence#init()
  422. autocmd FileType textile call textobj#sentence#init()
  423. autocmd FileType text call textobj#sentence#init()
  424. augroup END
  425. endif
  426. " }
  427. " TextObj Quote {
  428. if count(g:spf13_bundle_groups, 'writing')
  429. augroup textobj_quote
  430. autocmd!
  431. autocmd FileType markdown call textobj#quote#init()
  432. autocmd FileType textile call textobj#quote#init()
  433. autocmd FileType text call textobj#quote#init({'educate': 0})
  434. augroup END
  435. endif
  436. " }
  437. " PIV {
  438. if isdirectory(expand("~/.vim/bundle/PIV"))
  439. let g:DisableAutoPHPFolding = 0
  440. let g:PIVAutoClose = 0
  441. endif
  442. " }
  443. " Misc {
  444. if isdirectory(expand("~/.vim/bundle/nerdtree"))
  445. let g:NERDShutUp=1
  446. endif
  447. if isdirectory(expand("~/.vim/bundle/matchit.zip"))
  448. let b:match_ignorecase = 1
  449. endif
  450. " }
  451. " OmniComplete {
  452. " To disable omni complete, add the following to your .vimrc.before.local file:
  453. " let g:spf13_no_omni_complete = 1
  454. if !exists('g:spf13_no_omni_complete')
  455. if has("autocmd") && exists("+omnifunc")
  456. autocmd Filetype *
  457. \if &omnifunc == "" |
  458. \setlocal omnifunc=syntaxcomplete#Complete |
  459. \endif
  460. endif
  461. hi Pmenu guifg=#000000 guibg=#F8F8F8 ctermfg=black ctermbg=Lightgray
  462. hi PmenuSbar guifg=#8A95A7 guibg=#F8F8F8 gui=NONE ctermfg=darkcyan ctermbg=lightgray cterm=NONE
  463. hi PmenuThumb guifg=#F8F8F8 guibg=#8A95A7 gui=NONE ctermfg=lightgray ctermbg=darkcyan cterm=NONE
  464. " Some convenient mappings
  465. "inoremap <expr> <Esc> pumvisible() ? "\<C-e>" : "\<Esc>"
  466. if exists('g:spf13_map_cr_omni_complete')
  467. inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
  468. endif
  469. inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>"
  470. inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>"
  471. inoremap <expr> <C-d> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<C-d>"
  472. inoremap <expr> <C-u> pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<C-u>"
  473. " Automatically open and close the popup menu / preview window
  474. au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
  475. set completeopt=menu,preview,longest
  476. endif
  477. " }
  478. " Ctags {
  479. set tags=./tags;/,~/.vimtags
  480. " Make tags placed in .git/tags file available in all levels of a repository
  481. let gitroot = substitute(system('git rev-parse --show-toplevel'), '[\n\r]', '', 'g')
  482. if gitroot != ''
  483. let &tags = &tags . ',' . gitroot . '/.git/tags'
  484. endif
  485. " }
  486. " AutoCloseTag {
  487. " Make it so AutoCloseTag works for xml and xhtml files as well
  488. au FileType xhtml,xml ru ftplugin/html/autoclosetag.vim
  489. nmap <Leader>ac <Plug>ToggleAutoCloseMappings
  490. " }
  491. " SnipMate {
  492. " Setting the author var
  493. " If forking, please overwrite in your .vimrc.local file
  494. let g:snips_author = 'Steve Francia <steve.francia@gmail.com>'
  495. " }
  496. " NerdTree {
  497. if isdirectory(expand("~/.vim/bundle/nerdtree"))
  498. map <C-e> <plug>NERDTreeTabsToggle<CR>
  499. map <leader>e :NERDTreeFind<CR>
  500. nmap <leader>nt :NERDTreeFind<CR>
  501. let NERDTreeShowBookmarks=1
  502. let NERDTreeIgnore=['\.py[cd]$', '\~$', '\.swo$', '\.swp$', '^\.git$', '^\.hg$', '^\.svn$', '\.bzr$']
  503. let NERDTreeChDirMode=0
  504. let NERDTreeQuitOnOpen=1
  505. let NERDTreeMouseMode=2
  506. let NERDTreeShowHidden=1
  507. let NERDTreeKeepTreeInNewTab=1
  508. let g:nerdtree_tabs_open_on_gui_startup=0
  509. endif
  510. " }
  511. " Tabularize {
  512. if isdirectory(expand("~/.vim/bundle/tabular"))
  513. nmap <Leader>a& :Tabularize /&<CR>
  514. vmap <Leader>a& :Tabularize /&<CR>
  515. nmap <Leader>a= :Tabularize /^[^=]*\zs=<CR>
  516. vmap <Leader>a= :Tabularize /^[^=]*\zs=<CR>
  517. nmap <Leader>a=> :Tabularize /=><CR>
  518. vmap <Leader>a=> :Tabularize /=><CR>
  519. nmap <Leader>a: :Tabularize /:<CR>
  520. vmap <Leader>a: :Tabularize /:<CR>
  521. nmap <Leader>a:: :Tabularize /:\zs<CR>
  522. vmap <Leader>a:: :Tabularize /:\zs<CR>
  523. nmap <Leader>a, :Tabularize /,<CR>
  524. vmap <Leader>a, :Tabularize /,<CR>
  525. nmap <Leader>a,, :Tabularize /,\zs<CR>
  526. vmap <Leader>a,, :Tabularize /,\zs<CR>
  527. nmap <Leader>a<Bar> :Tabularize /<Bar><CR>
  528. vmap <Leader>a<Bar> :Tabularize /<Bar><CR>
  529. endif
  530. " }
  531. " Session List {
  532. set sessionoptions=blank,buffers,curdir,folds,tabpages,winsize
  533. if isdirectory(expand("~/.vim/bundle/sessionman.vim/"))
  534. nmap <leader>sl :SessionList<CR>
  535. nmap <leader>ss :SessionSave<CR>
  536. nmap <leader>sc :SessionClose<CR>
  537. endif
  538. " }
  539. " JSON {
  540. nmap <leader>jt <Esc>:%!python -m json.tool<CR><Esc>:set filetype=json<CR>
  541. let g:vim_json_syntax_conceal = 0
  542. " }
  543. " PyMode {
  544. " Disable if python support not present
  545. if !has('python') && !has('python3')
  546. let g:pymode = 0
  547. endif
  548. if isdirectory(expand("~/.vim/bundle/python-mode"))
  549. let g:pymode_lint_checkers = ['pyflakes']
  550. let g:pymode_trim_whitespaces = 0
  551. let g:pymode_options = 0
  552. let g:pymode_rope = 0
  553. endif
  554. " }
  555. " ctrlp {
  556. if isdirectory(expand("~/.vim/bundle/ctrlp.vim/"))
  557. let g:ctrlp_working_path_mode = 'ra'
  558. nnoremap <silent> <D-t> :CtrlP<CR>
  559. nnoremap <silent> <D-r> :CtrlPMRU<CR>
  560. let g:ctrlp_custom_ignore = {
  561. \ 'dir': '\.git$\|\.hg$\|\.svn$',
  562. \ 'file': '\.exe$\|\.so$\|\.dll$\|\.pyc$' }
  563. if executable('ag')
  564. let s:ctrlp_fallback = 'ag %s --nocolor -l -g ""'
  565. elseif executable('ack-grep')
  566. let s:ctrlp_fallback = 'ack-grep %s --nocolor -f'
  567. elseif executable('ack')
  568. let s:ctrlp_fallback = 'ack %s --nocolor -f'
  569. " On Windows use "dir" as fallback command.
  570. elseif WINDOWS()
  571. let s:ctrlp_fallback = 'dir %s /-n /b /s /a-d'
  572. else
  573. let s:ctrlp_fallback = 'find %s -type f'
  574. endif
  575. if exists("g:ctrlp_user_command")
  576. unlet g:ctrlp_user_command
  577. endif
  578. let g:ctrlp_user_command = {
  579. \ 'types': {
  580. \ 1: ['.git', 'cd %s && git ls-files . --cached --exclude-standard --others'],
  581. \ 2: ['.hg', 'hg --cwd %s locate -I .'],
  582. \ },
  583. \ 'fallback': s:ctrlp_fallback
  584. \ }
  585. if isdirectory(expand("~/.vim/bundle/ctrlp-funky/"))
  586. " CtrlP extensions
  587. let g:ctrlp_extensions = ['funky']
  588. "funky
  589. nnoremap <Leader>fu :CtrlPFunky<Cr>
  590. endif
  591. endif
  592. "}
  593. " TagBar {
  594. if isdirectory(expand("~/.vim/bundle/tagbar/"))
  595. nnoremap <silent> <leader>tt :TagbarToggle<CR>
  596. endif
  597. "}
  598. " Rainbow {
  599. if isdirectory(expand("~/.vim/bundle/rainbow/"))
  600. let g:rainbow_active = 1 "0 if you want to enable it later via :RainbowToggle
  601. endif
  602. "}
  603. " Fugitive {
  604. if isdirectory(expand("~/.vim/bundle/vim-fugitive/"))
  605. nnoremap <silent> <leader>gs :Gstatus<CR>
  606. nnoremap <silent> <leader>gd :Gdiff<CR>
  607. nnoremap <silent> <leader>gc :Gcommit<CR>
  608. nnoremap <silent> <leader>gb :Gblame<CR>
  609. nnoremap <silent> <leader>gl :Glog<CR>
  610. nnoremap <silent> <leader>gp :Git push<CR>
  611. nnoremap <silent> <leader>gr :Gread<CR>
  612. nnoremap <silent> <leader>gw :Gwrite<CR>
  613. nnoremap <silent> <leader>ge :Gedit<CR>
  614. " Mnemonic _i_nteractive
  615. nnoremap <silent> <leader>gi :Git add -p %<CR>
  616. nnoremap <silent> <leader>gg :SignifyToggle<CR>
  617. endif
  618. "}
  619. " YouCompleteMe {
  620. if count(g:spf13_bundle_groups, 'youcompleteme')
  621. let g:acp_enableAtStartup = 0
  622. " enable completion from tags
  623. let g:ycm_collect_identifiers_from_tags_files = 1
  624. " remap Ultisnips for compatibility for YCM
  625. let g:UltiSnipsExpandTrigger = '<C-j>'
  626. let g:UltiSnipsJumpForwardTrigger = '<C-j>'
  627. let g:UltiSnipsJumpBackwardTrigger = '<C-k>'
  628. " Enable omni completion.
  629. autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
  630. autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
  631. autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
  632. autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
  633. autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
  634. autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete
  635. autocmd FileType haskell setlocal omnifunc=necoghc#omnifunc
  636. " Haskell post write lint and check with ghcmod
  637. " $ `cabal install ghcmod` if missing and ensure
  638. " ~/.cabal/bin is in your $PATH.
  639. if !executable("ghcmod")
  640. autocmd BufWritePost *.hs GhcModCheckAndLintAsync
  641. endif
  642. " For snippet_complete marker.
  643. if !exists("g:spf13_no_conceal")
  644. if has('conceal')
  645. set conceallevel=2 concealcursor=i
  646. endif
  647. endif
  648. " Disable the neosnippet preview candidate window
  649. " When enabled, there can be too much visual noise
  650. " especially when splits are used.
  651. set completeopt-=preview
  652. endif
  653. " }
  654. " neocomplete {
  655. if count(g:spf13_bundle_groups, 'neocomplete')
  656. let g:acp_enableAtStartup = 0
  657. let g:neocomplete#enable_at_startup = 1
  658. let g:neocomplete#enable_smart_case = 1
  659. let g:neocomplete#enable_auto_delimiter = 1
  660. let g:neocomplete#max_list = 15
  661. let g:neocomplete#force_overwrite_completefunc = 1
  662. " Define dictionary.
  663. let g:neocomplete#sources#dictionary#dictionaries = {
  664. \ 'default' : '',
  665. \ 'vimshell' : $HOME.'/.vimshell_hist',
  666. \ 'scheme' : $HOME.'/.gosh_completions'
  667. \ }
  668. " Define keyword.
  669. if !exists('g:neocomplete#keyword_patterns')
  670. let g:neocomplete#keyword_patterns = {}
  671. endif
  672. let g:neocomplete#keyword_patterns['default'] = '\h\w*'
  673. " Plugin key-mappings {
  674. " These two lines conflict with the default digraph mapping of <C-K>
  675. if !exists('g:spf13_no_neosnippet_expand')
  676. imap <C-k> <Plug>(neosnippet_expand_or_jump)
  677. smap <C-k> <Plug>(neosnippet_expand_or_jump)
  678. endif
  679. if exists('g:spf13_noninvasive_completion')
  680. inoremap <CR> <CR>
  681. " <ESC> takes you out of insert mode
  682. inoremap <expr> <Esc> pumvisible() ? "\<C-y>\<Esc>" : "\<Esc>"
  683. " <CR> accepts first, then sends the <CR>
  684. inoremap <expr> <CR> pumvisible() ? "\<C-y>\<CR>" : "\<CR>"
  685. " <Down> and <Up> cycle like <Tab> and <S-Tab>
  686. inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>"
  687. inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>"
  688. " Jump up and down the list
  689. inoremap <expr> <C-d> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<C-d>"
  690. inoremap <expr> <C-u> pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<C-u>"
  691. else
  692. " <C-k> Complete Snippet
  693. " <C-k> Jump to next snippet point
  694. imap <silent><expr><C-k> neosnippet#expandable() ?
  695. \ "\<Plug>(neosnippet_expand_or_jump)" : (pumvisible() ?
  696. \ "\<C-e>" : "\<Plug>(neosnippet_expand_or_jump)")
  697. smap <TAB> <Right><Plug>(neosnippet_jump_or_expand)
  698. inoremap <expr><C-g> neocomplete#undo_completion()
  699. inoremap <expr><C-l> neocomplete#complete_common_string()
  700. "inoremap <expr><CR> neocomplete#complete_common_string()
  701. " <CR>: close popup
  702. " <s-CR>: close popup and save indent.
  703. inoremap <expr><s-CR> pumvisible() ? neocomplete#smart_close_popup()."\<CR>" : "\<CR>"
  704. function! CleverCr()
  705. if pumvisible()
  706. if neosnippet#expandable()
  707. let exp = "\<Plug>(neosnippet_expand)"
  708. return exp . neocomplete#smart_close_popup()
  709. else
  710. return neocomplete#smart_close_popup()
  711. endif
  712. else
  713. return "\<CR>"
  714. endif
  715. endfunction
  716. " <CR> close popup and save indent or expand snippet
  717. imap <expr> <CR> CleverCr()
  718. " <C-h>, <BS>: close popup and delete backword char.
  719. inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"
  720. inoremap <expr><C-y> neocomplete#smart_close_popup()
  721. endif
  722. " <TAB>: completion.
  723. inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
  724. inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<TAB>"
  725. " Courtesy of Matteo Cavalleri
  726. function! CleverTab()
  727. if pumvisible()
  728. return "\<C-n>"
  729. endif
  730. let substr = strpart(getline('.'), 0, col('.') - 1)
  731. let substr = matchstr(substr, '[^ \t]*$')
  732. if strlen(substr) == 0
  733. " nothing to match on empty string
  734. return "\<Tab>"
  735. else
  736. " existing text matching
  737. if neosnippet#expandable_or_jumpable()
  738. return "\<Plug>(neosnippet_expand_or_jump)"
  739. else
  740. return neocomplete#start_manual_complete()
  741. endif
  742. endif
  743. endfunction
  744. imap <expr> <Tab> CleverTab()
  745. " }
  746. " Enable heavy omni completion.
  747. if !exists('g:neocomplete#sources#omni#input_patterns')
  748. let g:neocomplete#sources#omni#input_patterns = {}
  749. endif
  750. let g:neocomplete#sources#omni#input_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
  751. let g:neocomplete#sources#omni#input_patterns.perl = '\h\w*->\h\w*\|\h\w*::'
  752. let g:neocomplete#sources#omni#input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
  753. let g:neocomplete#sources#omni#input_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'
  754. let g:neocomplete#sources#omni#input_patterns.ruby = '[^. *\t]\.\h\w*\|\h\w*::'
  755. " }
  756. " neocomplcache {
  757. elseif count(g:spf13_bundle_groups, 'neocomplcache')
  758. let g:acp_enableAtStartup = 0
  759. let g:neocomplcache_enable_at_startup = 1
  760. let g:neocomplcache_enable_camel_case_completion = 1
  761. let g:neocomplcache_enable_smart_case = 1
  762. let g:neocomplcache_enable_underbar_completion = 1
  763. let g:neocomplcache_enable_auto_delimiter = 1
  764. let g:neocomplcache_max_list = 15
  765. let g:neocomplcache_force_overwrite_completefunc = 1
  766. " Define dictionary.
  767. let g:neocomplcache_dictionary_filetype_lists = {
  768. \ 'default' : '',
  769. \ 'vimshell' : $HOME.'/.vimshell_hist',
  770. \ 'scheme' : $HOME.'/.gosh_completions'
  771. \ }
  772. " Define keyword.
  773. if !exists('g:neocomplcache_keyword_patterns')
  774. let g:neocomplcache_keyword_patterns = {}
  775. endif
  776. let g:neocomplcache_keyword_patterns._ = '\h\w*'
  777. " Plugin key-mappings {
  778. " These two lines conflict with the default digraph mapping of <C-K>
  779. imap <C-k> <Plug>(neosnippet_expand_or_jump)
  780. smap <C-k> <Plug>(neosnippet_expand_or_jump)
  781. if exists('g:spf13_noninvasive_completion')
  782. inoremap <CR> <CR>
  783. " <ESC> takes you out of insert mode
  784. inoremap <expr> <Esc> pumvisible() ? "\<C-y>\<Esc>" : "\<Esc>"
  785. " <CR> accepts first, then sends the <CR>
  786. inoremap <expr> <CR> pumvisible() ? "\<C-y>\<CR>" : "\<CR>"
  787. " <Down> and <Up> cycle like <Tab> and <S-Tab>
  788. inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>"
  789. inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>"
  790. " Jump up and down the list
  791. inoremap <expr> <C-d> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<C-d>"
  792. inoremap <expr> <C-u> pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<C-u>"
  793. else
  794. imap <silent><expr><C-k> neosnippet#expandable() ?
  795. \ "\<Plug>(neosnippet_expand_or_jump)" : (pumvisible() ?
  796. \ "\<C-e>" : "\<Plug>(neosnippet_expand_or_jump)")
  797. smap <TAB> <Right><Plug>(neosnippet_jump_or_expand)
  798. inoremap <expr><C-g> neocomplcache#undo_completion()
  799. inoremap <expr><C-l> neocomplcache#complete_common_string()
  800. "inoremap <expr><CR> neocomplcache#complete_common_string()
  801. function! CleverCr()
  802. if pumvisible()
  803. if neosnippet#expandable()
  804. let exp = "\<Plug>(neosnippet_expand)"
  805. return exp . neocomplcache#close_popup()
  806. else
  807. return neocomplcache#close_popup()
  808. endif
  809. else
  810. return "\<CR>"
  811. endif
  812. endfunction
  813. " <CR> close popup and save indent or expand snippet
  814. imap <expr> <CR> CleverCr()
  815. " <CR>: close popup
  816. " <s-CR>: close popup and save indent.
  817. inoremap <expr><s-CR> pumvisible() ? neocomplcache#close_popup()."\<CR>" : "\<CR>"
  818. "inoremap <expr><CR> pumvisible() ? neocomplcache#close_popup() : "\<CR>"
  819. " <C-h>, <BS>: close popup and delete backword char.
  820. inoremap <expr><BS> neocomplcache#smart_close_popup()."\<C-h>"
  821. inoremap <expr><C-y> neocomplcache#close_popup()
  822. endif
  823. " <TAB>: completion.
  824. inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
  825. inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<TAB>"
  826. " }
  827. " Enable omni completion.
  828. autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
  829. autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
  830. autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
  831. autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
  832. autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
  833. autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete
  834. autocmd FileType haskell setlocal omnifunc=necoghc#omnifunc
  835. " Enable heavy omni completion.
  836. if !exists('g:neocomplcache_omni_patterns')
  837. let g:neocomplcache_omni_patterns = {}
  838. endif
  839. let g:neocomplcache_omni_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
  840. let g:neocomplcache_omni_patterns.perl = '\h\w*->\h\w*\|\h\w*::'
  841. let g:neocomplcache_omni_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
  842. let g:neocomplcache_omni_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'
  843. let g:neocomplcache_omni_patterns.ruby = '[^. *\t]\.\h\w*\|\h\w*::'
  844. let g:neocomplcache_omni_patterns.go = '\h\w*\.\?'
  845. " }
  846. " Normal Vim omni-completion {
  847. " To disable omni complete, add the following to your .vimrc.before.local file:
  848. " let g:spf13_no_omni_complete = 1
  849. elseif !exists('g:spf13_no_omni_complete')
  850. " Enable omni-completion.
  851. autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
  852. autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
  853. autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
  854. autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
  855. autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
  856. autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete
  857. autocmd FileType haskell setlocal omnifunc=necoghc#omnifunc
  858. endif
  859. " }
  860. " Snippets {
  861. if count(g:spf13_bundle_groups, 'neocomplcache') ||
  862. \ count(g:spf13_bundle_groups, 'neocomplete')
  863. " Use honza's snippets.
  864. let g:neosnippet#snippets_directory='~/.vim/bundle/vim-snippets/snippets'
  865. " Enable neosnippet snipmate compatibility mode
  866. let g:neosnippet#enable_snipmate_compatibility = 1
  867. " For snippet_complete marker.
  868. if !exists("g:spf13_no_conceal")
  869. if has('conceal')
  870. set conceallevel=2 concealcursor=i
  871. endif
  872. endif
  873. " Enable neosnippets when using go
  874. let g:go_snippet_engine = "neosnippet"
  875. " Disable the neosnippet preview candidate window
  876. " When enabled, there can be too much visual noise
  877. " especially when splits are used.
  878. set completeopt-=preview
  879. endif
  880. " }
  881. " FIXME: Isn't this for Syntastic to handle?
  882. " Haskell post write lint and check with ghcmod
  883. " $ `cabal install ghcmod` if missing and ensure
  884. " ~/.cabal/bin is in your $PATH.
  885. if !executable("ghcmod")
  886. autocmd BufWritePost *.hs GhcModCheckAndLintAsync
  887. endif
  888. " UndoTree {
  889. if isdirectory(expand("~/.vim/bundle/undotree/"))
  890. nnoremap <Leader>u :UndotreeToggle<CR>
  891. " If undotree is opened, it is likely one wants to interact with it.
  892. let g:undotree_SetFocusWhenToggle=1
  893. endif
  894. " }
  895. " indent_guides {
  896. if isdirectory(expand("~/.vim/bundle/vim-indent-guides/"))
  897. let g:indent_guides_start_level = 2
  898. let g:indent_guides_guide_size = 1
  899. let g:indent_guides_enable_on_vim_startup = 1
  900. endif
  901. " }
  902. " Wildfire {
  903. let g:wildfire_objects = {
  904. \ "*" : ["i'", 'i"', "i)", "i]", "i}", "ip"],
  905. \ "html,xml" : ["at"],
  906. \ }
  907. " }
  908. " vim-airline {
  909. " Set configuration options for the statusline plugin vim-airline.
  910. " Use the powerline theme and optionally enable powerline symbols.
  911. " To use the symbols , , , , , , and .in the statusline
  912. " segments add the following to your .vimrc.before.local file:
  913. " let g:airline_powerline_fonts=1
  914. " If the previous symbols do not render for you then install a
  915. " powerline enabled font.
  916. " See `:echo g:airline_theme_map` for some more choices
  917. " Default in terminal vim is 'dark'
  918. if isdirectory(expand("~/.vim/bundle/vim-airline-themes/"))
  919. if !exists('g:airline_theme')
  920. let g:airline_theme = 'solarized'
  921. endif
  922. if !exists('g:airline_powerline_fonts')
  923. " Use the default set of separators with a few customizations
  924. let g:airline_left_sep='›' " Slightly fancier than '>'
  925. let g:airline_right_sep='‹' " Slightly fancier than '<'
  926. endif
  927. endif
  928. " }
  929. " }
  930. " GUI Settings {
  931. " GVIM- (here instead of .gvimrc)
  932. if has('gui_running')
  933. set guioptions-=T " Remove the toolbar
  934. set lines=40 " 40 lines of text instead of 24
  935. if !exists("g:spf13_no_big_font")
  936. if LINUX() && has("gui_running")
  937. set guifont=Andale\ Mono\ Regular\ 12,Menlo\ Regular\ 11,Consolas\ Regular\ 12,Courier\ New\ Regular\ 14
  938. elseif OSX() && has("gui_running")
  939. set guifont=Andale\ Mono\ Regular:h12,Menlo\ Regular:h11,Consolas\ Regular:h12,Courier\ New\ Regular:h14
  940. elseif WINDOWS() && has("gui_running")
  941. set guifont=Andale_Mono:h10,Menlo:h10,Consolas:h10,Courier_New:h10
  942. endif
  943. endif
  944. else
  945. if &term == 'xterm' || &term == 'screen'
  946. set t_Co=256 " Enable 256 colors to stop the CSApprox warning and make xterm vim shine
  947. endif
  948. "set term=builtin_ansi " Make arrow and other keys work
  949. endif
  950. " }
  951. " Functions {
  952. " Initialize directories {
  953. function! InitializeDirectories()
  954. let parent = $HOME
  955. let prefix = 'vim'
  956. let dir_list = {
  957. \ 'backup': 'backupdir',
  958. \ 'views': 'viewdir',
  959. \ 'swap': 'directory' }
  960. if has('persistent_undo')
  961. let dir_list['undo'] = 'undodir'
  962. endif
  963. " To specify a different directory in which to place the vimbackup,
  964. " vimviews, vimundo, and vimswap files/directories, add the following to
  965. " your .vimrc.before.local file:
  966. " let g:spf13_consolidated_directory = <full path to desired directory>
  967. " eg: let g:spf13_consolidated_directory = $HOME . '/.vim/'
  968. if exists('g:spf13_consolidated_directory')
  969. let common_dir = g:spf13_consolidated_directory . prefix
  970. else
  971. let common_dir = parent . '/.' . prefix
  972. endif
  973. for [dirname, settingname] in items(dir_list)
  974. let directory = common_dir . dirname . '/'
  975. if exists("*mkdir")
  976. if !isdirectory(directory)
  977. call mkdir(directory)
  978. endif
  979. endif
  980. if !isdirectory(directory)
  981. echo "Warning: Unable to create backup directory: " . directory
  982. echo "Try: mkdir -p " . directory
  983. else
  984. let directory = substitute(directory, " ", "\\\\ ", "g")
  985. exec "set " . settingname . "=" . directory
  986. endif
  987. endfor
  988. endfunction
  989. call InitializeDirectories()
  990. " }
  991. " Initialize NERDTree as needed {
  992. function! NERDTreeInitAsNeeded()
  993. redir => bufoutput
  994. buffers!
  995. redir END
  996. let idx = stridx(bufoutput, "NERD_tree")
  997. if idx > -1
  998. NERDTreeMirror
  999. NERDTreeFind
  1000. wincmd l
  1001. endif
  1002. endfunction
  1003. " }
  1004. " Strip whitespace {
  1005. function! StripTrailingWhitespace()
  1006. " Preparation: save last search, and cursor position.
  1007. let _s=@/
  1008. let l = line(".")
  1009. let c = col(".")
  1010. " do the business:
  1011. %s/\s\+$//e
  1012. " clean up: restore previous search history, and cursor position
  1013. let @/=_s
  1014. call cursor(l, c)
  1015. endfunction
  1016. " }
  1017. " Shell command {
  1018. function! s:RunShellCommand(cmdline)
  1019. botright new
  1020. setlocal buftype=nofile
  1021. setlocal bufhidden=delete
  1022. setlocal nobuflisted
  1023. setlocal noswapfile
  1024. setlocal nowrap
  1025. setlocal filetype=shell
  1026. setlocal syntax=shell
  1027. call setline(1, a:cmdline)
  1028. call setline(2, substitute(a:cmdline, '.', '=', 'g'))
  1029. execute 'silent $read !' . escape(a:cmdline, '%#')
  1030. setlocal nomodifiable
  1031. 1
  1032. endfunction
  1033. command! -complete=file -nargs=+ Shell call s:RunShellCommand(<q-args>)
  1034. " e.g. Grep current file for <search_term>: Shell grep -Hn <search_term> %
  1035. " }
  1036. function! s:IsSpf13Fork()
  1037. let s:is_fork = 0
  1038. let s:fork_files = ["~/.vimrc.fork", "~/.vimrc.before.fork", "~/.vimrc.bundles.fork"]
  1039. for fork_file in s:fork_files
  1040. if filereadable(expand(fork_file, ":p"))
  1041. let s:is_fork = 1
  1042. break
  1043. endif
  1044. endfor
  1045. return s:is_fork
  1046. endfunction
  1047. function! s:ExpandFilenameAndExecute(command, file)
  1048. execute a:command . " " . expand(a:file, ":p")
  1049. endfunction
  1050. function! s:EditSpf13Config()
  1051. call <SID>ExpandFilenameAndExecute("tabedit", "~/.vimrc")
  1052. call <SID>ExpandFilenameAndExecute("vsplit", "~/.vimrc.before")
  1053. call <SID>ExpandFilenameAndExecute("vsplit", "~/.vimrc.bundles")
  1054. execute bufwinnr(".vimrc") . "wincmd w"
  1055. call <SID>ExpandFilenameAndExecute("split", "~/.vimrc.local")
  1056. wincmd l
  1057. call <SID>ExpandFilenameAndExecute("split", "~/.vimrc.before.local")
  1058. wincmd l
  1059. call <SID>ExpandFilenameAndExecute("split", "~/.vimrc.bundles.local")
  1060. if <SID>IsSpf13Fork()
  1061. execute bufwinnr(".vimrc") . "wincmd w"
  1062. call <SID>ExpandFilenameAndExecute("split", "~/.vimrc.fork")
  1063. wincmd l
  1064. call <SID>ExpandFilenameAndExecute("split", "~/.vimrc.before.fork")
  1065. wincmd l
  1066. call <SID>ExpandFilenameAndExecute("split", "~/.vimrc.bundles.fork")
  1067. endif
  1068. execute bufwinnr(".vimrc.local") . "wincmd w"
  1069. endfunction
  1070. execute "noremap " . s:spf13_edit_config_mapping " :call <SID>EditSpf13Config()<CR>"
  1071. execute "noremap " . s:spf13_apply_config_mapping . " :source ~/.vimrc<CR>"
  1072. " }
  1073. " Use fork vimrc if available {
  1074. if filereadable(expand("~/.vimrc.fork"))
  1075. source ~/.vimrc.fork
  1076. endif
  1077. " }
  1078. " Use local vimrc if available {
  1079. if filereadable(expand("~/.vimrc.local"))
  1080. source ~/.vimrc.local
  1081. endif
  1082. " }
  1083. " Use local gvimrc if available and gui is running {
  1084. if has('gui_running')
  1085. if filereadable(expand("~/.gvimrc.local"))
  1086. source ~/.gvimrc.local
  1087. endif
  1088. endif
  1089. " }
转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号