如何使用 c++ 执行 gvim 命令

How to execute gvim command using c++

本文关键字:gvim 命令 执行 c++ 何使用      更新时间:2023-10-16

我需要编写一个代码来跳转到gVim中的特定给定行号。但我需要使用C++来做到这一点。有什么办法吗?

有一些方法可以通过使用C++代码执行 Linux 命令来打开 gvim。但是有没有办法使用相同的C++代码执行 gVim 命令?

你的意思是运行 linux 命令的函数system吗?您可以将其用于任何命令和命令参数。波纹管就是例子,请根据您的要求进行修改。

int line_no = 576;
std::string file_name;
std::stringstream command;
command << "gvim +" << line_no << " " << filename;
system(command.str().c_str());

它将执行gvim +576 file_name,在 gvim 中的特定行打开一个文件。

您可以要求vim从命令行运行命令。请参阅 vim 命令行选项列表。

将光标定位在行上num运行vim +num filename,例如vim +578 filename跳转到命名文件中的第 578 行。 vim + filename跳到最后一行。

搜索:vim +/pattern filename将光标定位在包含"模式"的第一行。

其他命令:vim -c command filename执行 ex(: ( 命令。您最多可以运行 10 个命令(最多 10 个-c选项(。