加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何在Vim中更改制表位后避免缩进错误?

发布时间:2020-12-16 01:53:44 所属栏目:安全 来源:网络整理
导读:我曾经在Vim中有8个空格的标签.然后我改为4个空格,但是现在每当我在更改为4个空格之前添加一行代码时,它会给我一个缩进不匹配错误,即使所有内容都很好地排列.有什么方法可以避免这个问题吗? 解决方法 你有没有改变tabstop选项? 我使用了4个空格(当我点击ta
我曾经在Vim中有8个空格的标签.然后我改为4个空格,但是现在每当我在更改为4个空格之前添加一行代码时,它会给我一个缩进不匹配错误,即使所有内容都很好地排列.有什么方法可以避免这个问题吗?

解决方法

你有没有改变tabstop选项?

我使用了4个空格(当我点击tab时填充空格,插入实际的tab命中ctrl-v标签).以下是.vimrc中与标签相关的设置:

" tabs
set tabstop=4
set shiftwidth=4
set expandtab

当您使用空格填充制表符时,您将始终插入空格而不是制表符,并且您的代码将始终看起来相同.

当您使用制表符时,每个工具都会以不同的方式显示制表符,您最终会花时间设置应为制表符(8,4,3.5)显示多少空格,而不是进行高效工作.

或者选择其中一个(来自vim 7.1 help tabstop):

Note: Setting 'tabstop' to any other value than 8 can make your file
    appear wrong in many places (e.g.,when printing it).


    There are four main ways to use tabs in Vim:
    1. Always keep 'tabstop' at 8,set 'softtabstop' and 'shiftwidth' to 4
       (or 3 or whatever you prefer) and use 'noexpandtab'.  Then Vim
       will use a mix of tabs and spaces,but typing <Tab> and <BS> will
       behave like a tab appears every 4 (or 3) characters.
    2. Set 'tabstop' and 'shiftwidth' to whatever you prefer and use
       'expandtab'.  This way you will always insert spaces.  The
       formatting will never be messed up when 'tabstop' is changed.
    3. Set 'tabstop' and 'shiftwidth' to whatever you prefer and use a
       |modeline| to set these values when editing the file again.  Only
       works when using Vim to edit the file.
    4. Always set 'tabstop' and 'shiftwidth' to the same value,and
       'noexpandtab'.  This should then work (for initial indents only)
       for any tabstop setting that people use.  It might be nice to have
       tabs after the first non-blank inserted as spaces if you do this
       though.  Otherwise aligned comments will be wrong when 'tabstop' is
       changed.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读