Can Vim display two spaces for indentation, while keeping four spaces in the file?

前端 未结 3 448
一生所求
一生所求 2021-02-07 13:54

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.

Can I confi

3条回答
  •  猫巷女王i
    2021-02-07 14:04

    This is the opposite of what was asked here.

    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:

    • Set the replacement character for 2 spaces to 1 space
    • Keep text under cursor concealed for normal, visual, and insert modes
    • Enable concealing text with one character

    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. Remove conceal rule :syntax clear spaces or
    2. Allow concealed text to be expanded under the cursor :set concealcursor=

提交回复
热议问题