vim 编辑模式 - 如何打开文件并转到行号 [英] vim edit mode - How to open a file and go to a line number
问题描述
在编辑模式下,如何指定 vim 转到特定行(比如 67)?以下命令将行号视为文件名.
In edit mode, how do I specify vim to go to a specific line(say 67)? The following command treats line number as file name.
:e /tmp/foo 67
我知道如何在启动 vim 时执行此操作,但是当您已经在编辑其他文件的会话中时,这很不方便.
I know how to do this when starting vim, but that's incovenient when you're already inside an editing session with other files.
vim /tmp/foo +67
推荐答案
虽然完全正确且规范(请参阅 :help +cmd
),但 OP 将行号放在文件名之前的解决方案从未感觉到对我来说是正确的,因为它不符合我的想法:目录 >文件 >线.
While perfectly correct and canonical (see :help +cmd
), OP's solution of putting the line number before the file name never felt right to me because it doesn't map with how I think: directory > file > line.
因此,我更喜欢这样做:
Therefore, I prefer to do:
:e /tmp/foo|67
让我先处理文件,然后处理行,这对我来说更直观.
which lets me deal with the file first, then with the line, which is much more intuitive to me.
请注意,:e +67/tmp/foo
和 :e/tmp/foo|67
在底层做了完全相同的事情:
Note that both :e +67 /tmp/foo
and :e /tmp/foo|67
do exactly the same thing under the hood:
:e /tmp/foo
:67
这篇关于vim 编辑模式 - 如何打开文件并转到行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!