Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I open vim with a particular line number at the top?

Tags:

linux

vim

vi

I know it is possible to have vim open a file at particular line number using this syntax:

vim +500 filename 

However, I would like it to open with the specified line at the top of the editor window, not in the middle.

like image 636
stinkypyper Avatar asked May 01 '12 01:05

stinkypyper


People also ask

How do I go to a specific line number in Vim?

The Vim goto line number command One can use the G letter. For example, press [ESC] key and type 10G (Shift-g) goto line number 10.

How do I go to a specific line number in Linux?

To do this, press Esc , type the line number, and then press Shift-g . If you press Esc and then Shift-g without specifying a line number, it will take you to the last line in the file.


2 Answers

You could issue zt after opening the file, so something like: vim +500 filename -c 'normal zt'.

like image 82
Cat Plus Plus Avatar answered Sep 24 '22 02:09

Cat Plus Plus


As an alternative (because I ended up here searching for it), if you want to have the syntax vim <filename>:<linenumber>, eg vim test.rb:45, you can use vim-fetch with Vundle:

Plugin 'kopischke/vim-fetch' 
like image 44
Dorian Avatar answered Sep 23 '22 02:09

Dorian