commit 90d0b5f2de4ffbff49613c7df18205fb51f52e96
parent 17218cf6d2be1841a8932104c03cfe70029fe3b8
Author: Ed van Bruggen <edvb54@gmail.com>
Date: Wed, 2 Jul 2014 19:53:16 -0700
VIM: add vim-rsi and vim-vinegar plug-ins
Diffstat:
8 files changed, 336 insertions(+), 0 deletions(-)
diff --git a/vim/bundle/vim-rsi/.gitignore b/vim/bundle/vim-rsi/.gitignore
@@ -0,0 +1 @@
+/doc/tags
diff --git a/vim/bundle/vim-rsi/README.markdown b/vim/bundle/vim-rsi/README.markdown
@@ -0,0 +1,52 @@
+# rsi.vim
+
+You know Readline key bindings? Of course you do, they're in your shell, your
+REPL, and perhaps even the GUI for your OS. They're similar to Emacs
+key bindings (C-a for home), but with several concessions for UNIX (C-w for
+delete word).
+
+With rsi.vim, I've taken that same concession philosophy and extended it to
+Vim. Get the most useful of the ubiquitous key bindings without blindly
+overriding built-in Vim functionality.
+
+## Features
+
+* Readline mappings are provided in insert mode and command line mode. Normal
+ mode is deliberately omitted.
+* Important Vim key bindings (like insert mode's C-n and C-p completion) are
+ not overridden.
+* Meta key bindings are provided in a way that works in the terminal without
+ the perils of remapping escape.
+* C-d, C-e, and C-f are mapped such that they perform the Readline behavior in
+ the middle of the line and the Vim behavior at the end. (Think about it.)
+
+## Installation
+
+If you don't have a preferred installation method, I recommend
+installing [pathogen.vim](https://github.com/tpope/vim-pathogen), and
+then simply copy and paste:
+
+ cd ~/.vim/bundle
+ git clone git://github.com/tpope/vim-rsi.git
+
+Once help tags have been generated, you can view the manual with
+`:help rsi`.
+
+## Contributing
+
+See the contribution guidelines for
+[pathogen.vim](https://github.com/tpope/vim-pathogen#readme).
+
+## Self-Promotion
+
+Like rsi.vim? Follow the repository on
+[GitHub](https://github.com/tpope/vim-rsi) and vote for it on
+[vim.org](http://www.vim.org/scripts/script.php?script_id=4359). And if
+you're feeling especially charitable, follow [tpope](http://tpo.pe/) on
+[Twitter](http://twitter.com/tpope) and
+[GitHub](https://github.com/tpope).
+
+## License
+
+Copyright © Tim Pope. Distributed under the same terms as Vim itself.
+See `:help license`.
diff --git a/vim/bundle/vim-rsi/doc/rsi.txt b/vim/bundle/vim-rsi/doc/rsi.txt
@@ -0,0 +1,73 @@
+*rsi.txt* Readline style insertion
+
+Author: Tim Pope <http://tpo.pe/>
+License: Same terms as Vim itself (see |license|)
+
+This plugin is only available if 'compatible' is not set.
+
+INTRODUCTION *rsi*
+
+This plugin provides Readline (Emacs) mappings for insert and command line
+mode that try not to overlap with built-in Vim functionality.
+
+MAPS *rsi-maps*
+
+ *rsi-CTRL-A*
+<C-a> Go to beginning of line.
+
+ *rsi-CTRL-X_CTRL-A*
+<C-x><C-a> Access Vim's built-in |i_CTRL-A| or |c_CTRL-A|.
+
+ *rsi-CTRL-B*
+<C-b> Go backwards one character. On a blank line, kill it
+ and go back to the previous line.
+
+ *rsi-CTRL-D*
+<C-d> Delete character in front of cursor. Falls back to
+ |i_CTRL-D| or |c_CTRL-D| at the end of the line.
+
+ *rsi-CTRL-E*
+<C-e> Go to end of line. Falls back to |i_CTRL-E| if
+ already at the end of the line. (|c_CTRL-E| already
+ goes to end of line, so it is not mapped.)
+
+ *rsi-CTRL-F*
+<C-f> Move forward one character. Falls back to
+ |i_CTRL-F| or |c_CTRL-F| at the end of the line.
+
+ *rsi-CTRL-T*
+<C-t> Transpose two characters. This is mapped in command
+ line mode only, as |i_CTRL-T| is too important to
+ clobber.
+
+ *rsi-META-BS*
+<M-BS> Delete backward one word.
+
+ *rsi-META-b*
+<M-b> Go backwards one word.
+
+ *rsi-META-d*
+<M-d> Delete forwards one word.
+
+ *rsi-META-f*
+<M-f> Go forwards one word.
+
+ *rsi-META-n*
+<M-n> Equivalent to |c_<Down>| or |i_<Down>|.
+
+ *rsi-META-p*
+<M-p> Equivalent to |c_<Up>| or |i_<Up>|.
+
+In the terminal, the meta key sends escape, so mapping these would require
+mappings starting with escape in insert mode. This makes Vim appear to lag
+for a second if you actually press just escape. Instead, rsi.vim makes
+these available by telling Vim they are existing special keys. For example,
+the key code for <S-Left> is changed to <Esc>b.
+
+ABOUT *rsi-about*
+
+Grab the latest version or report a bug on GitHub:
+
+http://github.com/tpope/vim-rsi
+
+ vim:tw=78:et:ft=help:norl:
diff --git a/vim/bundle/vim-rsi/plugin/rsi.vim b/vim/bundle/vim-rsi/plugin/rsi.vim
@@ -0,0 +1,68 @@
+" rsi.vim - Readline style insertion
+" Maintainer: Tim Pope
+" Version: 1.0
+" GetLatestVimScripts: 4359 1 :AutoInstall: rsi.vim
+
+if exists("g:loaded_rsi") || v:version < 700 || &cp
+ finish
+endif
+let g:loaded_rsi = 1
+
+set ttimeout
+if &ttimeoutlen == -1
+ set ttimeoutlen=50
+endif
+
+inoremap <C-A> <C-O>^
+inoremap <C-X><C-A> <C-A>
+cnoremap <C-A> <Home>
+cnoremap <C-X><C-A> <C-A>
+
+inoremap <expr> <C-B> getline('.')=~'^\s*$'&&col('.')>strlen(getline('.'))?"0\<Lt>C-D>\<Lt>Esc>kJs":"\<Lt>Left>"
+cnoremap <C-B> <Left>
+
+inoremap <expr> <C-D> col('.')>strlen(getline('.'))?"\<Lt>C-D>":"\<Lt>Del>"
+cnoremap <expr> <C-D> getcmdpos()>strlen(getcmdline())?"\<Lt>C-D>":"\<Lt>Del>"
+
+inoremap <expr> <C-E> col('.')>strlen(getline('.'))?"\<Lt>C-E>":"\<Lt>End>"
+
+inoremap <expr> <C-F> col('.')>strlen(getline('.'))?"\<Lt>C-F>":"\<Lt>Right>"
+cnoremap <expr> <C-F> getcmdpos()>strlen(getcmdline())?&cedit:"\<Lt>Right>"
+
+noremap! <expr> <SID>transposition getcmdpos()>strlen(getcmdline())?"\<Left>":getcmdpos()>1?'':"\<Right>"
+noremap! <expr> <SID>transpose "\<BS>\<Right>".matchstr(getcmdline()[0 : getcmdpos()-2], '.$')
+cmap <script> <C-T> <SID>transposition<SID>transpose
+
+if &encoding ==# 'latin1' && has('gui_running') && !empty(findfile('plugin/sensible.vim', escape(&rtp, ' ')))
+ set encoding=utf-8
+endif
+
+noremap! <M-b> <S-Left>
+noremap! <M-d> <C-O>dw
+cnoremap <M-d> <S-Right><C-W>
+noremap! <M-BS> <C-W>
+noremap! <M-f> <S-Right>
+noremap! <M-n> <Down>
+noremap! <M-p> <Up>
+
+if !has("gui_running")
+ silent! exe "set <S-Left>=\<Esc>b"
+ silent! exe "set <S-Right>=\<Esc>f"
+ silent! exe "set <F31>=\<Esc>d"
+ silent! exe "set <F32>=\<Esc>n"
+ silent! exe "set <F33>=\<Esc>p"
+ silent! exe "set <F34>=\<Esc>\<C-?>"
+ silent! exe "set <F35>=\<Esc>\<C-H>"
+ map! <F31> <M-d>
+ map! <F32> <M-n>
+ map! <F33> <M-p>
+ map! <F34> <M-BS>
+ map! <F35> <M-BS>
+ map <F31> <M-d>
+ map <F32> <M-n>
+ map <F33> <M-p>
+ map <F34> <M-BS>
+ map <F35> <M-BS>
+endif
+
+" vim:set et sw=2:
diff --git a/vim/bundle/vim-vinegar/CONTRIBUTING.markdown b/vim/bundle/vim-vinegar/CONTRIBUTING.markdown
@@ -0,0 +1 @@
+See the [contribution guidelines for pathogen.vim](https://github.com/tpope/vim-pathogen/blob/master/CONTRIBUTING.markdown).
diff --git a/vim/bundle/vim-vinegar/README.markdown b/vim/bundle/vim-vinegar/README.markdown
@@ -0,0 +1,45 @@
+# vinegar.vim
+
+> Split windows and the project drawer go together like oil and vinegar. I
+> don't mean to say that you can combine them to create a delicious salad
+> dressing. I mean that they don't mix well!
+> - Drew Neil
+
+You know what netrw is, right? The built in directory browser? Well,
+vinegar.vim enhances netrw, partially in an attempt to mitigate the need for
+more disruptive ["project drawer"][Oil and vinegar] style plugins.
+
+[Oil and vinegar]: http://vimcasts.org/blog/2013/01/oil-and-vinegar-split-windows-and-project-drawer/
+
+Some of the behaviors added by vinegar.vim would make excellent upstream
+additions. Many, the author would probably reject. Others are a bit too wild
+to even consider.
+
+* Press `-` in any buffer to hop up to the directory listing and seek to the
+ file you just came from. Keep bouncing to go up, up, up. Having rapid
+ directory access available changes everything.
+* All that annoying crap at the top is turned off, leaving you with nothing
+ but a list of files. This is surprisingly disorienting, but ultimately
+ very liberating. Press `I` to toggle until you adapt.
+* The oddly C-biased default sort order and file hiding is replaced with a
+ sensible application of `'suffixes'` and `'wildignore'`.
+* Press `.` on a file to pre-populate it at the end of a `:` command line.
+ This is great, for example, to quickly initiate a `:grep` of the file or
+ directory under the cursor. There's also `!`, which starts the line off
+ with a bang. Type `!chmod +x` and get `:!chmod +x path/to/file`.
+* Press `cg` or `cl` to `:cd` or `:lcd` to the currently edited directory.
+* Press `~` to go home.
+
+## Installation
+
+If you don't have a preferred installation method, I recommend
+installing [pathogen.vim](https://github.com/tpope/vim-pathogen), and
+then simply copy and paste:
+
+ cd ~/.vim/bundle
+ git clone git://github.com/tpope/vim-vinegar.git
+
+## License
+
+Copyright © Tim Pope. Distributed under the same terms as Vim itself.
+See `:help license`.
diff --git a/vim/bundle/vim-vinegar/plugin/vinegar.vim b/vim/bundle/vim-vinegar/plugin/vinegar.vim
@@ -0,0 +1,92 @@
+" vinegar.vim - combine with netrw to create a delicious salad dressing
+" Maintainer: Tim Pope <http://tpo.pe/>
+
+if exists("g:loaded_vinegar") || v:version < 700 || &cp
+ finish
+endif
+let g:loaded_vinegar = 1
+
+function! s:fnameescape(file) abort
+ if exists('*fnameescape')
+ return fnameescape(a:file)
+ else
+ return escape(a:file," \t\n*?[{`$\\%#'\"|!<")
+ endif
+endfunction
+
+let s:dotfiles = '\(^\|\s\s\)\zs\.\S\+'
+
+let g:netrw_sort_sequence = '[\/]$,*,\%(' . join(map(split(&suffixes, ','), 'escape(v:val, ".*$~")'), '\|') . '\)[*@]\=$'
+let s:escape = 'substitute(escape(v:val, ".$~"), "*", ".*", "g")'
+let g:netrw_list_hide =
+ \ join(map(split(&wildignore, ','), '"^".' . s:escape . '. "$"'), ',') . ',^\.\.\=/\=$' .
+ \ (get(g:, 'netrw_list_hide', '')[-strlen(s:dotfiles)-1:-1] ==# s:dotfiles ? ','.s:dotfiles : '')
+let g:netrw_banner = 0
+let s:netrw_up = ''
+
+nnoremap <silent> <Plug>VinegarUp :call <SID>opendir('edit')<CR>
+if empty(maparg('-', 'n'))
+ nmap - <Plug>VinegarUp
+endif
+
+nnoremap <silent> <Plug>VinegarTabUp :call <SID>opendir('tabedit')<CR>
+nnoremap <silent> <Plug>VinegarSplitUp :call <SID>opendir('split')<CR>
+nnoremap <silent> <Plug>VinegarVerticalSplitUp :call <SID>opendir('vsplit')<CR>
+
+function! s:opendir(cmd)
+ let df = ','.s:dotfiles
+ if expand('%:t')[0] ==# '.' && g:netrw_list_hide[-strlen(df):-1] ==# df
+ let g:netrw_list_hide = g:netrw_list_hide[0 : -strlen(df)-1]
+ endif
+ if &filetype ==# 'netrw'
+ let currdir = fnamemodify(b:netrw_curdir, ':t')
+ execute s:netrw_up
+ call s:seek(currdir)
+ else
+ if empty(expand('%'))
+ execute a:cmd '.'
+ else
+ execute a:cmd '%:h/'
+ call s:seek(expand('#:t'))
+ endif
+ endif
+endfunction
+
+function! s:seek(file)
+ let pattern = '^\%(| \)*'.escape(a:file, '.*[]~\').'[/*|@=]\=\%($\|\t\)'
+ call search(pattern, 'wc')
+ return pattern
+endfunction
+
+augroup vinegar
+ autocmd!
+ autocmd FileType netrw call s:setup_vinegar()
+augroup END
+
+function! s:escaped(first, last) abort
+ let files = getline(a:first, a:last)
+ call filter(files, 'v:val !~# "^\" "')
+ call map(files, 'substitute(v:val, "[/*|@=]\\=\\%(\\t.*\\)\\=$", "", "")')
+ return join(map(files, 'fnamemodify(b:netrw_curdir."/".v:val,":~:.")'), ' ')
+endfunction
+
+function! s:setup_vinegar() abort
+ if empty(s:netrw_up)
+ " save netrw mapping
+ let s:netrw_up = maparg('-', 'n')
+ " saved string is like this:
+ " :exe "norm! 0"|call netrw#LocalBrowseCheck(<SNR>172_NetrwBrowseChgDir(1,'../'))<CR>
+ " remove <CR> at the end (otherwise raises "E488: Trailing characters")
+ let s:netrw_up = strpart(s:netrw_up, 0, strlen(s:netrw_up)-4)
+ endif
+ nmap <buffer> - <Plug>VinegarUp
+ nnoremap <buffer> ~ :edit ~/<CR>
+ nnoremap <buffer> . :<C-U> <C-R>=<SID>escaped(line('.'), line('.') - 1 + v:count1)<CR><Home>
+ xnoremap <buffer> . <Esc>: <C-R>=<SID>escaped(line("'<"), line("'>"))<CR><Home>
+ nmap <buffer> ! .!
+ xmap <buffer> ! .!
+ nnoremap <buffer> <silent> cg :exe 'keepjumps cd ' .<SID>fnameescape(b:netrw_curdir)<CR>
+ nnoremap <buffer> <silent> cl :exe 'keepjumps lcd '.<SID>fnameescape(b:netrw_curdir)<CR>
+ exe 'syn match netrwSuffixes =\%(\S\+ \)*\S\+\%('.join(map(split(&suffixes, ','), s:escape), '\|') . '\)[*@]\=\S\@!='
+ hi def link netrwSuffixes SpecialKey
+endfunction
diff --git a/vimrc.bundles b/vimrc.bundles
@@ -27,6 +27,10 @@ Bundle 'tpope/vim-surround'
Bundle 'tpope/vim-unimpaired'
" better HTML/XML editing
Bundle 'tpope/vim-ragtag'
+" better netrw file explorer
+Bundle 'tpope/vim-vinegar'
+" Readline in insert mode
+Bundle 'tpope/vim-rsi'
""" language specific plug-ins
" syntax checker