Comment on page
Chapter 4: Some Tips
"Work well, must first sharpen his tools." Although Vim is very powerful, the default configuration of Vim looks relatively simple. In order to meet our development needs, we need to do some simple configuration to Vim.
:set numberdisplay line number
:set relativenumberdisplay relative line number (this is very important, slowly experience)
:set hlsearchsearch result highlight
:set autoindentautomatic indentation
:set smartindentsmart indentation
:set tabstop=4set tab tab width to 4
:set softtabstop=4set the width of the indentation when pressing
:set shiftwidth=4set the automatic indentation width to 4
:set expandtabindent tab to space
:filetype onopen file type detection
:syntax onopen syntax highlighting
Here are the commands that you can use to set up Vim, but the parameters set in this way only take effect before closing Vim this time. If you exit Vim and open it again, the previous settings will be invalid.
If you want to take effect permanently, you need to modify an automatic configuration file of Vim. The general file path is
/home/<user>/.vimrc(Linux system) or
/Users/<user>/.vimrc(Mac OS system)
If not, create a new one. Take Mac OS system as an example:
Execute the following command in the console, remember to press Enter at the end of each line
Now you have opened your Vim exclusive configuration file in Vim, copy the configuration mentioned above to your file, remember to delete the
:at the beginning of each lineAfter the modification is completed, execute
ZZto save and exit. When you enter Vim again, your configuration should take effectOf course, I have prepared a sample file vimrc for you. You can use it directly by executing
cp vimrc.vim ~/.vimrc, and start Vim again or execute
:source ~/.vimrcin Vim. Your configuration should take effect.
In the configuration mentioned above, there is an option to highlight all search results
:set hlsearch, its function is when you execute
#search and highlight all matching results.
If you have set this option, try executing
See the effect, the search results are clear at a glance, but this is sometimes a kind of trouble, because the highlight does not think so, it will always highlight, until you use
:set nohlsearchto turn it off.
But this requires you to turn it on when you need it, and turn it off when you don't need it. Is there a better solution? of course! See the ultimate answer below:
Search for a string that does not exist
Usually I use the command
/lfwto clear the search highlight. One is because the combination of
lfwis generally not available (not applicable to this document...), and the other is that the combination of these three letters is more comfortable to press, and the fingers basically do not need to move (you feel it).
Vim has a special command
., you can use it to repeat the last command.
Follow the instructions below to operate
Press dd to delete this line
Press . to repeat the delete operation
Press 2. to delete two more lines
This line is gone
Press p to paste it back
Press 3. to add 6 more lines
>>indent the current line to the right
<<indent the current line to the left
On this line, press
<Gin turn to see the effectGo to the soy sauce line
==automatic typesetting of the current line
gg=Gautomatic typesetting of the current document
<N>==automatic typesetting for N lines starting from the current line
=<N>jautomatic typesetting for the current line and N lines below
=<N>kautomatic typesetting for the current line and N lines above