从 gVim 打开终端
Open terminal from gVim
我想知道是否有一种方法可以在 gVim 中编译一个 c++ 文件,然后通过按下按钮将其 运行 并打开一个带有相应 cpp .out 文件的终端。
现在我的 .vimrc 中有这两行用于编译和 运行ing:
map <F5> :<C-U>!g++ -O2 -DLOCAL -std=c++11 -Wall -Wextra -Wno-unused-result -static %:r.cpp -o %:r<CR>
map <F9> :<C-U>!./%:r<CR>
但是当我按 F9 时,它 运行 是我在 gVim 中的脚本,我希望它在 linux 终端上打开。
你可以改变
map <F9> :<C-U>!./%:r<CR>
至
map <F9> :<C-U>!x-terminal-emulator -e ./%:r -hold<CR>
事实上,您可以使用任何您喜欢的终端。只需检查如何将命令传递到终端即可。在大多数情况下,它是 -e
.
-hold
是为了防止终端消失
要获得更多见解,请阅读 How can I make a script that opens terminal windows and executes commands in them?
你的映射看起来像 20 岁左右。您可能不希望映射在可视模式下工作。它们最好限制在正常模式下,是 nore-mappings,而且,vim 从一开始就集成了编译(与 vi 不同),参见 :h quickfix
.
希望您安装了正确版本的 gnumake(所有 Linux 系统,而不是 mingw),您可以简单地使用
" I wouldn't let no-unused-result out, nor use -static... but this is your choice
:let $CXXFLAGS = '-O2 -DLOCAL -std=c++11 -Wall -Wextra -Wno-unused-result -static'
" You also have $CFLAGS for C, $FFLAGS for Fortran (IIRC)...,
" and $LDFLAGS and $LDLIBS for libraries.
nnoremap <silent> <F5> :<c-u>make %<<cr>
" Also, you can use vim integrated terminal now
" or any other terminal, see vikram's answer
nnoremap <silent> <F9> :<c-u>vert term ./%<<cr>
我想知道是否有一种方法可以在 gVim 中编译一个 c++ 文件,然后通过按下按钮将其 运行 并打开一个带有相应 cpp .out 文件的终端。
现在我的 .vimrc 中有这两行用于编译和 运行ing:
map <F5> :<C-U>!g++ -O2 -DLOCAL -std=c++11 -Wall -Wextra -Wno-unused-result -static %:r.cpp -o %:r<CR>
map <F9> :<C-U>!./%:r<CR>
但是当我按 F9 时,它 运行 是我在 gVim 中的脚本,我希望它在 linux 终端上打开。
你可以改变
map <F9> :<C-U>!./%:r<CR>
至
map <F9> :<C-U>!x-terminal-emulator -e ./%:r -hold<CR>
事实上,您可以使用任何您喜欢的终端。只需检查如何将命令传递到终端即可。在大多数情况下,它是 -e
.
-hold
是为了防止终端消失
要获得更多见解,请阅读 How can I make a script that opens terminal windows and executes commands in them?
你的映射看起来像 20 岁左右。您可能不希望映射在可视模式下工作。它们最好限制在正常模式下,是 nore-mappings,而且,vim 从一开始就集成了编译(与 vi 不同),参见 :h quickfix
.
希望您安装了正确版本的 gnumake(所有 Linux 系统,而不是 mingw),您可以简单地使用
" I wouldn't let no-unused-result out, nor use -static... but this is your choice
:let $CXXFLAGS = '-O2 -DLOCAL -std=c++11 -Wall -Wextra -Wno-unused-result -static'
" You also have $CFLAGS for C, $FFLAGS for Fortran (IIRC)...,
" and $LDFLAGS and $LDLIBS for libraries.
nnoremap <silent> <F5> :<c-u>make %<<cr>
" Also, you can use vim integrated terminal now
" or any other terminal, see vikram's answer
nnoremap <silent> <F9> :<c-u>vert term ./%<<cr>