Vim可以在文件中保留四个空格的同时显示两个空格以进行缩进吗? [英] Can Vim display two spaces for indentation, while keeping four spaces in the file?

查看:91
本文介绍了Vim可以在文件中保留四个空格的同时显示两个空格以进行缩进吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从事其他人的项目,他使用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个空格
  • 将光标隐藏在常规,可视和插入模式下隐藏的文字
  • 启用隐藏一个字符的文字

您仍然必须将tabstopsofttabstopshiftwidth设置为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:

  1. 删除隐藏规则:syntax clear spaces
  2. 允许隐藏的文本在光标:set concealcursor=
  3. 下展开
  1. Remove conceal rule :syntax clear spaces or
  2. Allow concealed text to be expanded under the cursor :set concealcursor=

这篇关于Vim可以在文件中保留四个空格的同时显示两个空格以进行缩进吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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