VIM Configs

1,635 views
Skip to first unread message

Sergey Gavruk

unread,
Sep 29, 2013, 5:04:44 AM9/29/13
to golan...@googlegroups.com
Hello,

I think many of you use VIM as a primary text editor for Go. You've been optimising VIM for a long period to make it comfortable for Go.
So, lets share your vim configs here and describe what are the best features/keys you like in your config.

Miki Tebeka

unread,
Sep 29, 2013, 1:19:55 PM9/29/13
to golan...@googlegroups.com
https://github.com/nsf/gocode and
au BufNewFile,BufRead *.go setl noet
au BufNewFile,BufRead *.go setl ts=4
au BufNewFile,BufRead *.go setl tw=0
au FileType go setl makeprg=go\ build

Kevin Gillette

unread,
Sep 29, 2013, 1:54:27 PM9/29/13
to golan...@googlegroups.com
On Sunday, September 29, 2013 11:19:55 AM UTC-6, Miki Tebeka wrote:
https://github.com/nsf/gocode and
au BufNewFile,BufRead *.go setl noet
au BufNewFile,BufRead *.go setl ts=4
au BufNewFile,BufRead *.go setl tw=0
au FileType go setl makeprg=go\ build

If you're using FileType go, then it means something is already doing something like `au BufNewFile,BufRead *.go set filetype=go` somewhere, and you can put all your settings on one line. Thus you can change all that to:
au FileType go setl noet ts=4 tw=0 makeprg=go\ build

noet and ts are a bit irrelevant if you have to official go vim stuff incorporated and use `au BufWritePre *.go Fmt`

Robert Melton

