在正常情况下,我使用 vim 的 make 实用程序,我会将 makeprg 设置为我当前正在工作的项目的 Makefile。由于通常该项目会持续数周甚至更长时间,因此我不需要经常更改 makeprg 的设置。但有时我需要编写一些“foobar”代码来练习我的 c++ 技能或在脑海中对一些原始想法进行原型(prototype)设计。因此,每当我切换到 vim 使用的“foobar”模式时,我需要注释原始 makeprg 设置添加新设置如下:
au FileType c set makeprg=gcc\ %
au FileType cpp set makeprg=g++\ %
这真的非常非常不方便。当我回到vim使用的“正常项目模式”时,我需要改回原来的设置。来回 ....
我想从你们那里知道的是:是否可以临时进行makeprg的设置。例如,定义一个函数,其中首先设置makeprg的本地值,然后在返回之前调用make,函数调用会自动将makeprg恢复为函数调用之前的值。
最佳答案
这并不完全符合您的要求,但您只能将选项设置为缓冲区。这样你就不必费心包装你的函数了;只需更改makepgrp
本地在您想要的特定文件上。
*:setl* *:setlocal* :setl[ocal] ... Like ":set" but set only the value local to the current buffer or window. Not all options have a local value. If the option does not have a local value the global value is set. With the "all" argument: display all local option's local values. Without argument: Display all local option's local values which are different from the default. When displaying a specific local option, show the local value. For a global/local boolean option, when the global value is being used, "--" is displayed before the option name. For a global option the global value is shown (but that might change in the future). {not in Vi}
au FileType c setl mp=gcc\ %
au FileType cpp setl mp=g++\ %
关于vim - 如何在vim中临时设置makeprg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2405052/