On Wed, Apr 7, 2010 at 2:31 AM, Aman Jain <[email protected]> wrote:
> Hi
>
> After doing '[I' - (left bracket followed by capital i) which is meant
> for displaying all lines that contain the keyword under cursor, how
> can I save those results.
> The output was not available in any registers.

Besides the answers you have received I keep the following in my .vimrc


" Find and display (in a new buffer) with syntax highlighting on /*{{{*/
" Courtesy of Dr. Chip Campbell
" Try putting the following into your <.vimrc>; then
"     :[range]FindHiLite 'pattern'
" will set up a separate window using the syntax highlighting
" and highlight-search emphasis.
"
function! FindHiLite(regex) range
  let akeep = @a
  let @a    = ""
  let ft    = &ft
  " Escape special characters in the regex
  let regex = substitute(
              \     substitute(
              \         escape(a:regex, '\\/.*$^~[]'),
              \         "\n$",
              \         "", ""
              \     ),
              \     "\n", '\\_[[:return:]]', "g"
              \ )
  " Do not escape the special characters
  let regex = a:regex
  " Add line numbers followed by a tab for each
  " line found
  exe a:firstline.','.a:lastline."g/".
              \ (&ignorecase==1?'\c':'\C').
              \ regex.'/' .
              \ ':let @a = @a . line(".") . "\t" . getline(".") . "\n"'
  topleft split
  enew!
  put a
  norm! 1G2dd
  exe "set hls nomod ft=".ft
  let @a= akeep
endfunction

command! -range=% -nargs=1 FindHiLite <line1>,<line2>call FindHiLite(<q-args>)




Then I run:
:FindHiLite dave

A split window is opened with each of the lines you would see from [i,
the difference being is:
1.   they are in a new buffer.
2.  they are syntax highlighted
3.  they have lines numbers assigned to them

I use this frequently.  Then just use :bw! to get rid of it when you
have finished.  I have thought about adding a couple of buffer
specific maps which would:
1.  <enter> work like the quickfix window and transfer me back to the
previous window and take me to the line I wanted.
2.  'q' to run the :bw! for me, since I have 'q' "quit" my help,
quickfix, yankring, and other buffers so it is nice and consistent.

HTH,
Dave

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Subscription settings: http://groups.google.com/group/vim_use/subscribe?hl=en

Reply via email to