Oeasy teaches you to play VIM – 22 – configuration file

Time:2022-5-3

configuration file

Recall the last lesson

  • We learned about the status bar last 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?

Oeasy teaches you to play VIM - 22 - configuration file

configuration file

#First, open the original configuration file, ~ representing the user folder
vi ~/.vimrc
#You can find the writing method of the status bar with / statusline

Oeasy teaches you to play VIM - 22 - configuration file

~/.vimrc

  • Can be found~/.vimrcnamelyviofconfiguration file
  • If this configuration file cannot be foundviWhat will it look like?
  • try!
#Rename the original configuration file
mv ~/.vimrc ~/.vimrc_old
#Rewrite configuration file
vi ~/.vimrc

Write configuration file

  • After the configuration file is empty

    • All configuration information is lost
    • It doesn’t matter. Write from scratch
  • First, set a status bar in~/.vimrcWrite two sentences inside

    • set statusline=oeasy
    • set laststatus=2
    • Note that not here:Yes
  • Keep and exit
  • Re editvi ~/.vimrc
  • The status bar has been found to be effective
  • Update status bar

    • set statusline=%-040.40(%F%m%)%-030.30([%l,%c]%)%p%%
    • set laststatus=2
    • set ru nu sc

Oeasy teaches you to play VIM - 22 - configuration file

  • :h optionsQuery more practical switches

Various practical switches

  • set numberset number
  • set relativenumberShow relative line numbers
  • set cursorlineHighlight the current line where the cursor is
  • set cursorcolumnHighlight the current line where the cursor is
  • set nocompatibleusevimMode, not withVicompatible
  • syntax onTurn on syntax highlighting
  • set showmodeThe current mode is displayed at the bottom
  • set showcmdIn command mode, the typing instructions are displayed at the bottom
  • set mouse-=aPure keyboard operation
  • set encoding=utf-8Using UTF-8 encoding
  • set autoreadAfter the hard disk file changes, it will be read automatically
  • Store these in~/.vimrcAfter that, these configurations will work automatically in the future
  • You can also gogithubsearch.vimrcFind out more about configuration

Query switchoptiondetails

  • Help for querying a setting can be enclosed in single quotes

    • :h 'number'Can findnumberRelated settings
    • :h 'mouse'Can findmouseRelated settings
    • :h 'autoread'Can findautoreadRelated settings

Oeasy teaches you to play VIM - 22 - configuration file

Final setting

  • set statusline=%-040.40(%F%m%)%-030.30([%l,%c]%)%p%%
  • set laststatus=2
  • set ruler
  • set number
  • set showcmd
  • set nocompatible
  • set showcmd
  • set showmode
  • set history=100
  • Can you spell out what they mean?

summary

  • Locate the location of the configuration file~/.vimrc

    • Understand various configuration switches
    • Modify configuration file and apply
  • But how is this color configured?
  • Next time

Recommended Today

Generation of GUIDs in the database

GUID, namely Globally Unique Identifier (Globally Unique Identifier) ​​is also known as UUID (Universally Unique IDentifier). GUID is a digital identifier with a binary length of 128 bits generated by a specific algorithm to indicate the uniqueness of a product. GUIDs are primarily used in networks or systems with multiple nodes, multiple computers, to assign […]