Use the vim editor and the vim editor.

Source: Internet
Author: User

Use the vim editor and the vim editor.

I. Introduction

 1. vim is a powerful text editor. If you are familiar with it, it will effectively help us improve the efficiency of editing text and programs. The vim editor has a relatively high threshold for getting started. Many people are reluctant to remember many commands, which are often discouraged in the early stages of learning.

2. vim learning requires constant practice and use. Only by forcing itself to continue using it can we remember the seemingly complex commands in the Process of use. However, if we get used to the vim editing mode, we will feel that vim will really help us improve the efficiency of text editing.

3. For vim learning materials, the vim Help documentation provided in this document is rich enough for constant reference during the learning process. In addition, there is also a simplified starting document, namely vimtutor. You can enter vimtutor in the command line to start learning and finish learning in less than an hour.

Ii. Configuration

1. vim configuration files include global configuration (usually in the/etc/vim/vimrc directory) and personal configuration (/home/username /. in vimrc), the global configuration file takes effect for all users in the system, and the personal configuration file takes effect only for the user's own use environment.

2. The vim configuration file is usually configured on the Internet by someone else. You can copy it to your personal configuration file and use it directly. You can also customize your own environment as needed.

3. Configure scripts

  1. In the previous use process, I have configured a configuration script based on my personal needs. Most of the configuration scripts are annotated and can be configured as needed. Note: "beginning to indicate comments in vimrc

Set termencoding = utf8

Set hlsearch
"Row number
Set nu
"Syntax highlighting
Syntax on
"Enable mouse
Set mouse = v
"Auto indent
"Highlight Columns
"Set cursorcolumn
"Highlight the current row
Set cursorline
"Highlight the current row
"Hi CursorLine cterm = NONE ctermbg = magenta ctermfg = white guibg = darked guifg = white
Set autoindent
"Set guifont = Monaco: h80" font & font size
"Remove the annoying vi consistency mode to avoid bugs and limitations in earlier versions.
Set nocompatible
"Based on the above alignment format, the intelligent choice of the Start method is very useful for programming similar to the C language.
Set smartindent
"Set indent
Set tabstop = 4
Set softtabstop = 4
Set shiftwidth = 4
"Display the command being entered in the status bar
Set showcmd
"The current vim mode is displayed in the lower left corner.
Set showmode
"Code folding
Set foldenable
Set foldmethod = indent
Set foldlevel = 99
"Display ruler
Set ruler
"Enable Automatic file type detection
Filetype on
Set completeopt = longest, menu
"Enable auto-completion
"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 automatically called when files such as. h. c. hpp. cpp are created.
Autocmd BufNewFile *. [ch], *. php, *. cpp exec "call SetTitle ()"
Function SetComment ()
Call setline (1, "/* =================================================== ============================ ")
Call append (line ("."), "* Copyright (C)". strftime ("% Y"). "All rights reserved .")
Call append (line (".") + 1 ,"*")
Call append (line (".") + 2, "* file name:". expand ("%: t "))
Call append (line (".") + 3, "* Creator: mj ")
Call append (line (".") + 4, "* creation date:". strftime ("% Y % m % d "))
Call append (line (".") + 5, "* Description :")
Call append (line (".") + 6 ,"*")
Call append (line (". ") + 7, "============================================== =========================================== */")
Endfunction
"Defines the SetTitle function to automatically insert a file header.
Function SetTitle ()
Call SetComment ()
If expand ("%: e") = 'php'
Call append (line (".") + 8, "# ifndef _". toupper (expand ("%: t: r"). "_ H ")
Call append (line (".") + 9, "# define _". toupper (expand ("%: t: r"). "_ H ")
Call append (line (".") + 10, "# ifdef _ cplusplus ")
Call append (line (".") + 11, "extern \" C \"")
Call append (line (".") + 12 ,"{")
Call append (line (".") + 13, "# endif ")
Call append (line (".") + 14 ,"")
Call append (line (".") + 15, "# ifdef _ cplusplus ")
Call append (line (".") + 16 ,"}")
Call append (line (".") + 17, "# endif ")
Call append (line (".") + 18, "# endif //". toupper (expand ("%: t: r"). "_ H ")
Elseif expand ("%: e") = 'H'
"Call append (line (". ") + 8," # pragma once ")
Elseif & filetype = 'C'
Call append (line (".") + 8, "# include <stdio. h> ")
Call append (line (".") + 9, "# include <stdlib. h> ")
Call append (line (".") + 10 ,"")
Call append (line (".") + 11 ,"")
Call append (line (".") + 12, "int main ()")
Call append (line (".") + 13 ,"{")
Call append (line (".") + 14, "return EXIT_SUCCESS ;")
Call append (line (".") + 15 ,"}")
Elseif & filetype = 'cpp'
"Call append (line (". ") + 8," # include \ "". expand ("%: t: r"). ". h \"")
Call append (line (".") + 8, "# include <iostream> ")
Call append (line (".") + 9, "# include <string> ")
Call append (line (".") + 10, "# include <cstdlib> ")
Call append (line (".") + 11 ,"")
Call append (line (".") + 12, "using namespace std ;")
Call append (line (".") + 13 ,"")

Call append (line (".") + 13 ,"")
Call append (line (".") + 14, "int main ()")
Call append (line (".") + 15 ,"{")
Call append (line (".") + 16, "return EXIT_SUCCESS ;")
Call append (line (".") + 17 ,"}")
Endif
Endfunction
Autocmd BufNewFile *. sh exec "call SetBashTitle ()"
Function SetBashTitle ()
Call setline (1 ,"#! /Bin/bash ")
Endfunction
"Auto-completion
": 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

"Set the return key
Set backspace = indent, eol, start

2. vim topic Configuration

Vim comes with many theme settings. You can view the current version of vim color scheme in the/usr/share/vim/vim72/colors directory. in vimrc, use colorscheme darkblue or its topic to configure the vim topic.

You can also configure different or slightly complex color schemes according to the script. The following script configures the vim color scheme based on different time periods of each day.

  

"Set different vim color schemes based on different time periods

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 ()

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.