Эх сурвалжийг харах

remove unwanted plugins, separate folding and quickfix from vimrc.local

Also put back manual vim file backup. This is useful for safely removing old
vimrcs and folders before we start to populate spf13-vim bundles.
Weiyi Lou 12 жил өмнө
parent
commit
41ff958b98

+ 2 - 0
setup.sh

@@ -47,6 +47,8 @@ ln -s dotfiles/zsh/zshrc ~/.zshrc
 ln -s dotfiles/zsh/zshenv ~/.zshenv
 
 # Vim
+[ -d ~/.vim ] && mv ~/.vim "$BACKUP_DIR"
+[ -f ~/.vimrc ] && mv ~/.vimrc "$BACKUP_DIR"
 ln -s dotfiles/vim/vimrc.local ~/.vimrc.local
 ln -s dotfiles/vim/vimrc.before.local ~/.vimrc.before.local
 ln -s dotfiles/vim/vimrc.bundles.local ~/.vimrc.bundles.local

+ 113 - 0
vim/settings/folding.vim

@@ -0,0 +1,113 @@
+" Folding - Modeline and Notes {{{
+" vim: set sw=2 ts=2 sts=2 et tw=78 foldmarker={{{,}}} foldlevel=0 foldmethod=marker spell:
+"
+"   cinaeco/dotfiles Folding Settings
+"
+"   These are settings to make folding easier to use and look at:
+"    - Indented Folds to match their first line.
+"    - Stat box to right displays line count and fold level.
+"    - Coloured distinctly red!
+"        (sounds harsh, but actually works well with solarized-dark!)
+"    - Fillchar is forced to '.' rather than '-'.
+"        (easier on eyes)
+"    - SpaceBar toggles folds, if any.
+"        (much more convenient than the 'z' commands)
+"    - SPF13-VIM provides quick foldlevel setting map: <Leader>f[0-9]
+"        (useful with stat box lvl)
+"
+"   Note that custom foldtext will only work for vim 7.3+. For earlier
+"   versions of vim, only the colouring and spacebar mapping will take effect.
+"
+"   TODO:
+"    - Fold description is just the first line found. Haven't really
+"    understood the regex, but could perhaps make it better.
+"    - Fold description current truncation rule is 1/3 of the window width.
+"    Perhaps this could be some less arbitrary rule?
+"
+" }}}
+
+if has('folding')
+
+  " Keyboard Shortcut {{{
+    " Space as a Folding toggle in normal mode.
+    nnoremap <silent> <space>     @=(foldlevel('.')?'za':"\<space>")<CR>
+  " }}}
+
+  " Fold Highlighting {{{
+    " Red fold text! (Pretty good with solarized-dark)
+    highlight Folded term=none cterm=none ctermfg=darkred ctermbg=none guifg=darkred guibg=none
+  " }}}
+
+  " Fold Text {{{
+    set foldtext=CustomFoldText()
+
+    function! CustomFoldText()
+
+      " At least vim 7.3. {{{
+      "  - Requirement for strdisplaywidth.
+        if v:version < 703
+          return foldtext()
+        endif
+      " }}}
+
+      " Force dot fillchar. {{{
+      "  - The complicated line is to ensure we replace the fold fillchar only.
+        let &l:fillchars = substitute(&l:fillchars,',\?fold:.','','gi')
+        setlocal fillchars+=fold:.
+      " }}}
+
+      " Prepare script variables. {{{
+        let foldChar = matchstr(&fillchars, 'fold:\zs.')
+        let currWinWidth = winwidth(0)
+      " }}}
+
+      " Prepare fold indent. {{{
+      "  - Indent taken from first line in fold.
+        let indentLevel = indent(v:foldstart)
+        let indent = repeat(' ', indentLevel)
+      " }}}
+
+      " Prepare fold description. {{{
+      "  - Truncated to 1/3 of the current window width.
+        let allFoldMarkers = split(&foldmarker, ',')
+        let frontFoldMarker = allFoldMarkers[0]
+        let lineRaw = substitute(getline(v:foldstart), '^\s*"\?\s*\|\s*"\?\s*'.frontFoldMarker.'\d*\s*', '', 'g')
+        let line = '+ '.lineRaw.' '
+        let foldDesc = strpart(line, 0, currWinWidth / 3)
+      " }}}
+
+      " Prepare the stat box. {{{
+      "  - Fixed stat box width at 18 characters.
+      "  - Count width by display cells instead of bytes if at least vim 7.4
+        let lineCount = v:foldend - v:foldstart + 1
+        if v:version >= 704
+          let formatForm = 'S'
+        else
+          let formatForm = 's'
+        endif
+        let statBox = '| ' . printf('%18'.formatForm, lineCount.' lines, lvl '.v:foldlevel) . ' |'
+      " }}}
+
+      " Prepare filler lines. {{{
+      "  - endFiller is the fill after the stat box. Fixed at 5 characters.
+      "  - midFiller is the fill between the description and stat box.
+      "  - midFiller compensates for column widths generated by foldcolumn, number
+      "  and relativenumber.
+      "  - strdisplaywidth() seems to work. If multi-byte characters start to give
+      "  trouble, consider checking the more primitive solution in strlen() help.
+        let endFiller = repeat(foldChar, 5)
+        let midFillerLength = winwidth(0) - strdisplaywidth(indent.foldDesc.statBox.endFiller) - &foldcolumn
+        if (&number || &relativenumber)
+          let midFillerLength -= &numberwidth
+        endif
+        let midFiller = repeat(foldChar, midFillerLength)
+      " }}}
+
+      " Output the combined fold text. {{{
+        return indent.foldDesc.midFiller.statBox.endFiller
+      " }}}
+
+    endfunction
+  " }}}
+
+endif

