Results 1 to 4 of 4

Thread: How to go to the line having a particular word in GVIM?

  1. #1
    Join Date
    Apr 2013
    Beans
    2

    How to go to the line having a particular word in GVIM?

    Hi,
    When i open a file (*.SUM*), I want the cursor to go to a line having a particular word (: ERROR). and that line should have the first occurrence word(: ERROR) from the beginning of the gvim file(*.SUM*)
    Presently iam using the following command in my .gvimrc, but the cursor is going to the line having the second occurrence of the word (: ERROR)
    autocmd BufReadPost *.SUM* /: ERROR
    Plz help me out

  2. #2
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: How to go to the line having a particular word in GVIM?

    Try
    Code:
    autocmd BufReadPost *.SUM* 1;/: ERROR
    Last edited by schragge; April 8th, 2013 at 09:53 AM.

  3. #3
    Join Date
    Apr 2013
    Beans
    2

    Re: How to go to the line having a particular word in GVIM?

    Hi schragge, many thanks its working. iam thinking the buffer read has stopped after the first read of THE WORD (: ERROR ). aM I RIGHT? AND Can you please explain what was happening before?

  4. #4
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: How to go to the line having a particular word in GVIM?

    Most probably, you have a command in one of Vim's startup files (~/.vimrc, ~/.vim/*, /etc/vim/*) that makes Vim jump to the last known cursor position in file. I.e. if you were at the end of file when leaving it last time, Vim would first jump to the end and then try to search from that point forward. I just specified an interval, or range in vim parlance on which the command should have effect.
    Code:
    1;/regex/
    means from the line 1 to the first occurence of regular expression in //. Semicolon (;) means jump to the start line of a range before executing the command. If you omit the command, Ex will just jump to the last line of the range.

    See explanation or ranges in Vim documentation: Quick Reference, User Manual, Reference Manual.

    The command argument of autocmd is an Ex or command-line mode command. Basically, this is what you get inside a Vim session with
    Code:
    :1;/: ERROR
    Note the : as first character of the command.
    Last edited by schragge; April 8th, 2013 at 02:54 PM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •