我正在开发一个模块,它需要在 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
,其中是我想要的命令。事实上,将 vim +'call cursor(1,3)' README.md
复制/粘贴到新的终端窗口中可以得到所需的行为。
在我看来,当命令通过 Perl 的 exec()
运行时,vim
认为行是 116 而不是 1,列是 3790 而不是 3 .
这是 Perl 5.26.1、Vim 8.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: +'调用游标(1,3)'
2: README.md
该 shell 命令的 Perl 等价物是
exec('vim', '+call cursor(1,3)', 'README.md')
关于bash - 如何在特定的行和列打开文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56301513/