简体   繁体   English

我在.vimrc中有空格时的Makefile选项卡

[英]Makefile tabs when I have spaces in .vimrc

So in my .vimrc file, I have my tabs set to 2 spaces. 因此,在我的.vimrc文件中,我的选项卡设置为2个空格。 I know that the Makefile doesn't like this and what I have been doing is temporarily deleting the .vimrc conditions I have and editing the Makefile and then adding everything back to the .vimrc file. 我知道Makefile不喜欢这样,我一直在做的是暂时删除自己拥有的.vimrc条件并编辑Makefile,然后将所有内容重新添加到.vimrc文件中。 Is there any way I can use vim on the Makefile edit it without having to do all the changes? 有什么方法可以在Makefile上使用vim进行编辑,而不必进行所有更改? My Makefiles are very simple. 我的Makefile非常简单。 Like here below 像下面这样

all: main.cpp
  g++ -g -Wall main.cpp

Here is my .vimrc 这是我的.vimrc

set number
colorscheme ron 
set expandtab
: filetype on
: syntax on
: filetype indent on
set tabstop=2
set shiftwidth=2

You're missing out on Vim's :help filetype-plugin functionality. 您会错过Vim的:help filetype-plugin功能。 If you put 如果你把

:filetype plugin on

(you can combine all filetype commands from your ~/.vimrc as one :filetype indent plugin on ), and assuming your Makefile has a regular name so that it is detected (or you manually :setfiletype make ), this will load buffer-local settings from $VIMRUNTIME/ftplugin/make.vim , which contains these indent settings: (您可以将~/.vimrc所有文件类型命令组合为一个:filetype indent plugin on ),并假设您的Makefile具有常规名称以便可以检测到(或手动:setfiletype make ),这将加载本地缓冲区$VIMRUNTIME/ftplugin/make.vim设置,其中包含以下缩进设置:

" Make sure a hard tab is used, required for most make programs
setlocal noexpandtab softtabstop=0

If you explicitly don't want the filetype plugin feature (but be aware that any built-in option can be tweaked via user-configuration ( :help after-directory ), and the defaults are useful in general), you could emulate this setting via :autocmd in your ~/.vimrc , too: 如果您明确不想使用文件类型插件功能(但是请注意,可以通过用户配置( :help after-directory )来调整任何内置选项,并且默认情况下通常有用),则可以模拟此设置也通过:autocmd~/.vimrc

autocmd FileType make setlocal noexpandtab softtabstop=0

I think that setting your editor properly is the correct answer. 我认为正确设置编辑器是正确的答案。 However I'll just point out that if you use GNU make 3.82 or higher you could change the recipe introduction character from a TAB to something else using .RECIPEPREFIX as in: 但是,我只是指出,如果您使用GNU make 3.82或更高版本,则可以使用.RECIPEPREFIX将配方介绍字符从TAB更改为其他内容,如下所示:

.RECIPEPREFIX = |

all: main.cpp
| g++ -g -Wall main.cpp

As per the docs the prefix must be a single character, it cannot be a string. 根据文档,前缀必须为单个字符,不能为字符串。

您可以在您的Makefile中添加vim modeline,作为第一行或最后一行:

# vim: set noexpandtab:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM