Loading ...
Sorry, an error occurred while loading the content.

114979Re: A question about [I

Expand Messages
  • David Fishburn
    Jun 7, 2010
    • 0 Attachment
      On 07/06/2010 4:43 PM, Shagen Ogandzhanjan wrote:
      Hi, I have a question I've tried to answer myself - but I guess this time there is more sense to ask the respectable vim community:
      as vim documentation told me, [I "Display all lines that contain the keyword under the cursor." My question is - is there's any way to navigate
      through generated list same way as we navigating through quickfix window?

      I mean, I can type :N to jump to the Nth line or M[^I то jump  to the Mth occurence - but i just want to jump from first occurence to the second one, etc.

      thanks in advance
      --
      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

      Not that I am aware of.

      You can do something like this though:

      function! FindHiLite(prev_winnr, 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

        " Wipes out the buffer
        nnoremap <buffer> q :bw!<CR>
        " Takes you back to the previous buffer and goes to the line specified at
        " the start of the match
        let prev_win_cmd=':'.(a:prev_winnr+1).'wincmd w'
        exec 'nnoremap <buffer> <enter> :let cmd='."'".prev_win_cmd.' <Bar> :'."'.matchstr(getline('.'), '^\\d\\+')".' <Bar> exec cmd'.' <Bar> exec "normal zO"<CR>'
      endfunction

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

      Then map [I and ]I to use this function instead passing in the current word as an argument.
      This mapping does it:
      nmap ]I :exec 'FindHiLite '.expand('<cword>')<CR>

      Then you can do anything you like.  It is a buffer though, so you will have to close it.

      Notice the last nnoremap at the end of the function.  That is so you can hit <enter> on any line to take you back to the original file current line.

      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
    • Show all 4 messages in this topic