根据文件类型更改Vim缩进行为 [英] Changing Vim indentation behavior by file type

查看:425
本文介绍了根据文件类型更改Vim缩进行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以根据文件类型向我解释简单的方法来更改vim的缩进行为吗?例如,如果我打开一个python文件,它将缩进2个空格,但如果我打开powershell它将使用4个空格。

解决方案

您可以添加 .vim 文件,以便在vim切换到特定文件类型时执行。



例如,我有一个文件〜/ .vim / after / ftplugin / html.vim 与此内容:

  setlocal shiftwidth = 2 
setlocal tabstop = 2

哪个导致vim使用宽度为2个字符的标签用于缩进(在我的配置中, noexpandtab 选项设置在其他地方)



这里描述: http://vimdoc.sourceforge.net/htmldoc/usr_05。 html#05.4 ,向下滚动到filetype插件的部分。


Could someone explain to me simply the easiest way to change the indentation behavior of vim based on the file type? For instance if I open a python file it would indent with 2 spaces, but if I open powershell it would use 4 spaces.

解决方案

You can add .vim files to be executed whenever vim switches to a particular filetype.

For example, I have a file ~/.vim/after/ftplugin/html.vim with this contents:

setlocal shiftwidth=2
setlocal tabstop=2

Which causes vim to use tabs with a width of 2 characters for indenting (the noexpandtab option is set globally elsewhere in my configuration).

This is described here: http://vimdoc.sourceforge.net/htmldoc/usr_05.html#05.4, scroll down to the section on filetype plugins.

这篇关于根据文件类型更改Vim缩进行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