【问题标题】:How to open a file at a specific line and column?如何在特定的行和列打开文件?
【发布时间】:2019-05-25 03:44:49
【问题描述】:

我正在开发一个模块,该模块需要在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 复制/粘贴到新的终端窗口中可以得到我想要的行为。

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

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

【问题讨论】:

    标签: bash perl vim exec


    【解决方案1】:

    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')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-02
      • 1970-01-01
      • 1970-01-01
      • 2019-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多