----- Original Message ----- 
From: "Suresh Govindachar" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Friday, April 28, 2006 12:58 PM
Subject: Quick peak at files


>
> Hello,
>
>   I have summarized my posts today titled "Balloons", "File ->
>   register" and "Backslash in maps" as a vimtip
>   (www.vim.org/tips/tip.php?tip_id=1218) titled "Quick peak at
>   files";  the tip is also attached below.
>
>   --Suresh
>
> Quick peak at files
>
>   In an operating system's command-line terminal, one can get a
>   quick peak at a file using commands such as more, cat, head etc.
>   In vim, one way to peak at a file would be to open it in a new
>   buffer -- but there is a way to peak at a file from vim without
>   having to open it in a buffer, browse it and close the buffer --
>   one can just view it in vim's command line!  This mode of viewing
>   is facilitated in vim version 7 by version 7's support for
>   scrolling (see :help scroll-back).
>
>   So to peak at a file, we just echo its contents (:help echo; info
>   on other commands mentioned here can be found likewise via :help).
>
>   Simple implementation:
>   ---------------------
>   One way to implement the idea would be:
>
>       :new|r <file_name>|1d|exec 'normal "ayG'|q!|echo @a
>
>   One could also do :echo system('cat foo.bat'), but we are trying
>   to avoid explicit system calls.  In version 7, vim supports
>   readfile().  But the results of readfile() is an array of lines --
>   and these lines would need to be joined to enable viewing; so we
>   have:
>
>       :echo join(readfile('foo.bat'), "\n")
>
>   Applications:
>   ------------
>   Here are two applications that build on the idea presented here.
>
>   A) Yasuhiro Matsumoto's calendar utility
>      (www.vim.org/scripts/script.php?script_id=52) is written to
>      display the calendar in a buffer. For a quick peak at the
>      calendar, one can modify the plugin to support echoing the
>      calendar in vim's command line, and make a simple map (such as
>      of a RightMouse click) to trigger the display on the command
>      line!
>
>   B) I have the following in my vimfiles\after\ftplugin\index.vim
>      to speed up previewing emails using my mail user agent utility
>      (www.vim.org/scripts/script.php?script_id=1052)
>
>      if(v:version < 700)
>
>          nnoremap <buffer> <space> :exec "let @a='r
'.expand('%:p:h').'/'.substitute(
>                                       \getline('.'),
>
\'\\(^.*\|\\s*\\)\\\|\\(\\s\\s*$\\)',
>                                       \'',
>                                       \'g')
>                                       \\\|new\\|@a\\|1d\\|
>                                       \silent exec 'normal\
d}\"ayG'\\|q!\\|echo\ @a"<cr>
>      else
>
>          nnoremap <buffer> <space> :exec "let
alist=readfile(expand('%:p:h').'/'.
>                                       \substitute(getline('.'),
>
\'\\(^.*\|\\s*\\)\\\|\\(\\s\\s*$\\)',
>                                                  \'',
>                                                  \'g')
>                                       \)\\|
>                                       \while(remove(alist, 0) != '')
>                                       \\\|endwhile
>                                       \\\|echo\
>                                       \substitute(getline('.'),
>
\'\\(^.*\|\\s*\\)\\\|\\(\\s\\s*$\\)',
>                                                  \'',
>                                                  \'g').\"\n\n\"
>                                       \\\|echo join(alist,\"\n\")"<cr>
>
>      endif
>
>   Acknowledgment:
>   --------------
>   While the idea presented here is mine, people on the [email protected]
>   mailing list suggested alternate ways of implementing it and
>   helped with some implementation details (such as escaping |).
>
>   Happy vimming!
>
>   --Suresh
>


Just a clarification, peak or peek? People (like me)looking for a tip like
this might missed it. I myself think it's peek but that's just me.
By the way thank you for this tip.


Best regards,
h.

Reply via email to