Vim configuration details, VIM setting code folding

Source: Internet
Author: User

Vim configuration details

 

1. VIM configuration file

1. How should VIM be set to allow users to define their own configurations to display text? The two configuration files will be read during the running of VIM.
(1) The ". exrc" configuration file under the Home Directory, which takes effect for users in the Home Directory (personal)
(2)/etc/vimrc configuration file, which takes effect for all users (global)

2. The following describes how to configure VIM in user-defined mode. The configuration steps are as follows:

1) Step 1: create a new one named "under your home directory (/home/XXX".Exrc files
[Root @ Mylinux ~] Touch. exrc

2) Step 2: Open ". exrc" in the vim editor and write related Vim configuration options. Common configurations are shown in the following table.
[Root @ mylinux ~] Vim. exrc

VimCommon configuration options of configuration files

Set nocompatible

Do not use the VI keyboard mode, but Vim's own

Syntax on

Highlight the syntax

Set history = 100

Number of lines to be recorded in the history file

Set nobackup

I'm not used to having one more ~ Suffix backup file

Set autoindent shiftwidth = 4

Enable auto indent and set the auto indent width to 4

Set background = dark

Highlight a dark font (for example, comment)

Set incsearch

When searching, the entered words are highlighted by characters

Set hlsearch

Highlight the searched string (nohlsearch can be disabled)

Set tabstop = 4

Change the tab to a 4-character width.

Set shiftround

Use> or <to adjust the width according to shiftwidth

Set nu

Show row number

Set encoding = UTF-8

Display the encoding used (depending on the "Lang environment variable ")

Set fileencodings = UTF-8, Latin1

The sequence in which Vim attempts to automatically determine the encoding of Files
(Note: The Vim encoding used when writing files should not be in vimrc or. in exrc, VIM automatically sets this variable based on the judgment result after the file is loaded. This variable is modified and saved only when you want to convert the storage encoding of the file)

Set termencoding = UTF-8

Encoding type used for output to client terminal (TERM)

Set ambiwidth = double

Display Chinese Characters in two widths

Set clipboard + = unnamed

Share clipboard with windows

Filetype on

Detect file types

Filetype plugin on

Load file type plug-in

Filetype indent on

Load indent files for a specific file type

Set iskeyword + =_, $, @, % ,#,-

Do not separate words with the following symbols by line breaks

Set laststatus = 2

Always display status bar

Set statusline = % F % m % r % h % w/[POS = % l, % v] [% p %] // Encoding: /% {(& fenc = /"/")? & Enc: & fenc }%{ (& bomb? /"[BOM]/":/"/")} // % {strftime (/"% Y-% m-% d/-/% H: % M /")}

Content displayed in the VIM status line (including file type and decoding)

Set smartindent

Provides automatic indentation for C Programs

Set cindent

Use a C-style indent Scheme

Set ignorecase

Set list

Case Insensitive during search
Display the tab (ctrl + I) and the end of the line sign ($)

Colorscheme desert
Colorscheme evening
Colorscheme default

Vim Color Scheme

 

========================================================== ==================================

========================================================== ==================================

 

 

1. Folding Mode 
You can use the 'foldmethod' option to set the foldmethod: Set OFDM = *****.
There are 6 Ways to select the fold:
Manual manual definition folding
More indent indicates more fold
Expr uses expressions to define collapse
Syntax uses syntax highlighting to define collapse
Diff folds Unchanged text
Marker folds the mark in the text
Note that each folding method is incompatible. If expr is not used and marker is used, the indent and marker modes are used in turn.

When using this function, use the: set OFDM = marker command to set it to the marker foldmethod ).
To make the folding take effect every time vim is opened, add the settings in the. vimrc file, such as adding: set OFDM = syntax, just like adding other initialization settings.

2. Fold command
After the folding method is selected, we can implement the folding we need for some code. Because I use more indent and marker, their usage is used as an example:
If the indent method is used, vim automatically folds the middle part of the braces, and we can directly use these ready-made folding results.
In a foldable place (in the middle of braces ):
Zc folding
ZC folds all nested folding points in the range
Zo unfold and fold
ZO expands all nested folding points in the range
[Z to the start of the current fold.
] Z to the end of the currently opened fold.
Zj moves down. To the start of the next fold. The closed folding is also included.
Zk moves up to the end of the previous fold. The closed folding is also included.

When using the marker method, you need to use a tag to identify code folding. The default value of the system is {And}. Do not change it :)
We can use the following command to create and delete a fold:
Zf creates a fold, for example, in the marker mode:
Zf56G: Creates code folding from the current row to 56 rows;
10zf, 10zf +, or zf10 labels, create code folding from the current row to the last 10 lines.
10zf-or zf10 labels, create code folding from the current row to the previous 10 lines.
At ZF %, create the matching brackets (), {}, [], <>, etc.) from the current row ).
ZD Delete is the folding of the cursor. Valid only when 'foldmethod' is set to "Manual" or "marker.
ZD loop Delete refers to the folding under the cursor, that is, nesting Delete fold.
Valid only when 'foldmethod' is set to "Manual" or "marker.
Ze removes all folds in the (eliminate) window.
Valid only when 'foldmethod' is set to "Manual" or "marker.

 

 

========================================================== ======

Embellishment entertainment

========================================================== ======

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.