Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to realize vim syntax highlighting under linux

Shulou Source: shulou.com Published: 2022-06-01 06:39:11 09月19日 Update

This article is about how to achieve vim syntax highlighting under linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Highlight label * tag-highlight*

If you want to highlight all the tags in the file, you can use the following mapping.

-- generate a tags.vim file and highlight the label.

-highlight tags only based on existing tags.vim files.

: map: sp tags:%s/ ^\ ([^:] *:\)\ =\ ([^] *). * / syntax keyword Tag\ 2/:wq! Tags.vim/ ^

: map: so tags.vim

Warning: the longer the label file, the slower this will be, and the more memory Vim consumes.

Here only typedef is highlighted, and it can also be set for union and struct. To do this, you need Exuberant ctags (which can be found at http://ctags.sf.net).

Put the following line in your Makefile:

# create a highlighted file for types. Exuberant ctags and awk are required

Types: types.vim

Types.vim: *. [ch]

Ctags-i=gstuS-o-*. [ch] |\

Awk 'BEGIN {printf ("syntax keyword Type\ t")}\

{printf ("% s", $1)} END {print ""}'> $@

Put the following line in your .vimrc:

"load the types.vim highlighted file, if it exists

Autocmd BufRead,BufNewFile *. [ch] let fname = expand (': PRV h'). '/ types.vim'

Autocmd BufRead,BufNewFile *. [ch] if filereadable (fname)

Autocmd BufRead,BufNewFile *. [ch] exe'so. Fname

Autocmd BufRead,BufNewFile *. [ch] endif

=

The above F11 can only identify the internal definition of the function, the name of the function, etc., but not the macro definition.

Change it to

"generate a highlighted file tags.vim based on tags files

Map: sp tags:set nohls:%s/file/fi le/:%s/ ^\ ([^:] *:\)\ ([^] *). * / syntax keyword Tag\ 2/:wq! Tags.vim/ ^

"all the tags in the highlighted file

Map: so tags.vim

You can recognize macros.

Thank you for reading! On "how to achieve vim syntax highlighting under linux" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

Tags: Highlights files tags grammar content functions more articles generated good practical for this memory available in articles see knowledge the more the longer reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Xiaomi Huawei vpn Shulou Technology