Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Vim configuration


May 24, 2021 Vim


Table of contents


Configuration

The user profile is ~/.vimrc the relevant file is at ~/.vim/ the /etc/vimrc the /usr/share/vim/

If you need common features such as highlighting the syntax, going back to the last cursor position when opening a file, and so /etc/vimrc

/etc/vimrc/
...
runtime! vimrc_example.vim

Grammar highlights

Enable syntax highlighting (Vim supports syntax highlighting in many languages):

:filetype plugin on
:syntax on

The line-up is displayed

wrap is turned on by default, which causes Vim to automatically display the unseeded text to the next line when the length of one line of text exceeds the width of the window. wrap affects the display of the text, and the text itself is not changed.

Line-changing displays the last character that typically fits under the line window, even if it happens to be in the middle of a word. S marter line break displays can be linebreak W hen set linebreak the line break occurs after the characters listed in the string option breakat By default, breakat contains spaces and some punctuation :help breakat

The newer characters typically start at the beginning of the next line without any corresponding indentation. [ breakindent] I ndicates that Vim will take indentation into account when new lines are new, so that the new line will have the same indentation as the text that was intended to be displayed. breakindent behavior breakindentopt for example, in the Python file, the new line will indent four more spaces on top of the original indentation :help breakindentopt

autocmd FileType python set breakindentopt=shift:4

Use the mouse

Vim can use the mouse, but only works on some terminals (xterm on Linux and Linux console with gpm, see console support for more details):

Turn this on and add the following line of code ~/.vimrc

set mouse=a

Attention:

  • This method is also applicable in PutTY using SSH.
  • In PutTY, the normal highlight/copy behavior is different because Vim enters visual mode when using the mouse. In order to select a Chinese mouse, you need to hold down shift at Shift time.

Move the cursor across lines

By default, pressing → at the end a line cannot move the cursor to the top or next line.

To change the default behavior, add set whichwrap=b,s,<,>,[,] your file of ~/.vimrc