Quellcode durchsuchen

Degrade vim gracefully in older versions

Use Netrw+Vinegar for vim =< 7.1 or Dirvish for vim 7.2+.
Use FZF only if available, otherwise fall back to CtrlP.
Weiyi Lou vor 9 Jahren
Ursprung
Commit
e7f89de34c
5 geänderte Dateien mit 40 neuen und 22 gelöschten Zeilen
  1. 3 2
      README.md
  2. 1 3
      shell/common/fzf.sh
  3. 12 5
      vim/plugins.vim
  4. 21 9
      vim/settings/filebrowser.vim
  5. 3 3
      vim/vimrc

+ 3 - 2
README.md

@@ -3,7 +3,7 @@
 Configuration files for:
 
 - Bash (3.2+) and Zsh (4.3.17+)
-- Vim (7.4+) or NeoVim
+- Vim (7+) and NeoVim
 - Vimperator (3.8+)
 - Tmux (1.8+)
 - Other bits and pieces
@@ -62,13 +62,14 @@ Below is a non-exhaustive list of dotfiles usage.
 `Space` is the `<Leader>`.
 
 - `<Leader>w` saves.
-- `<Leader>q` closes files.
+- `<Leader>q` closes.
 - `<Leader>l` lists loaded buffers and allows jumping to them by number.
 - `<Leader>p` fuzzy-finds files.
 - `<Leader>f` fuzzy-finds functions in the current file.
 - `<Leader>t` opens a function/variable list for the current file.
 - `<Leader>n` toggles line numbers.
 - `<Leader>c` finds VCS conflict markers.
+- `-` opens a file browser.
 - Additional text objects exist (see `'Text Objects'` in [plugins.vim][]).
 - Saving `.pandoc` files also outputs `.docx` versions.
 - `:Goyo` for distraction-free writing.

+ 1 - 3
shell/common/fzf.sh

@@ -5,9 +5,7 @@ if [[ -x $(command -v ag 2>/dev/null) ]]; then
   export FZF_DEFAULT_COMMAND='ag -l -g ""'
 else
   # Otherwise at least use `git ls-tree` if available.
-  export FZF_DEFAULT_COMMAND='
-  (git ls-tree -r --name-only HEAD ||
-    find * -name ".*" -prune -o -type f -print -o -type l -print) 2>/dev/null'
+  export FZF_DEFAULT_COMMAND='(git ls-tree -r --name-only HEAD || find * -name ".*" -prune -o -type f -print -o -type l -print) 2>/dev/null'
 fi
 
 # To apply the command to CTRL-T as well (paste selection into command line)

+ 12 - 5
vim/plugins.vim

@@ -14,7 +14,6 @@ silent! call plug#begin('~/dotfiles/vim/plugged')
 Plug 'Raimondi/delimitMate'
 Plug 'dkprice/vim-easygrep'
 Plug 'haya14busa/vim-asterisk'
-Plug 'joonty/vdebug'
 Plug 'junegunn/vim-easy-align'
 Plug 'matchit.zip'
 Plug 'mbbill/undotree'
@@ -24,10 +23,13 @@ Plug 'tpope/vim-endwise'
 Plug 'tpope/vim-fugitive'
 Plug 'tpope/vim-repeat'
 Plug 'tpope/vim-unimpaired'
+Plug 'vim-scripts/visualrepeat'
+if v:version >= 703
+  Plug 'joonty/vdebug'
+endif
 if v:version >= 704
   Plug 'vim-pandoc/vim-pandoc'
 endif
-Plug 'vim-scripts/visualrepeat'
 " }}}
 
 " Visual {{{
@@ -57,7 +59,11 @@ Plug 'vim-scripts/argtextobj.vim'
 Plug 'ctrlpvim/ctrlp.vim'
 Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': 'yes \| ./install' }
 Plug 'junegunn/fzf.vim'
-Plug 'justinmk/vim-dirvish'
+if v:version >= 702
+  Plug 'justinmk/vim-dirvish'
+else
+  Plug 'tpope/vim-vinegar'
+endif
 " }}}
 
 " Code Browser {{{
@@ -79,13 +85,15 @@ Plug 'LnL7/vim-nix'
 Plug 'elzr/vim-json'
 Plug 'nicklasos/vim-jsx-riot'
 Plug 'pearofducks/ansible-vim'
-Plug 'scrooloose/syntastic'
 Plug 'sheerun/vim-polyglot'
 Plug 'tobyS/pdv'
 Plug 'tobyS/vmustache'
 Plug 'vim-pandoc/vim-pandoc-syntax'
 Plug 'vim-scripts/yaml.vim'
 Plug 'vimperator/vimperator.vim'
