Вопрос

I'm using VIM via terminal (SSH) and want to modify my syntax coloring settings in VIM to make the function_name Yellow for Lua programming. Unfortunately, I can't figure out how to do that.

For example, in the code below - I want my VIM to syntax color myFunc yellow

local function myFunc(arg1)
    ...
end

I've been able to figure out how to make function yellow, by using this code below:

hi luaFunction ctermfg=Yellow

But this code does not color the word myFunc yellow (and frankly, I'd rather not syntax color function at all)

Question: Any ideas how I can syntax color the function_name in Lua?

Это было полезно?

Решение

Another (more complex) regex to match the function name.

:hi luaCustomFunction ctermfg=yellow
:syn match luaCustomFunction "\(\<function\>\)\@<=\s\+\S\+\s*(\@=" 

This uses a look-behind to match the word function. Then after 1 or more spaces it will highlight any word that has a parenthesis as the first non whitespace character after it.

This only highlights the function name. It does not highlight the parenthesis.

I think if you put these commands in .vim/after/syntax/lua.vim it should work.

The problem with putting them in your vimrc is that sometime after the vimrc is sourced the syntax highlighting file is sourced and generally the first line in there is syn clear. (Which wipes the custom syntax highlighting you just set)

Другие советы

This very naive implementation works with your sample:

:hi luaCustomFunction ctermfg=yellow
:syn match luaCustomFunction "\s\+\zs\S\+\ze("

It is obviously very limited but at least you get a starting point. Read :h syntax for further help.

How about:

hi def link luaFunction Function
hi Function ctermfg=Yellow
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top