【问题标题】:How to open file in vscode from terminal with cursor at last line?如何使用光标在最后一行从终端打开vscode中的文件?
【发布时间】:2021-10-14 02:47:46
【问题描述】:

我正在开发 Ubuntu 20.04 LTS。 我写了一个 bash 脚本,它创建了一个带有样板行的 .sh 文件

#! /bin/bash
# 这个文件是由 create_script.sh 创建的

并在 vscode 中打开它。但是,当文件打开时,光标位于文件的开头。 我使用的命令是code $fname。 在$ code --help,我发现了以下内容

-g --goto <file:line[:character]> Open a file at the path on the specified line and character position.

所以我想我可以做到code -g $fname:3:1。 (我测试过并且有效) 但我想知道是否有一些选项可以在文件的最后一个字符处使用光标打开,这样我就可以对任何文件执行此操作,而无需使用 wc -l 之类的其他内容。我认为负索引会起作用,但它没有。

【问题讨论】:

  • 尝试“G”而不是行号。到 vi 中的最后一行。抱歉,我没有 linux 机器来测试它。
  • 它给了Warning: 'G' is not in the list of known options, but still passed to Electron/Chromium. 感谢您的回复。
  • 对不起,我帮不上忙。唯一的其他想法是将其设置为一个巨大的数字。只是为了测试。

标签: bash shell visual-studio-code scripting ubuntu-20.04


【解决方案1】:

这是gnodab给出的答案。 在选项-g file:line:character 中使用大量数字代替行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-15
    • 2022-07-15
    • 2020-12-24
    • 1970-01-01
    • 2023-03-17
    相关资源
    最近更新 更多