From 25d47834bf1d8de9eb7fc9d6ad0aa995dfda8142 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Sun, 8 Apr 2018 16:40:14 +0100 Subject: [PATCH 1/2] Match builtins as keywords and highlight with the Identifier group. This was changed from keywords to the regexp in #605, but I think that was a mistake. If you do `new := "foo"` then this is perfectly valid Go, but I don't think it's a bad thing to add a reminder that you're actually overriding a global built-in by highlighting the `new`, just as it's not a bad idea to highlight the `new()` in `func new()` to serve as a similar reminder. This is a common-ish mistake that most of us have probably made at least once or twice. The only case where this fails is in method declaration and calls: func () x new() { other.new() } But this is the case with the current highlight as well, so it doesn't make that worse. --- syntax/go.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/syntax/go.vim b/syntax/go.vim index 5a7da28530..68daa0a971 100644 --- a/syntax/go.vim +++ b/syntax/go.vim @@ -47,12 +47,12 @@ hi def link goFloats Type hi def link goComplexes Type " Predefined functions and values -syn match goBuiltins /\<\v(append|cap|close|complex|copy|delete|imag|len)\ze\(/ -syn match goBuiltins /\<\v(make|new|panic|print|println|real|recover)\ze\(/ +syn keyword goBuiltins append cap close complex copy delete imag len +syn keyword goBuiltins make new panic print println real recover syn keyword goBoolean true false syn keyword goPredefinedIdentifiers nil iota -hi def link goBuiltins Keyword +hi def link goBuiltins Identifier hi def link goBoolean Boolean hi def link goPredefinedIdentifiers goBoolean From 328747d04d90010847d2d987038f5cafef7b9cec Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Mon, 3 Sep 2018 00:57:20 -0700 Subject: [PATCH 2/2] add FAQ entry about customizing highlight groups --- doc/vim-go.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/vim-go.txt b/doc/vim-go.txt index 31a3a76e61..8dc0385684 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -2268,6 +2268,18 @@ By default new terminals are opened in a vertical split. To change it let g:go_term_mode = "split" > +How can I customize the highlighting?~ + +All the highlight groups used by vim-go are prefixed with `go` (e.g. +`goType`) and are defined in the files in the `syntax` directory. To change +the highlighting for any group, add a `highlight` command for the group to +your vimrc. To turn off the highlighting for any group, add `highlight link +group-name NONE` (where `group-name` is the name of the group whose highlight +you'd like to turn off) to your vimrc. + +Some people may wish to highlight Go's builtins as keywords. To do so, one +should simply add `highlight link goBuiltins Keyword` to the `vimrc` file. + ============================================================================== DEVELOPMENT *go-development*