Vim可以在文件中保留四个空格的同时显示两个空格以进行缩进吗? [英] Can Vim display two spaces for indentation, while keeping four spaces in the file?
问题描述
我想从事其他人的项目,他使用4个空格进行缩进.我使用2,但屏幕不够大,无法舒适地使用4个空格进行编辑.
I want to work on someone else's project, and he uses 4 spaces for indentation. I use 2, and my screen is not big enough to edit using 4 spaces comfortably.
我可以将Vim配置为显示2个缩进空间,但在文件中写入4个吗?
Can I configure Vim to display 2 spaces for indentation, but write 4 to the file?
推荐答案
Yes, you can! If you have the "conceal" option, you can try this out.
:syntax match spaces / / conceal cchar= "Don't forget the space after cchar!
:set concealcursor=nvi
:set conceallevel=1
以下是这些命令的作用:
Here are what these commands do:
- 将2个空格的替换字符设置为1个空格
- 将光标隐藏在常规,可视和插入模式下隐藏的文字
- 启用隐藏一个字符的文字
您仍然必须将tabstop
,softtabstop
和shiftwidth
设置为4
,但是看起来和感觉就像2
!但是,当您写入文件时,它实际上是4
.
You still have to set your tabstop
, softtabstop
and shiftwidth
to 4
, but it looks and feels like it is 2
! However, when you write the file, it's really 4
.
如果要关闭隐藏,可以执行以下两项操作之一:
If you want to turn concealment off you can do one of two things:
- 删除隐藏规则
:syntax clear spaces
或 - 允许隐藏的文本在光标
:set concealcursor=
下展开
- Remove conceal rule
:syntax clear spaces
or - Allow concealed text to be expanded under the cursor
:set concealcursor=
这篇关于Vim可以在文件中保留四个空格的同时显示两个空格以进行缩进吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!