如何在特定的行和列打开文件?

How to open a file at a specific line and column?

我正在开发一个模块,该模块需要在 vim 中的任意行和列打开文件。我通过 exec() 执行此操作,但 vim 未获得正确的行和列:

如果我把它提炼成一行:

perl -E "exec(q{vim}, q{+'call cursor(1,3)'}, q{README.md})"

此错误为:

"README.md" 116L, 3790C
Error detected while processing command line:
E20: Mark not set
Press ENTER or type command to continue

vim显示此错误时,ps显示vim +'call cursor(1,3)' README.md,这是我想要的命令。事实上,copy/pasting vim +'call cursor(1,3)' README.md 进入新终端 window 给了我想要的行为。

在我看来,vim 认为行是 116 而不是 1,当命令是 运行 通过 Perl 的 exec() 时,列是 3790 而不是 3。 =21=]

这是 Perl 5.26.1、Vim8.1 和 GNU bash,版本 3.2.57(1)-release (x86_64-apple-darwin18)。

bash命令

vim +'call cursor(1,3)' README.md

没有区别
vim '+call cursor(1,3)' README.md

两者都使用以下参数启动 vim

0: vim
1: +call cursor(1,3)
2: README.md

但是,您指示 Perl 将以下参数传递给 vim

0: vim
1: +'call cursor(1,3)'
2: README.md

该 shell 命令的 Perl 等价物是

exec('vim', '+call cursor(1,3)', 'README.md')