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

LinuxVimVi

Linux Problem Overview


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.

Linux Solutions


Solution 1 - Linux

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

Solution 2 - Linux

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'

Solution 3 - Linux

This should do it:

vim +'500|norm! zt' filename

Or you could just start the habit of using zt (top), zz (center), and zb (bottom); In my case, it is so automatic, I wouldn't really require the extra invocation argument

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionstinkypyperView Question on Stackoverflow
Solution 1 - LinuxCat Plus PlusView Answer on Stackoverflow
Solution 2 - LinuxDorianView Answer on Stackoverflow
Solution 3 - LinuxseheView Answer on Stackoverflow