Recently, the choice of the editor has been quite tangled. Vim was used at the beginning, because editing can be performed as long as it can be connected over ssh. Later, source in sight was used because it was very convenient to view the code; later, vs2010 was used because of its excellent support for tools such as SVN and code folding. However, in windows, vs2012 uses gb2132 encoding by default and cannot be changed to UTF-8, in Linux, all Chinese comments are garbled. But I secretly thought about how vim, a powerful tool, does not support code folding and SVN. So I decided to summarize the powerful functions of vim.
--------------------
0. The powerful functions of VIM mainly include plug-ins and VIM configuration files (~ /. Vimrc. First ~ In the/directory, create the. Vim/doc,. Vim/plugin, And. Vim/syntax directories. In addition, create ~ /. Vimrc configuration file.
I. Basic settings (including line number display, syntax highlighting, Tab conversion to space, code folding stool)
Note: The "" line in the configuration file is a comment
Vimrc -----------------------------------------
"Use Vim setting, rather than vi settings (much better !)
"This must be first, because it changes other options as a side effect.
Set nocompatible
"Show line numbers
Set number
"Syntax on
Syntax on
"Tab 2 Space
Set tabstop = 4
Set shiftwidth = 4
Vimrc -----------------------------------------
Ii. Code folding
You can use the "foldmethod" option to set the vim code folding method, for example, set foldmethod = indent.
There are 6 Ways to collapse the code
1. Manual // manually define the folding
2. indent // fold with indentation
3. expr // use an expression to define the fold
4. Syntax // use syntax highlighting to define collapse
5. Diff // fold Unchanged text
6. Marker // hide with a flag
Vim configuration files are divided into global configuration files and user configuration files.
1. Search for the global configuration file. In. Vim, enter echo $ vim, which is generally/usr/share/Vim/vimrc.
2. the user configuration file is in the user's home directory, for example,/home/abeen/. vimrc.
Set the folding mode in the vimrc file, for example, set foldmethod = indent.
After the folding mode is selected, you can use the folding command to perform the folding operation. The common folding modes are indent and marker.
Indent folding command
Indent mode. Vim automatically uses indentation for folding. We can use the ready-made folding results.
Enter the following command in the fold:
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.
Marker folding command
When the marker folding method is used, we need to use a tag to identify the code folding. The default value is {And }}}
Fold command
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.