dirvish.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. *dirvish.txt* directory viewer
  2. ==============================================================================
  3. OVERVIEW *dirvish*
  4. Dirvish is a minimalist directory viewer. It basically dumps a list of paths
  5. into a Vim buffer and provides some sugar to work with those paths. It works
  6. with built-in Vim mechanisms instead of inventing peripheral imitations.
  7. Because each Dirvish buffer-name is the literal directory path, you can |:cd|
  8. to the directory, >
  9. :cd %
  10. create a new file, >
  11. :edit %foo.txt
  12. |expand()| the directory path, >
  13. :let &titlestring = expand('%', 1)
  14. and use complementary plugin commands like |]f|/|[f| (unimpaired.vim).
  15. Because each dirvish buffer is just a list of paths, you can use normal Vim
  16. commands to |y|ank, |:read|, |gf|, etc. The built-in CTRL-W mappings also work
  17. as expected.
  18. It's totally fine to slice, dice, and smash any Dirvish buffer: it will never
  19. modify the filesystem. If you edit the buffer, Dirvish automatically disables
  20. |conceal| so you can see the full text.
  21. Dirvish is designed to work with built-in Vim concepts where possible. Tim
  22. Pope's plugins demonstrate this theme; more plugins should too. Re-use of
  23. concepts multiplies the utility of those concepts; conversely if a plugin does
  24. not reuse a concept, both that concept and the new one are made mutually less
  25. valuable--the sum is less than the parts--because the user must learn or
  26. choose from two slightly different things instead of one augmented system.
  27. ==============================================================================
  28. MAPPINGS *dirvish-mappings*
  29. Global ~
  30. <Plug>(dirvish_up)
  31. - Opens the [count]th parent directory of the current file.
  32. <Plug>(dirvish_split_up)
  33. Opens the [count]th parent in a new window.
  34. <Plug>(dirvish_vsplit_up)
  35. Opens the [count]th parent in a new, vertical window.
  36. Buffer-local (filetype=dirvish) ~
  37. g? Shows this help.
  38. [count]R Reloads the current directory. (|:edit| works too.)
  39. Sets |g:dirvish_mode| to [count], if given.
  40. Mnemonic: higher [count] => more files.
  41. <Plug>(dirvish_quit)
  42. q Quits and returns to the original file.
  43. gq Alias to "q". May be removed in the future.
  44. <2-LeftMouse>
  45. i
  46. <CR> Opens file at cursor.
  47. {Visual}I
  48. {Visual}<CR> Opens selected files.
  49. o Opens file in a new window.
  50. {Visual}O Opens each selected file in a new window.
  51. a Opens file in a new, vertical window.
  52. {Visual}A Opens each selected file in a new, vertical window.
  53. K Shows file info. [count] shows directory size.
  54. {Visual}K Shows info for selected files. [count] shows directory size.
  55. p Previews file at cursor.
  56. CTRL-N Previews the next file.
  57. CTRL-P Previews the previous file.
  58. <Plug>(dirvish_arg)
  59. x Adds/removes file to/from the local |arglist|.
  60. {Visual}x Adds selected files to the local arglist.
  61. dax Starts a new empty local arglist.
  62. . Inserts ":! {path}" into the command-line.
  63. {Visual}. Inserts "|:Shdo| {}" into the command-line.
  64. [count]. Inserts "|:Shdo|! {}" into the command-line.
  65. ~ Opens your home directory.
  66. cd Sets the local |current-directory|. |:lcd|
  67. [count]cd Sets the global |current-directory|. |:cd|
  68. Buffer-local (:Shdo) ~
  69. *Z!* *dirvish-Z!*
  70. Z! Saves and executes a |:Shdo| shell-script. Closes the
  71. window if the script succeeded.
  72. ==============================================================================
  73. COMMANDS *dirvish-commands*
  74. :Dirvish [path] *dirvish-:Dirvish*
  75. Opens the directory at [path], or its parent if [path] is a file, or the
  76. parent of the current file if [path] is not given.
  77. :[range]Shdo[!] {cmd} *:Shdo* *dirvish-:Shdo*
  78. Generates a shell script with {cmd} applied to [range] and the respective
  79. filepath inserted wherever {} appears in {cmd}. The window-local directory
  80. is initialized to the current Dirvish directory. If bang ! is given the
  81. |arglist| is used instead of [range].
  82. For example, to rename a list of visual-selected files: >
  83. :'<,'>Shdo mv {} {}-copy.txt
  84. < Run the script with |Z!| or ":!%".
  85. ==============================================================================
  86. FUNCTIONS *dirvish-functions*
  87. *dirvish#open()*
  88. [range]dirvish#open({cmd}, {bg})
  89. Performs {cmd} ("edit", "vsplit", "split", "tabedit") on the files in
  90. [range]. {bg} must be 0 (opens in current window) or 1 (opens in the
  91. "background").
  92. *dirvish#add_icon_fn()*
  93. dirvish#add_icon_fn(fn)
  94. Registers a function {fn} to decide the "icon" for each path in a Dirvish
  95. buffer. Returns id for use with |dirvish#remove_icon_fn()|. If multiple
  96. functions are registered: the first function to return non-whitespace for
  97. a given path, wins. Best practice: if you don't have anything meaningful
  98. to show for a given path, return empty string (or whitespace).
  99. {fn} is any |Funcref| that takes a path (string) and returns a single
  100. character (the "icon"). Example: >
  101. call dirvish#add_icon_fn({p -> p[-1:]=='/'?'📂':'📄'})
  102. <
  103. *dirvish#remove_icon_fn()*
  104. dirvish#remove_icon_fn(fn_id)
  105. Unregisters the function associated with {fn_id} returned from
  106. |dirvish#add_icon_fn()|.
  107. ==============================================================================
  108. OPTIONS *dirvish-options*
  109. g:dirvish_mode = 1 *g:dirvish_mode*
  110. Controls which files are listed and how they are presented.
  111. 1: 'suffixes' and 'wildignore' determine sorting and visibility.
  112. 2: Shows all files, in the order returned by |glob()|.
  113. ":{cmd}": Ex-command |:execute|d after listing files.
  114. Mnemonic: higher number => more files.
  115. g:dirvish_relative_paths = 0 *g:dirvish_relative_paths*
  116. 0: List full (absolute) paths in the Dirvish buffer.
  117. 1: List paths relative to the |current-directory|.
  118. (Recommended for Vim 7.3 because it lacks |conceal|).
  119. |BufNew| fires the first time a directory is opened (and not yet loaded).
  120. Note: Use expand("<afile>") to get the new buffer name (not "%").
  121. |FileType| fires after Dirvish has loaded: all mappings, options, and content
  122. can be overridden by handling that event. Example: >
  123. augroup dirvish_config
  124. autocmd!
  125. " Map `t` to open in new tab.
  126. autocmd FileType dirvish
  127. \ nnoremap <silent><buffer> t :call dirvish#open('tabedit', 0)<CR>
  128. \ |xnoremap <silent><buffer> t :call dirvish#open('tabedit', 0)<CR>
  129. " Map `gr` to reload.
  130. autocmd FileType dirvish nnoremap <silent><buffer>
  131. \ gr :<C-U>Dirvish<CR>
  132. " Map `gh` to hide dot-prefixed files. Press `R` to "toggle" (reload).
  133. autocmd FileType dirvish nnoremap <silent><buffer>
  134. \ gh :silent keeppatterns g@\v/\.[^\/]+/?$@d _<cr>:setl cole=3<cr>
  135. augroup END
  136. <
  137. ==============================================================================
  138. FAQ *dirvish-faq*
  139. How do I control where Dirvish opens split windows? ~
  140. Set the Vim options 'splitbelow' and 'splitright'.
  141. How do I group (sort) directories/folders? ~
  142. Sort folders at the top: >
  143. :sort ,^.*[\/],
  144. Sort folders at the bottom: >
  145. :sort ,^.*[^\/],
  146. To make this automatic, set |g:dirvish_mode|: >
  147. let g:dirvish_mode = ':sort ,^.*[\/],'
  148. If you use |g:dirvish_relative_paths|, try this: >
  149. let g:dirvish_mode = ':sort ,^\v(.*[\/])|\ze,'
  150. How do I filter? ~
  151. Use |:global| to delete lines matching any filter: >
  152. :g/foo/d
  153. To make this automatic, set |g:dirvish_mode|: >
  154. let g:dirvish_mode = ':silent keeppatterns g/foo/d _'
  155. How do I hide "hidden" (dot-prefixed) files? ~
  156. Use |:global| to delete the paths with dot-prefixed files: >
  157. :g@\v/\.[^\/]+/?$@d
  158. To "toggle", just reload.
  159. To make this automatic, set |g:dirvish_mode|: >
  160. let g:dirvish_mode = ':silent keeppatterns g@\v/\.[^\/]+/?$@d _'
  161. You could also use a FileType autocmd: >
  162. autocmd FileType dirvish silent keeppatterns g@\v/\.[^\/]+/?$@d _
  163. To un-hide, just undo. To hide again, reload.
  164. How do I disable a Dirvish mapping? ~
  165. As noted in |dirvish-options|, the way to customize Dirvish is to handle its
  166. FileType event. For example if you have a global <C-p> mapping and you don't
  167. want Dirvish to "shadow" it, :unmap the Dirvish buffer-local mapping: >
  168. augroup dirvish_config
  169. autocmd!
  170. autocmd FileType dirvish silent! unmap <buffer> <C-p>
  171. augroup END
  172. You could use ":mapclear <buffer>" to delete ALL of the mappings.
  173. Why does the "swap file" dialog appear if another Vim is viewing the same ~
  174. directory? ~
  175. To avoid this, |:noswapfile| is required (Vim 7.4.213).
  176. https://github.com/vim/vim/tree/v7.4.213
  177. How can I delete files, rename files, or perform other commands?~
  178. Since ":'<,'>call delete(getline('.'))" is a bit much to type, Dirvish
  179. provides the ":Shdo" command. |dirvish-:Shdo|
  180. Just for fun, here's the old-school way: >
  181. qqq
  182. :g/^/let @Q='echo '.shellescape(getline('.')).' '.shellescape(getline('.'))."\n"
  183. :exe 'e' tempname().'.sh'
  184. :put q|w|!%
  185. <
  186. Why does Dirvish report "invalid directory" for a path that contains unusual ~
  187. characters (e.g. brackets "[]")? ~
  188. Check your 'isfname' setting. On Windows (where filepaths may contain
  189. backslashes "\") |fnamemodify()| may produce nonsense if 'isfname' does not
  190. contain the aforementioned unusual characters.
  191. How to override the netrw :Explore, :Sexplore, :Vexplore commands? ~
  192. Put this in your vimrc: >
  193. let g:loaded_netrwPlugin = 1
  194. command! -nargs=? -complete=dir Explore Dirvish <args>
  195. command! -nargs=? -complete=dir Sexplore belowright split | silent Dirvish <args>
  196. command! -nargs=? -complete=dir Vexplore leftabove vsplit | silent Dirvish <args>
  197. How to expand a directory inline (like a tree-style view)? ~
  198. There is a hacky solution. Put this in your vimrc and hit "t" on a directory: >
  199. augroup dirvish_config
  200. autocmd!
  201. autocmd FileType dirvish
  202. \ nnoremap <buffer> t o<Esc>:r !find '<C-R>=substitute(getline(line(".")-1),"\\n","","g")<CR>' -maxdepth 1 -print0 \| xargs -0 ls -Fd<CR>:silent! keeppatterns %s/\/\//\//g<CR>:silent! keeppatterns %s/[^a-zA-Z0-9\/]$//g<CR>:silent! keeppatterns g/^$/d _<CR>"_dd
  203. augroup END
  204. Note:
  205. - Assumes unix-style "/" path separators.
  206. ==============================================================================
  207. vim:tw=78:ts=4:et:ft=help:norl: