Vim: need help with small script code to highlight

I need script code to highlight "[Capítulo" and "]" and everything in between. Thanks.

I want it to work every time I open, for example, a .txt file. Just like code highlighting.

+3
source share
2 answers

Here is an easy way to do this:

in vim, make sure syntax highlighting is enabled with :syn on

run the command :highlightto get a list of all the highlight group names and samples of how they look. The group Errorlooks as if it stands out well in my color scheme, so I will use it in my example (but you can use any other name, for example Todoor Search)

:syntax match Error /\[Capítulo[^\]]*\]/ 

This template will save you from greedy matching the largest fragment. Despite the fact that other people suggest you use a regex /\[Capítulo.*\]/, this is probably not what you want, because it will match all in between if there are two or more such patterns in the string.

For example, it /\[Capítulo.*\]/will match this entire line:

[Capítulo foo] these words should not stand out [Capítulo bar]

, /\[Capítulo[^\]]*\]/ []:

[Capítulo foo] [Capítulo bar]

, , , , , , .*, . [^\]]*, , " , ].

, , ":" .vimrc

+5

- , :

/ " " :

\[Capítulo.*\]/
+1

Source: https://habr.com/ru/post/1705843/


All Articles