This commit is contained in:
Brian Buller 2018-04-24 07:56:08 -05:00
parent c2efee6a8e
commit 6ac0895b2b
3 changed files with 0 additions and 177 deletions

View File

@ -1 +0,0 @@
See the [contribution guidelines for pathogen.vim](https://github.com/tpope/vim-pathogen/blob/master/CONTRIBUTING.markdown).

View File

@ -1,50 +0,0 @@
# 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 is replaced with a sensible application
of `'suffixes'`.
* File hiding: files are not listed that match with one of the patterns in
`'wildignore'`.
If you put `let g:netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+'`
in your vimrc, vinegar will initialize with dot files hidden.
Press `gh` to toggle dot file hiding.
* 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 `y.` to yank an absolute path for the file under the cursor.
* 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`.

View File

@ -1,126 +0,0 @@
" 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 : '')
if !exists("g:netrw_banner")
let g:netrw_banner = 0
endif
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) abort
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)
elseif expand('%') =~# '^$\|^term:[\/][\/]'
execute a:cmd '.'
else
execute a:cmd '%:h'
call s:seek(expand('#:t'))
endif
endfunction
function! s:seek(file) abort
if get(b:, 'netrw_liststyle') == 2
let pattern = '\%(^\|\s\+\)\zs'.escape(a:file, '.*[]~\').'[/*|@=]\=\%($\|\s\+\)'
else
let pattern = '^\%(| \)*'.escape(a:file, '.*[]~\').'[/*|@=]\=\%($\|\t\)'
endif
call search(pattern, 'wc')
return pattern
endfunction
augroup vinegar
autocmd!
autocmd FileType netrw call s:setup_vinegar()
augroup END
function! s:slash() abort
return !exists("+shellslash") || &shellslash ? '/' : '\'
endfunction
function! s:absolutes(first, ...) abort
let files = getline(a:first, a:0 ? a:1 : a:first)
call filter(files, 'v:val !~# "^\" "')
call map(files, 'b:netrw_curdir . s:slash() . substitute(v:val, "[/*|@=]\\=\\%(\\t.*\\)\\=$", "", "")')
return files
endfunction
function! s:relatives(first, ...) abort
let files = s:absolutes(a:first, a:0 ? a:1 : a:first)
call filter(files, 'v:val !~# "^\" "')
for i in range(len(files))
let relative = fnamemodify(files[i], ':.')
if relative !=# files[i]
let files[i] = '.' . s:slash() . relative
endif
endfor
return files
endfunction
function! s:escaped(first, last) abort
let files = s:relatives(a:first, a:last)
return join(map(files, 'fnameescape(v:val)'), ' ')
endfunction
function! s:setup_vinegar() abort
if empty(s:netrw_up)
" save netrw mapping
if strpart(g:loaded_netrw, 1, strlen(g:loaded_netrw)) < 162
let s:netrw_up = substitute(maparg('-', 'n'), '\c^:\%(<c-u>\)\=', '', '')
else
let s:netrw_up = substitute(maparg('<Plug>NetrwBrowseUpDir', 'n'), '\c^:\%(<c-u>\)\=', '', '')
endif
" 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
cnoremap <buffer><expr> <Plug><cfile> get(<SID>relatives('.'),0,"\022\006")
if empty(maparg('<C-R><C-F>', 'c'))
cmap <buffer> <C-R><C-F> <Plug><cfile>
endif
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>
if empty(mapcheck('y.', 'n'))
nnoremap <silent><buffer> y. :<C-U>call setreg(v:register, join(<SID>absolutes(line('.'), line('.') - 1 + v:count1), "\n")."\n")<CR>
endif
nmap <buffer> ! .!
xmap <buffer> ! .!
exe 'syn match netrwSuffixes =\%(\S\+ \)*\S\+\%('.join(map(split(&suffixes, ','), s:escape), '\|') . '\)[*@]\=\S\@!='
hi def link netrwSuffixes SpecialKey
endfunction