Hi,
I want to specify the line number to go to at the command line. Could anybody let me know how to do it with vim? Thanks. -- Regards, Peng -- -- 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 --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CABrM6w%3DdnVcz1kpLwYzvp1FiOQ28kZCzP4gqkd%3D6dzo%3DSR9gzg%40mail.gmail.com. |
* Peng Yu <[hidden email]> [2021-03-24 01:51]:
> I want to specify the line number to go to at the command line. > Could anybody let me know how to do it with vim? Thanks. how to go to line #23: jump to line 23 on startup: vim +23 filename jump to line 23 in command mode: 23G 23gg jump to line 23 in command mode: :23 turn line numbering on: :set nu see also: :help G :help gg :help range :help 'nu' :help +cmd Sven -- -- 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 --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20210324010250.7f2354bqmwsbixhl%40guckes.net. |
On Wed, Mar 24, 2021 at 2:02 AM Sven Guckes <[hidden email]> wrote:
> > * Peng Yu <[hidden email]> [2021-03-24 01:51]: > > I want to specify the line number to go to at the command line. > > Could anybody let me know how to do it with vim? Thanks. > > how to go to line #23: > > jump to line 23 on startup: > vim +23 filename > > jump to line 23 in command mode: > 23G > 23gg > > jump to line 23 in command mode: > :23 Yes, and as icing on the cake, a variation on this one: how to go to a specific line and column: " Go to line and column function GoTo(line, column) exe min([line("$"), a:line]) "| normal" a:column . "|" endfunction see :help [range] " a naked range goes to the line(s) mentioned :help bar " to go to a certain column :help min() " this function takes only a List or a Dictionary as argument > > turn line numbering on: > :set nu > > see also: > :help G > :help gg > :help range > :help 'nu' > :help +cmd > > Sven > > -- > -- > 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 > > --- > You received this message because you are subscribed to the Google Groups "vim_use" group. > To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. > To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20210324010250.7f2354bqmwsbixhl%40guckes.net. -- -- 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 --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXtZOyk9FOh6XedmFibAd%3DrCgfvHvAMrbP7crwc21-NF5A%40mail.gmail.com. |
In reply to this post by Sven Guckes-3
Sven Guckes <[hidden email]> wrote:
> * Peng Yu <[hidden email]> [2021-03-24 01:51]: >> I want to specify the line number to go to at the command line. >> Could anybody let me know how to do it with vim? Thanks. > > how to go to line #23: > > jump to line 23 on startup: > vim +23 filename That's a good answer. The more modern version is to use -c like this: vim -c :23 filename Up to ten -c commands can be given, each with an ex mode command. Note it may need quotes from the shell: vim -c ':normal 23G' filename I have a script that I use where I consider the filename to be sensitive and I don't want it to appear in `ps` output. To invoke vim to edit that file from script I use a temporary tags file. One could (but probably would find it too cumbersome) use a method like that to go to line 23. Here's the bit of sh script I use: case "$mode" in # ... edit) tmp=tags printf "main\t%s\t1\n" "$name" > $tmp vim -t main rc=$? rm $tmp exit $rc ;; # ... esac In the 'tags' file I create, the three columns are tagname, filename, and line number. (In typical 'tags' files the third column is a search pattern, not a line number. Typically they also have multiple lines with separate entries.) I then invoke vim with the tag name. I bring it up in case this isn't going to be cumbersome and might be something that helps your use case: vim -c ':set tags=/some/shared/tags/file' -t tagname Elijah -- -- 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 --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/4F5Pkq3pj8zfYm%40panix5.panix.com. |
In reply to this post by Tony Mechelynck
Tony Mechelynck <[hidden email]> wrote: > Yes, and as icing on the cake, a variation on this one: how to go to a > specific line and column: > > " Go to line and column > function GoTo(line, column) > exe min([line("$"), a:line]) "| normal" a:column . "|" > endfunction You don't need a vim function to do that. You can run normal from the command line. Go to line 23 column 45: vim -c ':normal 23G45|' filename Elijah -- -- 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 --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/4F5PrD4vNjzfYm%40panix5.panix.com. |
Free forum by Nabble | Edit this page |