vim - 如何在vim中临时设置makeprg

标签 vim

在正常情况下,我使用 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/

相关文章:

macos - vim 插入模式下的箭头键

vim - 在 vimrc 中使用 autocmd 进行多重高亮

vim - Vim 中的 TextMate 评论横幅

vim - 在vim中进行屏幕滚动

vim - 在 Tmux 中向 Vim 发送 Ctrl-Right

python - Python 的 Vim 语法高亮 'else:'

vim - tmux 和 Vim : Escape key being seen as ^[ and having long delay

vim 键映射到现有键

vim - E490 : No fold found in unix for vim

vim - 作为一个 vimer,我如何在搜索时禁用 cscope 跳转到 quickfix 列表中的第一个错误?