Linux 如何在顶部打开带有特定行号的 vim?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10392424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:06:10  来源:igfitidea点击:

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

linuxvimvi

提问by stinkypyper

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

我知道可以使用以下语法让 vim 在特定行号处打开文件:

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.

但是,我希望它以编辑器窗口顶部的指定行打开,而不是在中间。

采纳答案by Cat Plus Plus

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

您可以zt在打开文件后发出,例如:vim +500 filename -c 'normal zt'.

回答by sehe

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

或者你可以开始使用zt(top), zz(center), and zb(bottom)的习惯;就我而言,它是如此自动,我真的不需要额外的调用参数

回答by Dorian

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-fetchwith Vundle:

作为替代方案(因为我最终在这里搜索它),如果您想要语法vim <filename>:<linenumber>,例如vim test.rb:45,您可以将vim-fetchVundle一起使用

Plugin 'kopischke/vim-fetch'