├── .github └── FUNDING.yml ├── .gitignore ├── CONTRIBUTING.markdown ├── README.markdown ├── doc └── vinegar.txt └── plugin └── vinegar.vim /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: tpope 2 | custom: ["https://www.paypal.me/vimpope"] 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /doc/tags 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.markdown: -------------------------------------------------------------------------------- 1 | See the [contribution guidelines for pathogen.vim](https://github.com/tpope/vim-pathogen/blob/master/CONTRIBUTING.markdown). 2 | 3 | Vinegar is roughly 130 lines of code. Netrw is roughly 13,000 lines. There's 4 | literally a 99% chance the bug you're going to report is in Netrw, not 5 | Vinegar. Your issue needs to demonstrate beyond a shadow of a doubt that 6 | you've ruled out Netrw as the source of your problem. 7 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # vinegar.vim 2 | 3 | > Split windows and the project drawer go together like oil and vinegar. I 4 | > don't mean to say that you can combine them to create a delicious salad 5 | > dressing. I mean that they don't mix well! 6 | > - Drew Neil 7 | 8 | You know what netrw is, right? The built in directory browser? Well, 9 | vinegar.vim enhances netrw, partially in an attempt to mitigate the need for 10 | more disruptive ["project drawer"][Oil and vinegar] style plugins. 11 | 12 | [Oil and vinegar]: http://vimcasts.org/blog/2013/01/oil-and-vinegar-split-windows-and-project-drawer/ 13 | 14 | Some of the behaviors added by vinegar.vim would make excellent upstream 15 | additions. Many, the author would probably reject. Others are a bit too wild 16 | to even consider. 17 | 18 | * Press `-` in any buffer to hop up to the directory listing and seek to the 19 | file you just came from. Keep bouncing to go up, up, up. Having rapid 20 | directory access available changes everything. 21 | * All that annoying crap at the top is turned off, leaving you with nothing 22 | but a list of files. This is surprisingly disorienting, but ultimately 23 | very liberating. Press `I` to toggle until you adapt. 24 | * The oddly C-biased default sort order is replaced with a sensible application 25 | of `'suffixes'`. 26 | * File hiding: files are not listed that match with one of the patterns in 27 | `'wildignore'`. 28 | If you put `let g:netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+'` 29 | in your vimrc, vinegar will initialize with dot files hidden. 30 | Press `gh` to toggle dot file hiding. 31 | * Press `.` on a file to pre-populate it at the end of a `:` command line. 32 | This is great, for example, to quickly initiate a `:grep` of the file or 33 | directory under the cursor. Type `.!chmod +x` and 34 | get `:!chmod +x path/to/file`. 35 | * Press `y.` to yank an absolute path for the file under the cursor. 36 | * Press `~` to go home. 37 | * Use Vim's built-in `CTRL-^` (`CTRL-6`) for switching back to the previous 38 | buffer from the netrw buffer. 39 | 40 | ## Installation 41 | 42 | Install using your favourite package manager, or use Vim's built-in package support: 43 | 44 | mkdir -p ~/.vim/pack/tpope/start 45 | cd ~/.vim/pack/tpope/start 46 | git clone https://github.com/tpope/vim-vinegar.git 47 | 48 | ## Promotion 49 | 50 | Like vinegar.vim? Star the repository on 51 | [GitHub](https://github.com/tpope/vim-vinegar) and vote for it on 52 | [vim.org](https://www.vim.org/scripts/script.php?script_id=5671). 53 | 54 | Love vinegar.vim? Follow [tpope](http://tpo.pe/) on 55 | [GitHub](https://github.com/tpope) and 56 | [Twitter](http://twitter.com/tpope). 57 | 58 | ## License 59 | 60 | Copyright © Tim Pope. Distributed under the same terms as Vim itself. 61 | See `:help license`. 62 | -------------------------------------------------------------------------------- /doc/vinegar.txt: -------------------------------------------------------------------------------- 1 | *vinegar.txt* Combine with netrw to create a delicious salad dressing 2 | 3 | Author: Tim Pope 4 | Repo: https://github.com/tpope/vim-vinegar 5 | License: Same terms as Vim itself (see |license|) 6 | 7 | *vinegar* 8 | Vinegar extends netrw. If you don't find what you are looking for here, check 9 | |netrw.txt|. 10 | 11 | MAPPINGS *vinegar-mappings* 12 | 13 | *vinegar--* 14 | - Open the parent directory of the current file. This 15 | is the only mapping available outside of netrw 16 | buffers. 17 | 18 | *vinegar-~* 19 | ~ Open $HOME. 20 | 21 | *vinegar-c_CTRL-R_CTRL-F* 22 | *vinegar-c__* 23 | CTRL-R CTRL-F In command line mode, insert the path to the file 24 | under the cursor. Similar to the native 25 | |c_CTRL-R_CTRL-F|, but resolves the path with respect 26 | to the parent directory. 27 | 28 | *vinegar-.* 29 | . Start a command line with the path to the file 30 | under the cursor. Provide a [count] to include 31 | multiple files. 32 | 33 | *vinegar-!* 34 | ! As above, but use a |:!| command line. Deprecated. 35 | 36 | *vinegar-y.* 37 | y. Yank the current line or [count] lines as absolute 38 | paths. 39 | 40 | vim:tw=78:et:ft=help:norl: 41 | -------------------------------------------------------------------------------- /plugin/vinegar.vim: -------------------------------------------------------------------------------- 1 | " Location: plugin/vinegar.vim 2 | " Maintainer: Tim Pope 3 | " Version: 1.0 4 | " GetLatestVimScripts: 5671 1 :AutoInstall: vinegar.vim 5 | 6 | if exists("g:loaded_vinegar") || v:version < 700 || &cp 7 | finish 8 | endif 9 | let g:loaded_vinegar = 1 10 | 11 | function! s:fnameescape(file) abort 12 | if exists('*fnameescape') 13 | return fnameescape(a:file) 14 | else 15 | return escape(a:file," \t\n*?[{`$\\%#'\"|!<") 16 | endif 17 | endfunction 18 | 19 | let s:dotfiles = '\(^\|\s\s\)\zs\.\S\+' 20 | 21 | let s:escape = 'substitute(escape(v:val, ".$~"), "*", ".*", "g")' 22 | let g:netrw_list_hide = 23 | \ join(map(split(&wildignore, ','), '"^".' . s:escape . '. "/\\=$"'), ',') . ',^\.\.\=/\=$' . 24 | \ (get(g:, 'netrw_list_hide', '')[-strlen(s:dotfiles)-1:-1] ==# s:dotfiles ? ','.s:dotfiles : '') 25 | if !exists("g:netrw_banner") 26 | let g:netrw_banner = 0 27 | endif 28 | unlet! s:netrw_up 29 | 30 | nnoremap VinegarUp :call opendir('edit') 31 | if empty(maparg('-', 'n')) && !hasmapto('VinegarUp') 32 | nmap - VinegarUp 33 | endif 34 | 35 | nnoremap VinegarTabUp :call opendir('tabedit') 36 | nnoremap VinegarSplitUp :call opendir('split') 37 | nnoremap VinegarVerticalSplitUp :call opendir('vsplit') 38 | 39 | function! s:sort_sequence(suffixes) abort 40 | return '[\/]$,*' . (empty(a:suffixes) ? '' : ',\%(' . 41 | \ join(map(split(a:suffixes, ','), 'escape(v:val, ".*$~")'), '\|') . '\)[*@]\=$') 42 | endfunction 43 | let g:netrw_sort_sequence = s:sort_sequence(&suffixes) 44 | 45 | function! s:opendir(cmd) abort 46 | let df = ','.s:dotfiles 47 | if expand('%:t')[0] ==# '.' && g:netrw_list_hide[-strlen(df):-1] ==# df 48 | let g:netrw_list_hide = g:netrw_list_hide[0 : -strlen(df)-1] 49 | endif 50 | if &filetype ==# 'netrw' && len(s:netrw_up) 51 | let basename = fnamemodify(b:netrw_curdir, ':t') 52 | execute s:netrw_up 53 | call s:seek(basename) 54 | elseif expand('%') =~# '^$\|^term:[\/][\/]' 55 | execute a:cmd '.' 56 | else 57 | execute a:cmd '%:h' . (expand('%:p') =~# '^\a\a\+:' ? s:slash() : '') 58 | call s:seek(expand('#:t')) 59 | endif 60 | endfunction 61 | 62 | function! s:seek(file) abort 63 | if get(b:, 'netrw_liststyle') == 2 64 | let pattern = '\%(^\|\s\+\)\zs'.escape(a:file, '.*[]~\').'[/*|@=]\=\%($\|\s\+\)' 65 | else 66 | let pattern = '^\%(| \)*'.escape(a:file, '.*[]~\').'[/*|@=]\=\%($\|\t\)' 67 | endif 68 | call search(pattern, 'wc') 69 | return pattern 70 | endfunction 71 | 72 | augroup vinegar 73 | autocmd! 74 | autocmd FileType netrw call s:setup_vinegar() 75 | if exists('##OptionSet') 76 | autocmd OptionSet suffixes 77 | \ if s:sort_sequence(v:option_old) ==# get(g:, 'netrw_sort_sequence') | 78 | \ let g:netrw_sort_sequence = s:sort_sequence(v:option_new) | 79 | \ endif 80 | endif 81 | augroup END 82 | 83 | function! s:slash() abort 84 | return !exists("+shellslash") || &shellslash ? '/' : '\' 85 | endfunction 86 | 87 | function! s:absolutes(first, ...) abort 88 | let files = getline(a:first, a:0 ? a:1 : a:first) 89 | call filter(files, 'v:val !~# "^\" "') 90 | call map(files, "substitute(v:val, '^\\(| \\)*', '', '')") 91 | call map(files, 'b:netrw_curdir . s:slash() . substitute(v:val, "[/*|@=]\\=\\%(\\t.*\\)\\=$", "", "")') 92 | return files 93 | endfunction 94 | 95 | function! s:relatives(first, ...) abort 96 | let files = s:absolutes(a:first, a:0 ? a:1 : a:first) 97 | call filter(files, 'v:val !~# "^\" "') 98 | for i in range(len(files)) 99 | let relative = fnamemodify(files[i], ':.') 100 | if relative !=# files[i] 101 | let files[i] = '.' . s:slash() . relative 102 | endif 103 | endfor 104 | return files 105 | endfunction 106 | 107 | function! s:escaped(first, last) abort 108 | let files = s:relatives(a:first, a:last) 109 | return join(map(files, 's:fnameescape(v:val)'), ' ') 110 | endfunction 111 | " 97f3fbc9596f3997ebf8e30bfdd00ebb34597722 112 | 113 | function! s:setup_vinegar() abort 114 | if !exists('s:netrw_up') 115 | let orig = maparg('-', 'n') 116 | if orig =~? '^' && orig !=# 'VinegarUp' 117 | let s:netrw_up = 'execute "normal \'.substitute(orig, ' *$', '', '').'"' 118 | elseif orig =~# '^:' 119 | " :exe "norm! 0"|call netrw#LocalBrowseCheck(123_NetrwBrowseChgDir(1,'../')) 120 | let s:netrw_up = substitute(orig, '\c^:\%(\)\=\|$', '', 'g') 121 | else 122 | let s:netrw_up = '' 123 | endif 124 | endif 125 | nmap - VinegarUp 126 | cnoremap get(relatives('.'),0,"\022\006") 127 | if empty(maparg('', 'c')) 128 | cmap 129 | endif 130 | nnoremap ~ :edit ~/ 131 | nnoremap . : =escaped(line('.'), line('.') - 1 + v:count1) 132 | xnoremap . : =escaped(line("'<"), line("'>")) 133 | if empty(mapcheck('y.', 'n')) 134 | nnoremap y. :call setreg(v:register, join(absolutes(line('.'), line('.') - 1 + v:count1), "\n")."\n") 135 | endif 136 | nmap ! .! 137 | xmap ! .! 138 | exe 'syn match netrwSuffixes =\%(\S\+ \)*\S\+\%('.join(map(split(&suffixes, ','), s:escape), '\|') . '\)[*@]\=\S\@!=' 139 | hi def link netrwSuffixes SpecialKey 140 | endfunction 141 | --------------------------------------------------------------------------------