Wikia

Vim Tips Wiki

Changes: Folding of find locate tar-tf output

Edit

Back to page

(Adjust previous/next navigation + minor manual clean)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 3: Line 3:
 
|previous=1544
 
|previous=1544
 
|next=1546
 
|next=1546
|created=January 20, 2008
+
|created=2008
 
|complexity=basic
 
|complexity=basic
 
|author=Umu
 
|author=Umu
Line 13: Line 13:
 
Given a huge file listing as text file, you can use this script to comfortably browse it. Use all fold commands of Vim to open/close parts of the directory tree, as used from standard file managers ( but even more flexible, including moving in fold structure, executing commands on folds ... )
 
Given a huge file listing as text file, you can use this script to comfortably browse it. Use all fold commands of Vim to open/close parts of the directory tree, as used from standard file managers ( but even more flexible, including moving in fold structure, executing commands on folds ... )
   
The more, on Unix-like systems you can pipe the output of tools like <tt>find</tt>, <tt>locate</tt>, <tt>tar -t</tt>, ... directly into Vim executing this script by using <tt>-</tt> as filename.
+
The more, on Unix-like systems you can pipe the output of tools like <code>find</code>, <code>locate</code>, <code>tar -t</code>, ... directly into Vim executing this script by using <code>-</code> as filename.
   
 
Examples:
 
Examples:
Line 51: Line 51:
 
*Briefly explain purpose of tip and how to use (don't assume reader can quickly determine what idea is).
 
*Briefly explain purpose of tip and how to use (don't assume reader can quickly determine what idea is).
 
*Include something like "On Unix systems..." near top as hint for new readers.
 
*Include something like "On Unix systems..." near top as hint for new readers.
*Mention how the <tt>-</tt> makes Vim input from stdin.
+
*Mention how the <code>-</code> makes Vim input from stdin.
   
 
----
 
----

Latest revision as of 06:31, July 13, 2012

Tip 1545 Printable Monobook Previous Next

created 2008 · complexity basic · author Umu · version 7.0


Given a huge file listing as text file, you can use this script to comfortably browse it. Use all fold commands of Vim to open/close parts of the directory tree, as used from standard file managers ( but even more flexible, including moving in fold structure, executing commands on folds ... )

The more, on Unix-like systems you can pipe the output of tools like find, locate, tar -t, ... directly into Vim executing this script by using - as filename.

Examples:

vim -u browser.vim  arch-hurd-i386.files
find . | vim -u browser.vim -
locate nox | vim -u browser.vim -
tar -tzf boost.tar.gz | vim -u browser.vim -

browser.vim

set mouse=a
set foldminlines=1 foldcolumn=2 fillchars="+" foldlevel=0
set foldmethod=expr
set foldexpr=FileBrowserFoldExpr()
set foldtext=FileBrowserFoldText()

function FileBrowserFoldExpr()
  let line=getline(v:lnum)
  let n=strlen(substitute(line,'[^/]*','','g'))
  if (line=~'^.*/$')
    return '>'.n
  elseif (strpart(getline(v:lnum+1),0,strlen(line)+1)==line.'/')
    return '>'.(n+1)
  endif
  return n
endfunction

function FileBrowserFoldText()
  return getline(v:foldstart) . '    ... [' . (v:foldend-v:foldstart+1) . ' lines]'
endfunction

CommentsEdit

 TO DO 

  • Briefly explain purpose of tip and how to use (don't assume reader can quickly determine what idea is).
  • Include something like "On Unix systems..." near top as hint for new readers.
  • Mention how the - makes Vim input from stdin.

Around Wikia's network

Random Wiki