+ 69 - 0
vim/settings/quickfix.vim

@@ -0,0 +1,69 @@
+" Quickfix - Modeline and Notes {{{
+" vim: set sw=2 ts=2 sts=2 et tw=78 foldmarker={{{,}}} foldlevel=0 foldmethod=marker spell:
+"
+"   cinaeco/dotfiles Quickfix Maps and Behaviors
+"
+"   Some personal conventions:
+"    - 'q' to close quickfix and location list windows.
+"    - 'o' to open quickfix and location list entries.
+"      (not all plugins have these maps)
+"    - <TAB> and <BSLASH> for previous and next entries, so long as quickfix
+"    is open.
+"      (maps are cleared when quickfix is closed)
+"    - quickfix should open after any grep invocation e.g. :Glog
+"      (particularly for fugitive - tpope refuses this as default behaviour)
+"
+"   TODO:
+"    Perhaps this could be some less arbitrary rule?
+"
+" }}}
+
+if has("autocmd")
+
+  " Quickfix Buffer remaps, 'q' and 'o'. {{{
+  "  - `q` to close qf buffer.
+  "  - `o` to open location entry under cursor.
+    autocmd FileType qf nnoremap <silent> <buffer> q :ccl<CR>:lcl<CR>
+    autocmd FileType qf nnoremap <silent> <buffer> o <CR>
+  " }}}
+
+  " Global maps on qf window open, '<TAB>' and '<BSLASH>'. {{{
+  "  - `<TAB>` and `<BSLASH>` for going to previous and next entry
+  "  - unmaps when qf buffer is closed.
+    autocmd BufWinEnter quickfix
+          \ setlocal nocursorline |
+          \ let g:qfix_win = bufnr("$") |
+          \ call MapQfPrevNext()
+          \ endif
+  " }}}
+
+  " Global map removal on qf window close. {{{
+    autocmd BufWinLeave *
+          \ if exists("g:qfix_win") && expand("<abuf>") == g:qfix_win |
+          \   unlet! g:qfix_win |
+          \   call UnmapQfPrefNext() |
+          \ endif
+  " }}}
+
+  " Open quickfix window after any grep invocation (Glog and Ggrep). {{{
+    autocmd QuickFixCmdPost *grep* cwindow |
+          \ setlocal nocursorline |
+          \ let g:qfix_win = bufnr("$") |
+          \ call MapQfPrevNext()
+  " }}}
+
+  " <TAB> and <BSLASH> map adding helper. {{{
+    function! MapQfPrevNext()
+      exec "nmap <silent> <tab> :cprev<CR>"
+      exec "nmap <silent> <bslash> :cnext<CR>"
+    endfunction
+  " }}}
+
+  " <TAB> and <BSLASH> map removal helper. {{{
+    function! UnmapQfPrefNext()
+      exec "nunmap <tab>"
+      exec "nunmap <bslash>"
+    endfunction
+  " }}}
+
+endif

+ 83 - 1
vim/vimrc.bundles.local

