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

Re: how to determine when +/pat is used at invocation...?

Expand Messages
  • Tony Mechelynck
    ... If you want to make sure to go to the first match from the top of the file, I think you can use (untested) vim +0;/pattern/ somefile.txt From an
    Message 1 of 2 , May 1 12:52 AM
      On 24/04/09 16:39, vim@... wrote:
      > Hello,
      >
      > I recently added the statements to my ~/.vimrc (found in the FAQ)
      > that cause vim to return to it's last position in a file, e.g.:
      >
      > autocmd BufReadPost * if line("'\"")> 0&& line("'\"")<= line("$")
      > \ | execute "normal g`\"" | endif
      >
      > I have noticed that command line use of +/pat has some undesirable
      > interactions with this new "jump to last" feature... For example,
      > it can cause the cursor to jump to the N+1 'pat' with each new
      > invocation as `" keeps getting changing to the Nth 'pat' (I hope
      > that makes sense).
      >
      > Anywho, here's the pseudo-code of what I would like to do:
      >
      > if plus_slash_pat_used_at_invocation()
      > " do nothing (+/pat works and finds 1st match)
      > else
      > autocmd BufReadPost * if line("'\"")> 0&& line("'\"")<= line("$")
      > \ | execute "normal g`\"" | endif
      > endif
      >
      > Unfortunately, I can't figure out how to determine if +/pat is used
      > at invocation. The @/ register is not reliable to test as it may be
      > set from a previous editing session and args() seems to only list
      > file names, so I'm stumped!
      >
      > Maybe my whole approach is misguided...?
      >
      > Your help is appreciated!
      >
      > Thanks!
      >
      > - Tor

      If you want to make sure to go to the first match from the top of the
      file, I think you can use (untested)

      vim +0;/pattern/ somefile.txt

      From an already-running Vim, I just tested the following movement
      command (and it works)

      :0;/pattern/

      to go to the first (topmost) line matching /pattern/ in the current file.


      Best regards,
      Tony.
      --
      Machines certainly can solve problems, store information, correlate,
      and play games -- but not with pleasure.
      -- Leo Rosten

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    Your message has been successfully submitted and would be delivered to recipients shortly.