N8: manually add colors to VIM syntax

Source: Internet
Author: User

VimThere are ready-made Plug-ins on the official website to add the vim syntax color, which has been difficult to solve. The principle is relatively simple. Use the ctags tool to generate the tags file, then generate the vim source file from the tags file, and then run the vim source command to execute it.

1. Download a Vim that supports Lua, learn Lua's hand itch, and have little understanding of Vim's script. The function is written by Lua;

2. Download a ctags. cygwin may conflict with each other. Make sure the version is correct.

Exuberant ctags 5.8, copyright (c) 1996-2009 Darren Hiebert
Compiled: Jul 9 2009 17:05:35
Addresses: <dhiebert@users.sourceforge.net>, http://ctags.sourceforge.net
Optional compiled features: + Win32, + RegEx, + internal-sort

3. Write a Lua file named stag. Lua. You can modify it by yourself and add more personal settings, such as known tags and change colors;

local tags_vim=io.open("tags.vim", "w");local hl={};hl.f="Function";hl.m="Member";hl.d="Define";hl.s="Struct";hl.v="Variable";hl.t="Typedef";--ctags -R -V -f ./tagsio.input("tags")for line in io.lines() dolocal id, idtype=string.match(line, "^(.-)\t.-;\"\t(.)");if (id) thenlocal hltype=hl[idtype];hltype=hltype or "Type";tags_vim:write("syn keyword " .. hltype .. " " .. id .. "\n");endendtags_vim:write([[syn keyword Typedef stringsyn keyword Typedef stdsyn keyword Typedef auto_ptrhighlight Function     gui=none guifg=navy     guibg=bg      ctermfg=Greenhighlight Member       gui=none guifg=#808080  guibg=bg      ctermfg=DarkMagentahighlight Define       gui=none guifg=#a055df  guibg=bg      ctermfg=Whitehighlight Struct       gui=none guifg=#7f0055  guibg=bg      ctermfg=LightGreenhighlight Variable     gui=none guifg=blue     guibg=bg      ctermfg=LightGreenhighlight Typedef      gui=none guifg=blue     guibg=bg      ctermfg=Yellow]]);tags_vim:close();

4. Bind two keys to gvimrc;

map <F11> :call Myhl() <CR><F12>map <F12> :so tags.vim<CR>function! Myhl()lua << EOFdofile("stag.lua");EOFendfunction

5.Run ctags.exe in the directory of the source code to generate the tags file. Press F11 in VIM to see your favorite color settings.

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.