unread,
Sep 29, 2013, 2:21:13 PM9/29/13
to Sergey Gavruk, golang-nuts
Here is what my setup looks like http://i.imgur.com/vYnmjMF.png -- I
use the official Go vim files and additionally use gocode
(https://github.com/nsf/gocode) and gotags
(https://github.com/jstemmer/gotags). I use tagbar
(https://github.com/majutsushi/tagbar) along the left. I use a couple
simple autocommands specific to go. I also use golint
(https://github.com/golang/lint), but have excluded it from here
because I know some people don't like it.

au BufRead,BufNewFile *.go set list noexpandtab syntax=go
listchars=tab:\|\ ,trail:-
- turns on listing special chars, turns off expand tab, sets syntax to
go, makes it so a tab is displayed as a bar plus spaces (you can see
this in the screenshot) and turns on showing trailing spaces.

au BufWritePre *.go Fmt
- when I save, ensure it is in go style

Other things you might notice in the screenshot are color-coded
parenthesis, brackets, ... that all comes from Rainbow Parentheses
(https://github.com/kien/rainbow_parentheses.vim) and the color theme
is Herald (https://github.com/h3rald/stash/tree/master/.vim/colors).
> --
> 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/groups/opt_out.



--
Robert Melton

Nabeel Memon

unread,
Sep 29, 2013, 2:50:42 PM9/29/13
to Robert Melton, Sergey Gavruk, golang-nuts
Robert, can you share all this setup in one package? With vimrc as well?

I'm trying to pick up vim but having newbie problems which is a big waste of time. 


Nabeel

Robert Melton

unread,
Sep 29, 2013, 3:15:10 PM9/29/13
to Nabeel Memon, Sergey Gavruk, golang-nuts
On Sun, Sep 29, 2013 at 2:50 PM, Nabeel Memon <nm3...@gmail.com> wrote:
> Robert, can you share all this setup in one package? With vimrc as well?

Generally I discourage such packs, as they are layers of indirection
and users end up with .vimrc they don't understand at all. I have run
the #vim channel on freenode for over a decade, so I see the pain such
indirect bundles can cause. What if my bundle version didn't match up
with gocode or golint or gotags binaries? Bad things would happen.

You can look around my vim-files
(https://github.com/robertmeta/vim-files/), but trying to copy them
wholesale will only cause you pain. They are customized just for my
usage (and even in some cases my specific development machines). You
might be able to get some settings you want to copy, or some plugins
(under bundles) you want to try.

--
Robert Melton

Josh Hoak

unread,
Sep 29, 2013, 1:18:33 PM9/29/13
to Sergey Gavruk, golan...@googlegroups.com
It's hardly battle tested, but I created a Go-Build tool (Gobu) that really speeds up by build/test phase in Vim for me.  It uses a 'scratch' like window to display errors (instead of QuickFix)  so I can get more complex behavior and highlighting.

- Josh


--

Robert Melton

unread,
Sep 29, 2013, 5:17:38 PM9/29/13
to Josh Hoak, Sergey Gavruk, golang-nuts
That a really cool idea. I currently use Syntastic
(https://github.com/scrooloose/syntastic) which marks errors inline.
But having a nice quickfix compatible (and the more similar you make
it for muscle memory, the better) tool as well seems great.
--
Robert Melton

Nabeel Memon

unread,
Sep 29, 2013, 8:16:36 PM9/29/13
to Robert Melton, Sergey Gavruk, golang-nuts
Yeah it's just to give me a heads up and getting to use vim. 

Sergey Gavruk

unread,
Sep 30, 2013, 3:59:28 PM9/30/13
to golan...@googlegroups.com, Nabeel Memon, Sergey Gavruk
Robert, thank you for sharing you vim files.
I think your vim config will help us to find out new ways to make vim better for Go.

For those who want to try VIM, I've look all over the internet and collected the most basic settings for vim

Jeff Mitchell

unread,
Sep 30, 2013, 4:34:12 PM9/30/13
to Sergey Gavruk, golan...@googlegroups.com, Nabeel Memon
Sergey Gavruk wrote:
> Robert, thank you for sharing you vim files.
> I think your vim config will help us to find out new ways to make vim
> better for Go.
>
> For those who want to try VIM, I've look all over the internet and
> collected the most basic settings for vim
> https://github.com/Gavruk/vim-config

I have found this to be a very useful blog post:
http://0value.com/my-Go-centric-Vim-setup

--Jeff

Robert Melton

unread,
Sep 30, 2013, 4:45:36 PM9/30/13
to Jeff Mitchell, Sergey Gavruk, golang-nuts, Nabeel Memon
Most of what is in that post is already covered in this thread, but it
adds one really cool tool godef (https://github.com/dgryski/vim-godef)
--- which in my quick testing seems to work really, really well.
Thanks!

--
Robert Melton

Damian Gryski

unread,
Oct 1, 2013, 5:58:08 AM10/1/13
to golan...@googlegroups.com, Jeff Mitchell, Sergey Gavruk, Nabeel Memon
Le lundi 30 septembre 2013 22:45:36 UTC+2, Robert Melton a écrit :

Most of what is in that post is already covered in this thread, but it
adds one really cool tool godef (https://github.com/dgryski/vim-godef)
--- which in my quick testing seems to work really, really well.
Thanks!

   I'm glad so many people are enjoying the godef plugin I wrote.  However, it seems the new Go Oracle will probably replace most uses of godef when it is released.

   Damian 


__kaveh__

unread,
Oct 1, 2013, 11:50:31 AM10/1/13
to golan...@googlegroups.com
This is my _gvimrc (on Windows 8) and I have added some shortcuts to run 'go run', go build', 'go install', 'go test' and (my God!) fmt! I use a color scheme named dejavu (Go code is from Gorilla web tools):

Kamil Kisiel

unread,
Oct 1, 2013, 12:23:14 PM10/1/13
to golan...@googlegroups.com, Jeff Mitchell, Sergey Gavruk, Nabeel Memon
Someone still needs to write a killer vim plugin for Go Oracle :)

Sergey Gavruk

unread,
Oct 1, 2013, 1:51:13 PM10/1/13
to Robert Melton, golang-nuts
Robert, how do you call this dropdown list (http://i.imgur.com/vYnmjMF.png)? I've tried many ways to run it (omnifunc C-x,C-o), but still cannot. Even with your config.
--
Best regards,
Sergey Gavruk

James Hillyerd

unread,
Oct 2, 2013, 4:55:42 PM10/2/13
to golan...@googlegroups.com, Robert Melton
Sergey,

For each project you work in, you'll want to start vim in it's src directory and run :UpdateTags -R .

That will build the tag files for you, which should be updated automagically from that point on.

-james

Sergey Gavruk

unread,
Oct 2, 2013, 5:04:26 PM10/2/13
to golan...@googlegroups.com
Thanks, I will try to configure this.

But I have a problem loading ftplugins. Path looks like: 

~/.vim/bundle/gosupport/ftplugin/go/lint.vim

~/.vim/bundle/gosupport is at runtimepath

:echo &ft
prints "go"

The actual code of this file is:
https://github.com/golang/lint/blob/master/misc/vim/ftplugin/go/lint.vim

So, I should be able to access ':Lint' command, but this command doesn't exists. But in theory this file should be executed and command should be added.

Do you have any suggestions how to solve this problem?

Sean Browning

unread,
Oct 2, 2013, 8:28:03 PM10/2/13
to golan...@googlegroups.com

If you use gocode, I highly recommend YouCompleteMe. https://github.com/Valloric/YouCompleteMe

Sergey Gavruk

unread,
Oct 4, 2013, 1:28:00 PM10/4/13
to golan...@googlegroups.com
To those who have the same problem, I have a solution:

This part checks if "golist" is executable (if not - no nothing)

if !executable("golint")
    finish
endif

In my case, its not executable (as for vim), but I can easily execute "golint" from bash (its located in the path). So, removing this part helps and :Lint work fine.

Andrew Radev

unread,
Oct 20, 2013, 9:04:06 AM10/20/13
to golan...@googlegroups.com
I'm still learning Go and I use it rarely, so my own customizations are going slowly. The big thing that I use is my own fork of the runtime files here: https://github.com/AndrewRadev/vim-golang. I've pushed some bugfixes upstream, but I was told that additional features will probably not be added to keep it minimal, so I went the "let's rewrite the whole thing" way. I may yet propose some fixes/improvements upstream, but let's see. For now, the differences are not that great and mostly internal, but I do have a small list of additions in the README that may be useful to someone.

Other than that, my ftplugin is pretty small: https://github.com/AndrewRadev/Vimfiles/blob/master/ftplugin/go.vim. I'm not happy with `go run` as my makeprg, but I'd rather not have binaries laying around, unless I build them for a purpose. Gotta think about that, I suppose.

The "var template" area (https://github.com/AndrewRadev/Vimfiles/blob/master/ftplugin/go.vim#L9-10) is something I use with other filetypes for extracting and inlining code from/to variables. The script is here: https://gist.github.com/AndrewRadev/2592904.

It seems to work alright, although the presence of both "foo = bar" and "foo := bar" syntaxes makes it slightly trickier. Maybe my switch.vim plugin could help for that, though I still don't have any Go-specific definitions in there. Incidentally, if anybody knows about switch.vim and has a good idea for Go switches, open up an issue, I'd love to hear it. Same for splitjoin.vim.

The `outline_pattern` line (https://github.com/AndrewRadev/Vimfiles/blob/master/ftplugin/go.vim#L12) is also something I use for different filetypes. Implementation is here: https://github.com/AndrewRadev/Vimfiles/blob/master/startup/commands.vim#L65-84. It depends on the foldutil.vim plugin: http://www.vim.org/scripts/script.php?script_id=158, though you could just use foldutil on its own, really. I just have a simple :Outline command that folds the buffer so you can see all function definitions.

The :RunCommand just maps the ! key to go-run the current file. Useful for simple experimentation.

I'm still not using ctags with Go, although godef seems like a nice alternative. I don't really know anything about this "Go Oracle" that people are mentioning, guess I should investigate.
Reply all
Reply to author
Forward
0 new messages