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

Re: ijump ?pattern?

Expand Messages
  • Bram Moolenaar
    ... Or the last pattern in the last file with a match? Anyway, this is quite difficult to implement. I normally first use [I to see all matches, and then
    Message 1 of 10 , Oct 3, 2000
    • 0 Attachment
      Johannes Zellner wrote:

      > what about
      > ijump ?pattern?
      > searching the last occurence of pattern in a file ?

      Or the last pattern in the last file with a match?

      Anyway, this is quite difficult to implement. I normally first use "[I" to
      see all matches, and then type the count before a "[<Tab>" command. That's
      two steps, but it's OK for me, since I mostly want to see where the jump goes
      to anyway.

      --
      hundred-and-one symptoms of being an internet addict:
      153. You find yourself staring at your "inbox" waiting for new e-mail
      to arrive.

      /// Bram Moolenaar Bram@... http://www.moolenaar.net \\\
      \\\ Vim: http://www.vim.org ICCF Holland: http://iccf-holland.org ///
    • Johannes Zellner
      ... I meant this mainly to be used in scripts. But anyway: that gave me the idea of finally implement one of my items of the todo list (see `:help todo and
      Message 2 of 10 , Oct 3, 2000
      • 0 Attachment
        On Tue, Oct 03, 2000 at 11:21:06AM +0200, Bram Moolenaar wrote:
        >
        > Johannes Zellner wrote:
        >
        > > what about
        > > ijump ?pattern?
        > > searching the last occurence of pattern in a file ?
        >
        > Or the last pattern in the last file with a match?
        >
        > Anyway, this is quite difficult to implement. I normally first use "[I" to
        > see all matches, and then type the count before a "[<Tab>" command. That's
        > two steps, but it's OK for me, since I mostly want to see where the jump goes
        > to anyway.

        I meant this mainly to be used in scripts. But anyway: that gave
        me the idea of finally implement one of my items of the todo list
        (see `:help todo' and the last item of `Zellner') -- a list of
        [I items and the possiblity to select one of the items.

        The script is attached and works just like the famous explorer.vim
        and bufexplorer.vim scripts: Type <Map>i (e.g.: ,i) while the cursor
        is on a keyword of interest, the rest is explained in the header
        of the newly created selection window. You can also visually select
        something (must be a one-liner though) and hit ,i.

        Just drop the attached script in your <runtime>/plugin directory.
        Works only with 6.0h, as it uses <Map>, <buffer> and such.

        --
        Johannes
      • Bram Moolenaar
        ... Looks nice. One problem I discovered is that the highlighting only highlights the first file name. When I hit CR on a line for a file that s not in a
        Message 3 of 10 , Oct 4, 2000
        • 0 Attachment
          Johannes Zellner wrote:

          > I meant this mainly to be used in scripts. But anyway: that gave
          > me the idea of finally implement one of my items of the todo list
          > (see `:help todo' and the last item of `Zellner') -- a list of
          > [I items and the possiblity to select one of the items.

          Looks nice. One problem I discovered is that the highlighting only highlights
          the first file name.

          When I hit CR on a line for a file that's not in a window I get an error
          message. I would expect this to jump to the found location.

          > Just drop the attached script in your <runtime>/plugin directory.
          > Works only with 6.0h, as it uses <Map>, <buffer> and such.

          As an exercise, I changed the mapping stuff into how it would be with the
          proposed method for plugins. This won't work for you yet, since you don't
          have the hasmapto() function. But you can check if this looks OK:

          if !hasmapto('\IexplorerInit')
          " <Map>i -- open a list of items which match the word under the cursor
          nmap <Map>i \IexplorerInit
          endif
          if !hasmapto('\IexplorerInitV')
          " visual <Map>i - open a list of items which match the visually selected area
          vmap <Map>i \IexplorerInitV
          endif
          nmap \IexplorerInit :call Iexplorer(expand('<cword>'), 'n')<cr>
          vmap \IexplorerInitV <esc>:call Iexplorer(IexplorerGetVisual(), 'v')<cr>

          If you don't like the default key sequence <Map>i, you can put something like
          this in your vimrc file:

          nmap \x \IexplorerInit
          vmap \x \IexplorerInitV

          --
          "Hit any key to continue" is very confusing when you have two keyboards.

          /// Bram Moolenaar Bram@... http://www.moolenaar.net \\\
          \\\ Vim: http://www.vim.org ICCF Holland: http://iccf-holland.org ///
        • Johannes Zellner
          ... I can t see this here. Example: # vim -u NONE iexplorer.vim ... ,i (somewhere on a word) o (close other window, so that only the iexplorer
          Message 4 of 10 , Oct 4, 2000
          • 0 Attachment
            On Wed, Oct 04, 2000 at 12:50:04PM +0200, Bram Moolenaar wrote:
            > > I meant this mainly to be used in scripts. But anyway: that gave
            > > me the idea of finally implement one of my items of the todo list
            > > (see `:help todo' and the last item of `Zellner') -- a list of
            > > [I items and the possiblity to select one of the items.
            >
            > Looks nice. One problem I discovered is that the highlighting only highlights
            > the first file name.
            >
            > When I hit CR on a line for a file that's not in a window I get an error
            > message. I would expect this to jump to the found location.

            I can't see this here. Example:
            # vim -u NONE iexplorer.vim
            :set cpo-=<
            :source iexplorer.vim
            ,i (somewhere on a word)
            <c-w>o (close other window, so that only the iexplorer window is left)
            <cr> (splits again and goes to the correct location)

            or did I misunderstand you? This works not only with -u NONE but also
            with my own setup. Maybe I didn't take into account some possible settings?

            > As an exercise, I changed the mapping stuff into how it would be with the
            > proposed method for plugins. This won't work for you yet, since you don't
            > have the hasmapto() function. But you can check if this looks OK:
            >
            > if !hasmapto('\IexplorerInit')
            > " <Map>i -- open a list of items which match the word under the cursor
            > nmap <Map>i \IexplorerInit
            > endif
            > if !hasmapto('\IexplorerInitV')
            > " visual <Map>i - open a list of items which match the visually selected area
            > vmap <Map>i \IexplorerInitV
            > endif
            > nmap \IexplorerInit :call Iexplorer(expand('<cword>'), 'n')<cr>
            > vmap \IexplorerInitV <esc>:call Iexplorer(IexplorerGetVisual(), 'v')<cr>
            >
            > If you don't like the default key sequence <Map>i, you can put something like
            > this in your vimrc file:
            >
            > nmap \x \IexplorerInit
            > vmap \x \IexplorerInitV

            This is ok!

            --
            Johannes
          • Johannes Zellner
            ... There s indeed one minor correction necessary, but I don t know if this solves your problem. If you had the cursor on the file name in line 2 you got an
            Message 5 of 10 , Oct 4, 2000
            • 0 Attachment
              On Wed, Oct 04, 2000 at 12:50:04PM +0200, Bram Moolenaar wrote:
              > When I hit CR on a line for a file that's not in a window I get an error
              > message. I would expect this to jump to the found location.

              There's indeed one minor correction necessary, but I don't know
              if this solves your problem. If you had the cursor on the file
              name in line 2 you got an error message. Here's the `patch':

              - if line('.') <= 1
              + if line('.') <= 2

              --
              Johannes
            • Bram Moolenaar
              ... I edit main.c in the Vim src directory, then source iexplorer.vim . Move the cursor to a word, e.g., mch_errmsg, the type ,i. I get a window with a
              Message 6 of 10 , Oct 4, 2000
              • 0 Attachment
                Johannes Zellner wrote:

                > On Wed, Oct 04, 2000 at 12:50:04PM +0200, Bram Moolenaar wrote:
                > > > I meant this mainly to be used in scripts. But anyway: that gave
                > > > me the idea of finally implement one of my items of the todo list
                > > > (see `:help todo' and the last item of `Zellner') -- a list of
                > > > [I items and the possiblity to select one of the items.
                > >
                > > Looks nice. One problem I discovered is that the highlighting only
                > > highlights the first file name.
                > >
                > > When I hit CR on a line for a file that's not in a window I get an error
                > > message. I would expect this to jump to the found location.
                >
                > I can't see this here. Example:
                > # vim -u NONE iexplorer.vim
                > :set cpo-=<
                > :source iexplorer.vim
                > ,i (somewhere on a word)
                > <c-w>o (close other window, so that only the iexplorer window is left)
                > <cr> (splits again and goes to the correct location)
                >
                > or did I misunderstand you? This works not only with -u NONE but also
                > with my own setup. Maybe I didn't take into account some possible settings?

                I edit "main.c" in the Vim src directory, then source "iexplorer.vim". Move
                the cursor to a word, e.g., mch_errmsg, the type ,i. I get a window with a
                long list of matches in different files. Only the first file name is
                highlighted. Hitting <CR> on the first match gives an error in
                IexplorerSelect(). It's for this line:

                exe 'sb '.getline(2)

                "getline(2)" gets the first file name. Strange, how would it get one of the
                other file names? Then "sb" only works if there already is a buffer for this
                filename. That explains the error I'm getting.

                Perhaps I didn't understand what iexplorer.vim was supposed to be used for?
                Does it only work for matches within one file?

                --
                hundred-and-one symptoms of being an internet addict:
                174. You know what a listserv is.

                /// Bram Moolenaar Bram@... http://www.moolenaar.net \\\
                \\\ Vim: http://www.vim.org ICCF Holland: http://iccf-holland.org ///
              • Johannes Zellner
                ... ok ok. Was my fault. I used this only with vim and tex files up to now and didn t consider matches in /multiple/ files beeing found. (Both vim and tex have
                Message 7 of 10 , Oct 4, 2000
                • 0 Attachment
                  On Wed, Oct 04, 2000 at 09:56:08PM +0200, Bram Moolenaar wrote:
                  > I edit "main.c" in the Vim src directory, then source "iexplorer.vim". Move
                  > the cursor to a word, e.g., mch_errmsg, the type ,i. I get a window with a
                  > long list of matches in different files. Only the first file name is
                  > highlighted. Hitting <CR> on the first match gives an error in

                  ok ok. Was my fault. I used this only with vim and tex files up to
                  now and didn't consider matches in /multiple/ files beeing found.
                  (Both vim and tex have no other files included).
                  I'll modify it.

                  --
                  Johannes
                • Johannes Zellner
                  Hello, here is an updated version of iexplorer.vim -- the [I-list explorer. 1) all file names are highlighted correctly 2) matches in multiple files are
                  Message 8 of 10 , Oct 4, 2000
                  • 0 Attachment
                    " Description: select item from ijump -- [I -- list
                    " Author: Johannes Zellner <johannes@...>
                    " URL: http://www.zellner.org/vim/plugin/iexplorer.vim
                    " Last Change: Don, 05 Okt 2000 03:59:38 +0200
                    " Requirements: vim >= 6.0h, cpoptions must /not/ contain '<'
                    " $Id:$

                    " <Map>i -- open a list of items which match the word under the cursor
                    nmap <Map>i :call Iexplorer(expand('<cword>'), 'n')<cr>
                    " visual <Map>i - open a list of items which match the visually selected area
                    vmap <Map>i <esc>:call Iexplorer(IexplorerGetVisual(), 'v')<cr>

                    au! BufUnload,BufHidden /_iexplorer.tmp :bd! /_iexplorer.tmp

                    fun! Iexplorer(word, mode)
                    if expand('%:p:t') == '_iexplorer.tmp'
                    return
                    endif

                    let save_report = &report
                    set report=999999
                    let save_x = @x
                    redir @x
                    if 'v' == a:mode
                    silent! exe 'ilist! /'.a:word.'/'
                    else
                    silent! exe 'ilist! '.a:word
                    endif
                    redir END

                    " save the directory where the list was created
                    let cwd = substitute(getcwd(), '[/\\]$', '', '')

                    if bufexists('/_iexplorer.tmp')
                    bd! /_iexplorer.tmp
                    endif

                    sp /_iexplorer.tmp

                    " [-- mappings --]
                    " local command keys
                    nnoremap <buffer> <cr> :call IexplorerSelect(0)<cr>
                    nnoremap <buffer> <space> :call IexplorerSelect(1)<cr>
                    nnoremap <buffer> <tab> :call IexplorerSelect(2)<cr>
                    nnoremap <buffer> q :bd! /_iexplorer.tmp<cr>
                    " don't need the iselect command
                    nnoremap <buffer> <Map>i <nop>
                    " don't need insert mode commands
                    nnoremap <buffer> i <nop>
                    nnoremap <buffer> o <nop>
                    nnoremap <buffer> a <nop>
                    nnoremap <buffer> I <nop>
                    nnoremap <buffer> O <nop>
                    nnoremap <buffer> A <nop>

                    " [-- fill _iexplorer.tmp --]
                    " clear buffer
                    %d _
                    " header
                    let header = "\" <space>:view, <cr>:select, <tab>:select and quit, <q>uit\n"
                    0put!=header
                    " append the list of matches
                    put x
                    " restore the x register
                    let @x = save_x
                    " delete empty lines
                    g/^\s*$/d
                    " make the files absolute paths to make it
                    " still working if we change directories.
                    exe '%s§^[^~/\\]\f*$§'.cwd.'/&§ge'
                    let &modified=0

                    " [-- resize --]
                    1
                    if winheight('.') > line('$')
                    exe 'resize' . line('$')
                    endif
                    3

                    call IexplorerSyntax(a:word, a:mode)
                    let &report = save_report
                    endfun

                    fun! IexplorerSelect(mode)
                    " the topmost 2 lines contain the header and the first file name
                    if line('.') <= 2
                    return
                    endif

                    " parse the current line
                    " example:
                    " 1: 59 <text>
                    " ^^
                    let lnum = line('.')
                    let line = getline(lnum)
                    let lineno = substitute(line, '^\s*\d\+:\s*\(\d\+\)\s.*$', '\1', 'g')

                    if lineno == line
                    " the substitution failed, could issue a warning here.
                    return
                    endif

                    " search backwards for the filename
                    let filename = ''
                    let lnum = lnum - 1
                    while lnum >= 2
                    let tmp = getline(lnum)
                    " check if it's a filename
                    if tmp =~ '^\f\+$'
                    " check if it's not a [I pattern
                    if tmp !~ '^\s*\d\+:\s*\d\+'
                    let filename = tmp
                    break
                    endif
                    endif
                    let lnum = lnum - 1
                    endwhile

                    if '' == filename
                    " unable to get filename, could issue a warning here.
                    return
                    endif

                    " save the window number
                    let win = bufwinnr('/_iexplorer.tmp')

                    " go to the buffer (assuming it's already loaded)
                    let save_switchbuf = &switchbuf
                    set switchbuf=useopen
                    exe 'silent! sb '.filename
                    let &switchbuf = save_switchbuf

                    " if the file is not loaded, sb fails, and
                    " we're still in /_iexplorer.tmp. Try 'sp'
                    if win == winnr()
                    exe 'sp '.filename
                    endif

                    " go to the line
                    exe lineno

                    if 1 == a:mode
                    " go back to _iexplorer.tmp
                    " normal w
                    exe 'normal '.win.'w'
                    elseif 2 == a:mode
                    bd! /_iexplorer.tmp
                    endif
                    endfun

                    fun! IexplorerSyntax(word, mode)
                    if has('syntax')
                    if 'v' == a:mode
                    exe 'syn match iexplorerWord /'.a:word.'/'
                    else
                    exe 'syn match iexplorerWord /\<'.a:word.'\>/'
                    endif

                    " hightlight the topmost line (the header) as comment
                    syn match iexplorerComment /^".*$/
                    " highlight the file names. This files
                    " for file names starting with a digit.
                    syn match iexplorerFileName /^\F\f*\>/
                    syn match iexplorerLineNum /^\s*\d\+:\s\+\d\+/hs=s+5

                    hi link iexplorerWord Statement
                    hi link iexplorerComment Comment
                    hi link iexplorerFileName Function
                    hi link iexplorerLineNum LineNr
                    endif
                    endfun

                    fun! IexplorerGetVisual()
                    let x = @x
                    normal gv"xy
                    let vis = @x
                    let @x = x
                    return vis
                    endfun
                  • Bram Moolenaar
                    ... It appears to work very well. I ll drop it in my ~/.vim/plugin directory. I would suggest modifying it when 6.0i comes out to include the hasmapto()
                    Message 9 of 10 , Oct 5, 2000
                    • 0 Attachment
                      Johannes Zellner wrote:

                      > here is an updated version of 'iexplorer.vim' -- the [I-list explorer.
                      > 1) all file names are highlighted correctly
                      > 2) matches in multiple files are possible.
                      >
                      > needs version 6.0h

                      It appears to work very well. I'll drop it in my ~/.vim/plugin directory.

                      I would suggest modifying it when 6.0i comes out to include the hasmapto()
                      function. Then upload it to VUR!

                      --
                      hundred-and-one symptoms of being an internet addict:
                      179. You wonder why your household garbage can doesn't have an
                      "empty recycle bin" button.

                      /// Bram Moolenaar Bram@... http://www.moolenaar.net \\\
                      \\\ Vim: http://www.vim.org ICCF Holland: http://iccf-holland.org ///
                    Your message has been successfully submitted and would be delivered to recipients shortly.