@@ -1 +1,83 @@
-Bundle 'tacahiroy/ctrlp-funky'
+" Modeline and Notes {
+" vim: set sw=2 ts=2 sts=2 et tw=78 foldmarker={,} foldlevel=0 foldmethod=marker spell:
+"
+"                    __ _ _____              _
+"         ___ _ __  / _/ |___ /      __   __(_)_ __ ___
+"        / __| '_ \| |_| | |_ \ _____\ \ / /| | '_ ` _ \
+"        \__ \ |_) |  _| |___) |_____|\ V / | | | | | | |
+"        |___/ .__/|_| |_|____/        \_/  |_|_| |_| |_|
+"            |_|
+"
+"   These are the adjusted bundles for cinaeco's setup. Thanks spf13 for an
+"   otherwise fantastic vim distribution! (well, seems to be the Only Other
+"   distribution, other than Janus, which is not that great at all).
+"
+"   Notes for when spf13-vim modules get updated:
+"   Mostly we just override the General bundle section to remove unwanted
+"   bundles. This way we don't have to do a two step
+"   BundleInstall-then-BundleClean to get where we want, and running the
+"   spf13-vim install script doesn't reinstall unwanted bundles.
+" }
+
+" Add Wanted Bundles {
+  Bundle 'tacahiroy/ctrlp-funky'
+" }"
+
+" Remove Unwanted Bundles {
+
+  " Keep all other spf13-vim sections except 'general'.
+  if !exists('g:spf13_bundle_groups')
+    let g:spf13_bundle_groups=['neocomplcache', 'programming', 'php', 'ruby', 'python', 'go', 'twig', 'javascript', 'haskell', 'html', 'misc', 'scala']
+  endif
+
+  " General {
+  Bundle 'scrooloose/nerdtree'
+  Bundle 'altercation/vim-colors-solarized'
+  Bundle 'spf13/vim-colors'
+  Bundle 'tpope/vim-surround'
+  Bundle 'spf13/vim-autoclose'
+  Bundle 'kien/ctrlp.vim'
+  Bundle 'terryma/vim-multiple-cursors'
+  Bundle 'vim-scripts/sessionman.vim'
+  Bundle 'matchit.zip'
+
+  " Removed: We use our own powerline install, which comes with our dotfiles.
+  " Needless to say it means that we intend for this customization of spf13-vim to
+  " only work with our dotfiles installation! Need to reconsider this if we want
+  " to have this as a standalone... but then, we'd really be looking at a fork.
+  "if (has("python") || has("python3")) && exists('g:spf13_use_powerline') && !exists('g:spf13_use_old_powerline')
+    "Bundle 'Lokaltog/powerline', {'rtp':'/powerline/bindings/vim'}
+  "elseif exists('g:spf13_use_powerline') && exists('g:spf13_use_old_powerline')
+    "Bundle 'Lokaltog/vim-powerline'
+  "else
+    "Bundle 'bling/vim-airline'
+  "endif
+
+  " Removed: Never got used to easy motion.
+  " Also, we use <Leader><Leader> for quick NERDCommenter toggling and like it that way.
+  "Bundle 'Lokaltog/vim-easymotion'
+
+  " Removed: Don't care about gvim... yet.
+  " This causes problems with t_Co = 16 issue with solarized. Still work in
+  " progress.
+  "Bundle 'godlygeek/csapprox'
+  "
+  Bundle 'jistr/vim-nerdtree-tabs'
+  Bundle 'flazz/vim-colorschemes'
+  Bundle 'mbbill/undotree'
+
+  " Removed: This is not a fantastic idea, and is slow when working through tunnels.
+  "Bundle 'myusuf3/numbers.vim'
+
+  Bundle 'nathanaelkane/vim-indent-guides'
+  if !exists('g:spf13_no_views')
+    Bundle 'vim-scripts/restore_view.vim'
+  endif
+
+  " Removed: Great, but is slow when you work through tunnels, which I do a LOT.
+  "Bundle 'airblade/vim-gitgutter'
+
+  Bundle 'tpope/vim-abolish.git'
+  " }
+
+" }

+ 3 - 77
vim/vimrc.local

