Oeasy teaches you to play with VIM – 26 – indent settings

Time:2022-4-28

Indent settings

Recall the last lesson

  • This time I learned the details of color
  • Set 256 color mode

    • :set t_Co=256
  • Then the specific colors are determined
  • You can also generate web pages:TOhtml
  • Is there anything else interesting?

Oeasy teaches you to play with VIM - 26 - indent settings

Indent settings

Oeasy teaches you to play with VIM - 26 - indent settings

  • In normal mode

    • use<<Can indent forward
    • use>>You can indent backwards
    • =You can indent the current line automatically
  • useg g = G

    • You can automatically indent from the beginning to the end
  • It’s cool

display indent

  • We encounter indentation when programming

    • What is this indentationSpaceAnd? stilltabAnd?
    • To putSpaceandtabDistinguish
  • :set listMake the list effective

    • tabWill be displayed as^I
    • The end of the line displays$

Oeasy teaches you to play with VIM - 26 - indent settings

  • :set nolistInvalidate list

    • tabIs displayed as a space indent

Oeasy teaches you to play with VIM - 26 - indent settings

  • But it seems that the indentation looks like only two spaces
  • Inconsistent with reality
  • Can you modify it?

Custom tab display

  • Treat special characters aslistcharsThe group is displayed
  • :set listchars
  • set uplistchars
  • :set listchars=eol:$,tab:>-,space:_

    • tabcorresponding>-
    • >It’s the beginning
    • -Fill in the back

Oeasy teaches you to play with VIM - 26 - indent settings

  • spacecorresponding_
  • eolcorresponding$
  • :h listcharsYou can view the relevant manuals

Space color

  • :hi SpecialKey ctermfg=DarkRed guifg=grey70

    • set uplistcharsCorresponding color
    • Make it special

Oeasy teaches you to play with VIM - 26 - indent settings

Final effect

Oeasy teaches you to play with VIM - 26 - indent settings

  • It is recommended to use tab when it is available
  • Reduce file capacity

Oeasy teaches you to play with VIM - 26 - indent settings

Basics

  • The shiftwidth value is the basis for the entire indentation
  • :set shiftwidth=4

    • shiftwidthIs a basic value, corresponding to
    • Press>>Width of indent
    • PresstabWidth of indent
    • Backspace or delete\tWidth of indent when
  • commonlytabstopsofttabstopAll the same as him

    • Usually 4
    • IfshiftwidthIf it is 0
    • Just followtabstopcome

Width interpretation

  • tabstopyesread fileUsed in
  • get to read\tCharacter time
  • Explain how many spaces he corresponds to
  • Usually four spaces

Oeasy teaches you to play with VIM - 26 - indent settings

Softtabstop handles the number of spaces

  • IfsofttabstopEqual to 0

    • The feature is cancelled and everything is in accordance withtabstopcome
  • Iftabstop=4softtabstop=8

    • PresstabTime

      • Insert 8 positions at a time
      • It looks like two tabs are inserted
    • When you want to delete a tab

      • Delete 8 spaces at a time
      • It looks like two tabs have been deleted
    • You can try, you can see
  • When he’s negativeshiftwidthwork
  • SoshiftwidthIs the foundation

Oeasy teaches you to play with VIM - 26 - indent settings

Extension tab

  • :set expandtab

    • You can put the inputtabbecomeSpace
  • After setting, in normal mode

    • > >
    • Or in insert modetabWhen
    • I can’t see it>---Instead, it becomes a space directly_
  • conversely:set noexpandtabafter

    • InsertedtabAll or>---
  • :h expandtabYou can view the relevant manuals

    • expandtabCan be abbreviated aset

Oeasy teaches you to play with VIM - 26 - indent settings

  • What about the existing tabs?

Forced expansion

  • :retab!
  • Forcibly expand the existing tab into a space

Oeasy teaches you to play with VIM - 26 - indent settings

  • After turning around
  • There is no order to turn back
  • Be careful
  • I think tab is very good

Auto indent after enter

  • :set autoindent

    • Can be abbreviated as:set ai
    • Add indent consistent with the previous line
    • Cancel as:se noai
  • :set smartindent

    • Abbreviated as:se si
    • stayautoindentBased on{}To adjust the indent of the line
    • Cancel as:se nosi
    • Need guarantee:se nopaste
  • :set cindent

    • Dynamically adjust the indentation according to the code similar to C and Java
    • SeeifSomething like that can be indented automatically
    • Cancel as:set nocindent

Oeasy teaches you to play with VIM - 26 - indent settings

The overall setting is

  • :set noexpandtab
  • :set shiftwidth = 4
  • :set tabstop =4
  • :set softtabstop=4
  • :set autoindent
  • Abbreviated as:set noet sw=4 ts=4 sts=4 ai
  • It’s all personal preference
  • There is no absolute rule

summary

  • This time I learned about various ways of indentation
  • Used in normal mode<<indent
  • Used in insert modetabindent
  • There are parameters about the number of spaces corresponding to indentation

    • expandtab
    • shiftwidth
    • tabstop
    • softtabstop
    • autoindent
  • Can different file types correspond to different indents??

    • Python, Java indent 4
    • HTML and CSS can be indented by 2
  • Next time