First, Introduction
1. Vim is a powerful text editor, if used skillfully, will effectively help us improve the efficiency of editing text, programs. Vim Editor's use of the threshold is relatively high, many people are afraid to remember a lot of orders, often in the early stages of learning to be deterred.
2. Vim learning requires constant practice and use, only forcing itself to use constantly, in order to remember those seemingly complex commands in the process of use, but if you get used to Vim's editing mode, you will feel that vim will really help us improve the efficiency of text editing.
3. For VIM learning materials, its own VIM help documentation is plentiful enough to be continuously consulted during the learning process. In addition, there is a simplified starting document that is vimtutor, in the command line input vimtutor, you can start to learn, probably less than one hours to learn and practice.
Second, the configuration
1. The configuration file of Vim has global configuration (generally in directory/ETC/VIM/VIMRC) and personal configuration (/HOME/USERNAME/.VIMRC), the global profile is effective for all users of the system. Personal profile is only valid for user's own usage environment
2. The configuration file of vim usually has the configuration that someone else has already set up, can copy to own personal profile directly to use, also can customize own use environment according to need
Third, configuration script
1. In the previous use of the process, I have a reference to personal needs to configure a copy of their own configuration script, most of which are annotated, can be configured as needed. Note: "Start with comments in VIMRC
Set Termencoding=utf8
set hlsearch
"line number
Set Nu
" syntax highlighting
syntax on
"Enable mouse
Set mouse=v
" Auto Indent
Highlight Column
Set cursorcolumn
Highlight current line
Set Cursorline
"Highlight current line
" Hi cursorline cterm=none ctermbg= Magenta Ctermfg=white guibg=darked guifg=white
Set autoindent
"set guifont=monaco:h80" font && font size
" Get rid of nasty about VI consistency mode, avoid some bugs and limitations of previous version
set Nocompatible
"based on the above alignment format, intelligent selection of the way, for similar C language writing is very useful for
set smartindent
" Set indent
Set tabstop=4
Set softtabstop=4
Set shiftwidth=4
"show the command being entered in the status bar
set ShowCmd
" displays the current vim mode in the lower left corner
Set Showmode
"code collapse
Set foldenable
Set foldmethod=indent
Set foldlevel=99
" show ruler
set ruler
" Open the file type Auto-detect feature
filetype on
set Completeopt=longest,menu
"Start auto complete
" filetype plugin indent on
"Move between split windows
: Nnoremap <C-h> <c-w>h
: Nnoremap <C-j> <c-w>j
: Nnoremap <C-k> <c-w>k
: Nnoremap <C-l> <c-w>l
The Settitle function is called automatically when you create a file such as new. H. C. cpp.
Autocmd Bufnewfile *. [Ch],*.php,*.cpp Exec "Call Settitle ()"
function Setcomment ()
Call Setline (1, "/*========================================================")
Call Append ("."), "* Copyright (C)". Strftime ("%Y"). " All rights reserved. ")
Call Append (".") +1, "*")
Call Append (".") +2, "* File name:". Expand ("%:t"))
Call Append (".") +3, "* Creator: MJ")
Call Append (".") +4, "* Created Date:". Strftime ("%y years%m Month%d"))
Call Append (".") +5, "* Description:")
Call Append (".") +6, "*")
Call Append (".") +7, "================================================================*/")
Endfunction
"Define function settitle, insert file header automatically
function Settitle ()
Call Setcomment ()
If expand ("%:e") = = = ' php '
Call Append (".") +8, "#ifndef _". ToUpper (Expand ("%:t:r")). " _h ")
Call Append (".") +9, "#define _". ToUpper (Expand ("%:t:r")). " _h ")
Call Append (".") +10, "#ifdef __cplusplus")
Call Append (".") +11, "extern \" C\ "")
Call Append (".") +12, "{")
Call Append (".") +13, "#endif")
Call Append (".") +14, "")
Call Append (".") +15, "#ifdef __cplusplus")
Call Append (".") +16, "}")
Call Append (".") +17, "#endif")
Call Append (".") +18, "#endif//". ToUpper (Expand ("%:t:r")). " _h ")
ElseIf expand ("%:e") = = ' h '
"Call Append (". ") +8, "#pragma once")
ElseIf &filetype = = ' C '
Call Append (".") +8, "#include <stdio.h>")
Call Append (".") +9, "#include <stdlib.h>")
Call Append (".") +10, "")
Call Append (".") +11, "")
Call Append (".") +12, "int main ()")
Call Append (".") +13, "{")
Call Append (".") +14, "return exit_success;")
Call Append (".") +15, "}")
ElseIf &filetype = = ' cpp '
"Call Append (". ") +8, "#include \" ". Expand ("%:t:r ").". H\ "")
Call Append (".") +8, "#include <iostream>")
Call Append (".") +9, "#include <string>")
Call Append (".") +10, "#include <cstdlib>")
Call Append (".") +11, "")
Call Append (".") +12, "using namespace std;")
Call Append (".") +13, "")
Call Append (".") +13, "")
Call Append (".") +14, "int main ()")
Call Append (".") +15, "{")
Call Append (".") +16, "return exit_success;")
Call Append (".") +17, "}")
endif
Endfunction
Autocmd bufnewfile *.sh Exec "call Setbashtitle ()"
function Setbashtitle ()
Call Setline (1, "#!/bin/bash")
Endfunction
"Auto-complete
": Inoremap (() <esc>i
": Inoremap) <c-r>=closepair (') ') <CR>
": inoremap {{}<esc>
: Inoremap} <c-r>=closepair ('} ') <CR>
: Inoremap [[]<esc>i
: Inoremap] <c-r>=closepair ('] ') <CR>
: Inoremap ' <esc>i
function! Closepair (char)
If Getline ('. ') [Col ('. ')-1] = = A:char
Return "\<right>"
Else
Return A:char
endif
Endfunction
The Set Backspace key
Set Backspace=indent,eol,start
2. Vim Theme Configuration
Vim comes with a lot of theme settings, you can generally see the current version of the Vim color scheme in the/usr/share/vim/vim72/colors directory, you can use the ColorScheme darkblue or its theme in the. VIMRC theme configuration.
You can also configure different or slightly more complex color schemes according to the script, the following script is to configure the Vim color scheme according to the different time periods of the day
"Set different color schemes for vim depending on the time period
function Settimeofdaycolors ()
Let Currenthour = strftime ("%H")
Let Colorscheme= ""
If Currenthour < 1 + 0
Let ColorScheme = "Blue"
echo "Setting ColorScheme to Blue"
ElseIf Currenthour < 2 + 0
Let Colorscheme= "Darkblue"
echo "Setting ColorScheme to Darkblue"
ElseIf Currenthour < 3 + 0
Let colorscheme= "Default"
echo "Setting ColorScheme to Default"
ElseIf Currenthour < 4 + 0
Let Colorscheme= "Delek"
echo "Setting ColorScheme to Delek"
ElseIf Currenthour < 5 + 0
Let colorscheme= "Desert"
echo "Setting ColorScheme to Desert"
ElseIf Currenthour < 6 + 0
Let Colorscheme= "Elflord"
echo "Setting ColorScheme to Elflord"
ElseIf Currenthour < 7 + 0
Let Colorscheme= "Evening"
echo "Setting ColorScheme to Evening"
ElseIf Currenthour < 8 + 0
Let Colorscheme= "Koehler"
echo "Setting ColorScheme to Koehler"
ElseIf Currenthour < 9 + 0
Let Colorscheme= "Morning"
echo "Setting ColorScheme to Morning"
ElseIf Currenthour < 10 + 0
Let Colorscheme= "Murphy"
echo "Setting ColorScheme to Murphy"
ElseIf Currenthour < 11 + 0
Let Colorscheme= "Pablo"
echo "Setting ColorScheme to Pablo"
ElseIf Currenthour < 12 + 0
Let Colorscheme= "Peachpuff"
echo "Setting ColorScheme to Peachpuff"
ElseIf Currenthour < 13 + 0
Let Colorscheme= "Ron"
echo "Setting ColorScheme to Ron"
ElseIf Currenthour < 14 + 0
Let colorscheme= "Shine"
echo "Setting ColorScheme to Shine"
ElseIf Currenthour < 15 + 0
Let colorscheme= "Desert"
echo "Setting ColorScheme to Desert"
ElseIf Currenthour < 16 + 0
Let ColorScheme = "Torte"
echo "Setting ColorScheme to Torte"
ElseIf Currenthour < 17 + 0
Let Colorscheme= "Zellner"
echo "Setting ColorScheme to Zellner"
Else
Let colorscheme= "Desert"
endif
Execute "colorscheme". ColorScheme
Endfunction
Call Settimeofdaycolors ()
The VIM editor uses