+if v:version > 700 || (v:version == 700 && has('patch175'))
+  Plug 'scrooloose/syntastic'
+endif
 " }}}
 
 " Discarded {{{
@@ -95,7 +103,6 @@ Plug 'vimperator/vimperator.vim'
 "Plug 'kshenoy/vim-signature' - nice, but mostly unused.
 "Plug 'scrooloose/nerdtree' - moved away from drawer-style browser to netrw.
 "Plug 'terryma/vim-expand-region' - cool, but often slower than text objects.
-"Plug 'tpope/vim-vinegar' - moved from netrw to dirvish.
 "
 "Plug 'MarcWeber/vim-addon-mw-utils' -\
 "Plug 'ervandew/supertab' ------------|

+ 21 - 9
vim/settings/filebrowser.vim

@@ -1,3 +1,12 @@
+" Netrw - Vim's built-in file browser.
+
+" Put errors in `:messages`
+let g:netrw_use_errorwindow = 0
+
+" 'o' to (o)pen
+autocmd FileType netrw map <silent> <buffer> o <CR>
+
+
 " Dirvish file browser.
 
 " Use relative paths if there is no `conceal` ability.
@@ -10,7 +19,7 @@ augroup dirvishCustomisation
   autocmd FileType dirvish call fugitive#detect(@%)
 
   " Add/Adjust mappings.
-  " - Reverse 'o' to (o)pen and 'i' to spl(i)t.
+  " - 'o' to (o)pen and 'i' to spl(i)t.
   " - Create, Delete, Rename with 'mc', 'md', 'mr'.
   autocmd FileType dirvish let s:nowait = (v:version > 703 ? '<nowait>' : '')
         \| execute 'nnoremap '.s:nowait.'<buffer><silent> o :<C-U>.call dirvish#open("edit", 0)<CR>'
@@ -59,19 +68,22 @@ function! FileRename()
 endfunction
 
 
-" CtrlP - Fuzzy Finder in Vimscript
-let s:fallback = executable('ag') ? 'ag %s -l --nocolor -g ""' : 'find %s -type f'
+" Fuzzy Finder
 
+" Set `<Leader>p` to FZF if possible. CtrlP is always available at `<C-p>`
+if executable('fzf')
+  map <silent> <Leader>p :FZF<CR>
+else
+  let g:ctrlp_map = '<Leader>p'
+endif
+
+" CtrlP uses `git ls-files` in git repos, otherwise `ag` then `find`.
 let g:ctrlp_user_command = [
   \ '.git',
   \ 'cd %s && git ls-files . -co --exclude-standard',
-  \ s:fallback
+  \ executable('ag') ? 'ag %s -l --nocolor -g ""' : 'find %s -type f'
 \]
 
-" Function definition jumping with CtrlP's Funky plugin.
+" CtrlP Funky plugin - jump to function definitions in the current file.
 let g:ctrlp_extensions = ['funky']
 map <silent> <Leader>f :CtrlPFunky<CR>
-
-
-" FZF - Fuzzy Finder in Go/Ruby
-map <silent> <Leader>p :FZF<CR>

+ 3 - 3
vim/vimrc

@@ -94,22 +94,22 @@ set smartcase   " Case-sensitive when uppercase present
 " }}}
 
 " Visuals {{{
-set colorcolumn=+1                      " Highlight the textwidth limit
 set cursorline                          " Highlight current line
 set list                                " Display unprintables (like tabs)
 set listchars=tab:>\ ,extends:#,nbsp:#  " Customise unprintables
+set matchpairs+=<:>                     " Match <> as a pair, not just ()[]{}
+set number                              " Show line numbers
 set scrolloff=5                         " Lines to keep above/below cursor
 set shortmess+=filmnrxoOtT              " Abbreviation of messages
 set showmatch                           " Show matching brackets/parenthesis
-set matchpairs+=<:>                     " Match <> as a pair, not just ()[]{}
 set sidescroll=1                        " Side-ways scroll speed
 set sidescrolloff=10                    " Columns to keep left/right of cursor
 set wildmenu                            " Ex command tab-complete shows options
 if has('syntax')
   syntax enable                         " Syntax highlighting
 endif
-set number                              " Show line numbers
 if v:version >= 703
+  set colorcolumn=+1                    " Highlight the textwidth limit
   set relativenumber                    " Show numbers relative to current line
 endif
 " }}}