@@ -1,23 +1,3 @@
-"""""""
-"" Remove Unwanted Bundles
-"""""""""""""""""""""""""""""""""""""""""""""""""""
-
-" We use our own powerline install
-UnBundle 'bling/vim-airline'
-
-" Great, but is slow when you work through tunnels, which I do a LOT.
-UnBundle 'airblade/vim-gitgutter'
-
-" This is not a fantastic idea, and is slow when working through tunnels.
-UnBundle 'myusuf3/numbers.vim'
-
-" Never go used to this
-UnBundle 'Lokaltog/vim-easymotion'
-
-" Don't care about gvim... yet.
-UnBundle 'godlygeek/csapprox'
-
-
 if has("autocmd")
 
   " Show trailing white space
@@ -27,31 +7,6 @@ if has("autocmd")
   " Source the vimrc file after saving it
   autocmd BufWritePost .vimrc.local nested source $MYVIMRC
 
-  " QuickFix - Local remaps:
-  "            - `q` to close qf buffer
-  "            - `o` to open location entry under cursor
-  autocmd FileType qf nnoremap <silent> <buffer> q :ccl<CR>:lcl<CR>
-  autocmd FileType qf nnoremap <silent> <buffer> o <CR>
-
-  " QuickFix - Global remaps:
-  "            - `<TAB>` and `\` for previous and next location entry
-  "            - unmaps when qf buffer is closed.
-  autocmd BufWinEnter quickfix
-        \ setlocal nocursorline |
-        \ let g:qfix_win = bufnr("$") |
-        \ call MapQfPrevNext()
-  autocmd BufWinLeave *
-        \ if exists("g:qfix_win") && expand("<abuf>") == g:qfix_win |
-        \   unlet! g:qfix_win |
-        \   call UnmapQfPrefNext() |
-        \ endif
-
-  " QuickFix - Open window after any grep invocation (Glog and Ggrep)
-  autocmd QuickFixCmdPost *grep* cwindow |
-        \ setlocal nocursorline |
-        \ let g:qfix_win = bufnr("$") |
-        \ call MapQfPrevNext()
-
   " Fugitive - Go up to previous tree object while exploring git tree with '..'
   autocmd User fugitive
     \ if fugitive#buffer().type() =~# '^\%(tree\|blob\)$' |
@@ -61,12 +16,6 @@ if has("autocmd")
   " Fugitive - Delete buffers when they are not active
   autocmd BufReadPost fugitive://* set bufhidden=delete
 
-  " PHP - Offline docs, manpage-style, using `K`.
-  " - needs pman installed through PEAR: `pear install doc.php.net/pman`
-  if executable('pman')
-    autocmd FileType php set keywordprg=pman
-  endif
-
 endif
 
 
@@ -81,7 +30,6 @@ set smarttab        " backspace tabs where appropriate even if spaces
 set softtabstop=2   " let backspace delete by indents
 set textwidth=80    " try to keep text within 80 characters
 set colorcolumn=+1  " mark out the limits of the textwidth
-set fillchars=fold:.
 
 
 """"""""
@@ -90,9 +38,6 @@ set fillchars=fold:.
 
 set t_Co=16
 
-" set colour for folded lines
-highlight Folded term=none cterm=none ctermfg=darkred ctermbg=none
-
 " show trailing white space
 highlight ExtraWhitespace ctermfg=red ctermbg=red guifg=red guibg=red
 
@@ -111,7 +56,6 @@ highlight IndentGuidesEven ctermbg=black
 
 set foldmethod=indent
 set foldlevel=10
-set foldtext=FoldText()
 
 
 """"""""
@@ -135,9 +79,6 @@ nnoremap <silent> <leader>$    :%s/\s\+$//g<CR>
 " Convert tabs to spaces
 nnoremap <silent> <leader><TAB>    :%s/<TAB>/  /g<CR>
 
-" Space as a Folding toggle in normal mode.
-nnoremap <silent> <space>     @=(foldlevel('.')?'za':"\<space>")<CR>
-
 " Backspace to clear current search (and stop highlighting)
 nnoremap <silent> <backspace>    :call ClearSearch()<CR>
 
@@ -254,15 +195,6 @@ let g:sparkupNextMapping = '<leader>n' " resolve conflict with vim-multiple-curs
 "" Functions
 """"""""""""""""""""""""""""""""""""""""""""""""""""""""
 
-function! FoldText()
-  let line = getline(v:foldstart)
-  let indent = indent(v:foldstart)
-  let indentOnly = strpart(line, 0, indent-1)
-  let linecount = v:foldend+1 - v:foldstart
-  let foldtext = '+'.indentOnly.'... ('.linecount.' More lines)'
-  return foldtext
-endfunction
-
 function! ToggleMouse()
   if &mouse == 'a'
     set mouse=
@@ -305,12 +237,6 @@ function! CycleKeymap()
   endif
 endfunction
 
-function! MapQfPrevNext()
-  exec "nmap <silent> <tab> :cprev<CR>"
-  exec "nmap <silent> <bslash> :cnext<CR>"
-endfunction
-
-function! UnmapQfPrefNext()
-  exec "nunmap <tab>"
-  exec "nunmap <bslash>"
-endfunction
+for filePath in split(globpath('~/dotfiles/vim/settings', '*.vim'), '\n')
+  execute 'source' filePath
+endfor