Set vim in Linux to automatically add spaces on both sides of the operation symbol

Source: Internet
Author: User

Vim is set to automatically add spaces to the left and right sides of the operation symbols such as =+-. The original VIM does not have this function, write code such as Z=x+y, not beautiful, many compilers (such as VS) can automatically add space on both sides of the symbol, such as Z = x + y, looks more beautiful.

Just add the following code to the. VIMRC:

"set = +-* Auto space before and after"set, automatically add spaces afterifExists"g:equ"): Inoremap= <c-r>=equalsign ('=') <CR>: Inoremap+ <c-r>=equalsign ('+') <CR>: Inoremap-<c-r>=equalsign ('-') <CR>: Inoremap* <c-r>=equalsign ('*') <CR>: Inoremap/<c-r>=equalsign ('/') <CR>: Inoremap> <c-r>=equalsign ('>') <CR>: Inoremap< <c-r>=equalsign ('<') <CR>: Inoremap,,<space>endiffunction! Equalsign (Char)ifA:Char=~'='&& Getline ('.') =~".*("return A:Charendif let Ex1= Getline ('.') [Col ('.') -3]let ex2= Getline ('.') [Col ('.') -2]ifEx1 =~"[-=+><>\/\*]"ifEX2!~"\s"return"\<esc>i"AChar."\<space>"Elsereturn"\<esc>xa"AChar."\<space>"endifElseifEX2!~"\s"return"\<space>"AChar."\<space>\<esc>a"Elsereturn A:Char."\<space>\<esc>a"endif endifendif

You can do it. In addition, you can add the following code to increase the convenience of vim:

"prevention of hand-mistaken kill strokesnnoremap:: Cnoremap Q! Q!command Wq wqcommand Q qcommand Wq wqset nu"code Displays line numberSyntax on"keyword highlightingSet Cindent"C Syntax Auto indentSet Autoindent"New Line Auto indentSet shiftwidth=4 "Indent width 4Set tabstop=4 "Tab Width 4Set softtabstop=4 "Tab Width 4

Set vim in Linux to automatically add spaces on both sides of the operation symbol

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.