[英]How can I write a shortcut to compile and run a program in a separate terminal window in Vim?
I have this as a Sublime Text build system right now: It compiles a C++ program, then opens a new window in Terminal.app and runs it there upon pressing ctrl+b.我现在把它作为一个 Sublime Text 构建系统:它编译一个 C++ 程序,然后在 Terminal.app 中打开一个新窗口,并在按下 ctrl+b 后在那里运行它。
{
"shell_cmd": "g++-11 -std=c++20 '${file}' -o '${file_base_name}' && echo 'cd \"${file_path}/\"' > '/tmp/${file_base_name}' && echo './\"${file_base_name}\"' >> '/tmp/${file_base_name}' && echo read >> '/tmp/${file_base_name}' && chmod +x '/tmp/${file_base_name}' && open -a Terminal.app '/tmp/${file_base_name}'"
}
However, I'm not sure how I could get something in (Mac)Vim.但是,我不确定如何在 (Mac)Vim 中获得一些东西。 I've read some similar questions, but none of the ones I've seen mention opening in a separate terminal.
我读过一些类似的问题,但我见过的问题都没有提到在单独的终端中打开。
I've tried writing some shortcuts/commands to compile and run within Vim which mostly worked, but I would still rather my programs run in a separate window (edited).我已经尝试编写一些快捷方式/命令来在 Vim 中编译和运行,它们大多有效,但我仍然希望我的程序在单独的窗口中运行(已编辑)。
noremap <C-b> :!g++-11 %:p && ./a.out<CR>
希望neovim的这个插件可以帮到你: https : //github.com/michaelb/sniprun
You actually have a few options, so use whatever suits your needs the most.您实际上有几个选择,因此请使用最适合您需求的选择。
You can use vim's built in terminal :terminal
(or :term
; see :help :terminal
), which is probably the easier way:您可以使用vim 的内置终端
:terminal
(或:term
;请参阅:help :terminal
),这可能是更简单的方法:
:term g++-11 %:p && ./a.out<CR>
Or you can use :compiler
with :make
(see :help :compile
and :help 'makeprg'
):或者你可以使用
:compiler
和:make
(参见:help :compile
和:help 'makeprg'
):
:compiler gcc
:let $CXXFLAGS='-std=c++20 -Wall -Werror'
:make
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.