How to get syntax highlighting for golang in vim?

1,401 views
Skip to first unread message

krishna...@gmail.com

unread,
Apr 16, 2016, 9:37:08 AM4/16/16
to golang-nuts
I am a vim n00b trying to setup a cloud instance for golang development, and have a hard time configuring vim to get syntax highlighting for golang.
Many blogs/articles online recommend vim-go, & I have been unable to get it to work. After following all the steps, I never get syntax highlighting.

Since, all I need is syntax highlighting (with a good enough color scheme!), vim-go seems to be too heavy for that. I use normal go CLIs to get other stuff done, & its good learning too. :)

I already have pathogen installed.
Any pointers as to how I set up syntax highlighting for golang in vim?

Jan Mercl

unread,
Apr 16, 2016, 9:50:57 AM4/16/16
to krishna...@gmail.com, golang-nuts

On Sat, Apr 16, 2016 at 3:37 PM <krishna...@gmail.com> wrote:

> Many blogs/articles online recommend vim-go, & I have been unable to get it to work. After following all the steps, I never get syntax highlighting.

Did you restart vim after configuring the .vimrc file? (Or reload it with :so % while editig it?) Is your vim a recent version?

By coincidence, I started using vim-go just a few days ago. I followed the instructions in the readme exactly and, with firstly installing pathogen, it just worked for me without any trouble whatsoever.

Here's my full .vimrc, if that can help:
==========
execute pathogen#infect()
syntax on
filetype plugin indent on

map <F2> @v

nmap <cr> :mak editor<cr>
nmap <F12> :noh<cr>


set autoread
set autowrite
set cc=80
set columns=160
set cursorline
set hlsearch
set incsearch
set lines=50
set modeline
set number
set tabpagemax=100
set spell spelllang=en_us
winpos 550 72

let maplocalleader = ","
let mapleader = ","

au Filetype go nnoremap <buffer> <LocalLeader>k
    \ :exe 'GoImport ' . expand('<cword>')<CR>


" Search for selected text, forwards or backwards.
vnoremap <silent> * :<C-U>
  \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
  \gvy/<C-R><C-R>=substitute(
  \escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
  \gV:call setreg('"', old_reg, old_regtype)<CR>
vnoremap <silent> # :<C-U>
  \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
  \gvy?<C-R><C-R>=substitute(
  \escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
  \gV:call setreg('"', old_reg, old_regtype)<CR>

let g:go_auto_type_info = 1

au FileType go nmap <Leader>ds <Plug>(go-def-split)
au FileType go nmap <Leader>dv <Plug>(go-def-vertical)
au FileType go nmap <Leader>dt <Plug>(go-def-tab)

au FileType go nmap <Leader>e <Plug>(go-rename)
==================================================


--

-j

Matt Silverlock

unread,
Apr 16, 2016, 3:15:22 PM4/16/16
to golang-nuts, krishna...@gmail.com
> Since, all I need is syntax highlighting (with a good enough color scheme!), vim-go seems to be too heavy for that. I use normal go CLIs to get other stuff done, & its good learning too. :)

You can just ignore all the other features of vim-go until you want to use them (godef, godoc and gobuild being the most useful). Most won't work until you explicitly bind keys to them, anyway!

Steve Mynott

unread,
Apr 16, 2016, 7:51:41 PM4/16/16
to krishna...@gmail.com, golang-nuts
If you using a recent vim (I used 7.4) without extra plugins all you
need do for colour syntax is to type ":syntax on" in command mode (or
add "syntax on" in .vimrc).

S
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
4096R/EA75174B Steve Mynott <steve....@gmail.com>

Steve Mynott

unread,
Apr 16, 2016, 7:54:05 PM4/16/16
to krishna...@gmail.com, golang-nuts
Also if you have a black terminal background "set bg=dark" which will
make the colours look a lot better.

S
Reply all
Reply to author
Forward
0 new messages