Oeasy teaches you to play VIM – 21 – status bar

Time:2022-5-4

Status bar

Recall the last lesson

  • We studied the ruler last time
  • Ruler

    • opense ru
    • closese noru
  • Line number

    • opense nu
    • closese nonu
  • Command location

    • opense showcmd
    • closese noshowcmd
  • Jump

    • use29 GJump line number
    • use19 |Jump column number
    • use29 %Skip to 29% of the entire file

Prepare the environment

#Download material
git clone http://github.com/overmind1980/vimtutorial.git
#Enter directory
cd vimtutorial
#Or start with the simplest vim
vi -u NONE oeasy.java

Set cursor line

  • Let’s look at a switch option
  • Cursor linecursorline

    • cursorcursor
    • that ‘s okline
  • :set cursorline

Oeasy teaches you to play VIM - 21 - status bar

  • h 'cursorline'

    • tocursorlineWith single quotation marks
    • explaincursorlineIs an attributeoption

Oeasy teaches you to play VIM - 21 - status bar

Set cursor column

  • There are rows and columns
  • Cursor linecursorcolumn

    • cursorcursor
    • that ‘s okcolumn
  • :set cursorcolumn

Oeasy teaches you to play VIM - 21 - status bar

  • h 'cursorcolumn'

    • tocursorcolumnWith single quotation marks
    • explaincursorcolumnIs an attributeoption

Oeasy teaches you to play VIM - 21 - status bar

Change the status bar below

  • With row and column position
  • Then cooperate with ruler
  • The cursor position is clear
  • stay:h rulerWhen
  • Accidentally found a Xintiandistatusline

    • statuslineStatus bar
    • On the penultimate line
    • statuslineIt’s also a good choicesetSomething
    • Let’s look at the manual
    • :h statusline
    • It seems that you can give it directlystatuslineassignment
    • I’ll give one directlyoeasy
  • :set statusline=oeasy
  • Then you need to setlaststatus

    • Setting laststatus = 0 does not explicitly state the line
    • Set laststatus = 1 to display the status line only when there are more than one window
    • Set laststatus = 2, always explicit status line
  • :set laststatus=2

What can I put on the statusline?

  • :h 'statusline'

Oeasy teaches you to play VIM - 21 - status bar

Display properties

  • Can I display some other properties besides string constants?

    • Continue to look through the help manual
    • Find relevantitems
    • variousitemsThere are different attributes (number, text, logo)
    • eachitemCorrespond to a letter
    • This letter needs to pass%To escape
    • FCorresponding file name
  • :set statusline=[oeasy]%F

    • The status bar is displayed[oeasy] current file name

Oeasy teaches you to play VIM - 21 - status bar

Flag attribute

  • Continue Flipping Properties

    • FlagIs the flag bit
    • mIs a flag bit about whether it has been modified
    • hold%mAdditional entrystatusline
  • :set statusline=[oeasy]%F%m
  • Unsaved files are displayed after modifying the file[+]

    • Observation effect
  • After saving[+]Will disappear

    • Watch in the dark

Oeasy teaches you to play VIM - 21 - status bar

Numeric attribute

  • Status bar details found

    • NrepresentativeNumberrepresentativeitemIs a numeric type
    • Line numberl, column numberc, percentagepAll numeric types
    • use[]Separate numerical variables
    • %%Can put%The escape is displayed
  • :set statusline=[oeasy]%F%m[%l,%c]%p%%

Oeasy teaches you to play VIM - 21 - status bar

  • The status bar value can also change with the cursor

Control width

Oeasy teaches you to play VIM - 21 - status bar

  • You can use format to control the width
  • %-0{MinWidth}.{MaxWidth}{item}
  • %-040.40FJust use40Fixed width display ofF
  • If it exceeds the range, the front part will be hidden
  • :set statusline=[oeasy]%-040.40F%m[%l,%c]%p%%
  • One line total80character
  • What about the back part?

Group

Oeasy teaches you to play VIM - 21 - status bar

  • We can combine rows and columns into oneitems group
  • use()To encapsulate this group

    • use%yes()Escape
    • :set statusline=%([%l,%c]%)
    • In this way, the width of this ruler group can be set uniformly
    • :set statusline=%-010.10([%l,%c]%)

      • The width of the ruler group is fixed to 10
  • Similarly, the file name and whether the file is modified can also be grouped

    • :set statusline=%(%F%m%)

Final integration

Oeasy teaches you to play VIM - 21 - status bar

  • The final integration is divided into three parts

    • file%-040.40(%F%m%)
    • Ruler%-030.30([%l,%c]%)
    • proportion%p%%
  • There is also a master switch on the status bar

    • :set laststatus=0close
    • :set laststatus=2open

summary

  • We learned the status bar this time

    • Expressed by escapeitem
    • controlitemWidth method
    • takeitemGroup approach
    • There is also a main switchlaststatus
  • But it’s troublesome to write a long paragraph to configure every time
  • Can we write a configuration file so thatvimHow about automatic configuration every time?
  • Next time