简体   繁体   English

Gvim不写标签

[英]Gvim does not write tabs

In C++ files that I edit with Gvim I have noticed that code lines which are in inside blocks 在我用Gvim编辑的C ++文件中,我注意到内部块中的代码行
(curly braces {}) (大括号 {})
although are being shown on the screen with the correct amount of tabs in Gvim 尽管在屏幕上显示的是Gvim中正确数量的选项卡
(ie plus one tab from the code which is outside of this code block) (即在此代码块之外的代码中加上一个标签)
when I open the same files with an another editor like sublime text 当我使用另一个编辑器(如sublime text)打开相同的文件时
that extra tab that must exist in every line inside the code block does not exist. 在代码块内的每一行中必须存在的额外选项卡不存在。
So after opening these files with a hex editor I noticed that Gvim does not write those extra tabs in the code blocks? 因此,使用十六进制编辑器打开这些文件后,我注意到Gvim不在代码块中写入了那些额外的选项卡吗?

Why does this happen? 为什么会这样? Is it because of cindent? 是因为碰碰运气吗? Also how can I fix this rather than auto-reformat every time? 另外,如何解决此问题,而不是每次都自动重新格式化?

I am pretty sure that vim will faithfully save all the characters that are in the buffer. 我很确定vim会忠实地保存缓冲区中的所有字符。 Various options affect how tabs are displayed, and whether actual tab characters or spaces are used for indenting. 各种选项会影响选项卡的显示方式以及是否使用实际的选项卡字符或空格进行缩进。 You can check their values, and see where they were set (default, in your vimrc file, or by some plugin) with 您可以检查它们的值,并查看它们的设置位置(默认值,在vimrc文件中还是通过某些插件),方法如下:

:verbose set ts? sts? et? sw? sta? ci? pi?

(These and more related options are grouped together if you open an options window with :options and look at Section 15.) If you want to visually check where you have tab characters rather than spaces, you can :set hls and then search for tab characters (or :match Search '\\t' ) or you can :set list . (如果使用:options打开选项窗口并查看第15节,则这些和更多相关选项组合在一起。)如果要直观地查看具有制表符而不是空格的位置,则可以:set hls然后搜索制表符字符(或:match Search '\\t' ),也可以:set list

If you try all that and you still think that vim is not saving what is in the buffer, then there are odd things to check, like whether you have any BufWrite or related autocommands. 如果您尝试了所有这些操作,但仍然认为vim没有保存缓冲区中的内容,那么您将需要检查一些奇怪的事情,例如是否有任何BufWrite或相关的自动命令。

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

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