fatih / vim-go-tutorial Goto Github PK
View Code? Open in Web Editor NEWTutorial for vim-go
Home Page: https://github.com/fatih/vim-go
License: BSD 3-Clause "New" or "Revised" License
Tutorial for vim-go
Home Page: https://github.com/fatih/vim-go
License: BSD 3-Clause "New" or "Revised" License
Often I'm working and I'd like to keep building, and when it works, actually use the resulting binary. Is there a way to make :GoBuild save the binary? Is there some other command I should use?
I tried "Enter", Ctrl+], :cnext and Ctrl+n.
Just for reference, I have created an Ubuntu Docker image to use as a Go development environment. As part of the environment I would like to have vim-go and its binaries preinstalled in the image. However I am having difficulties scripting the :GoInstallBinaries
functionality in my Dockerfile.
The command I am using is $ vim +Silent +GoInstallBinaries +qall
and it successfully kicks of the install process. However, this always stalls when the 'screen becomes full':
The same thing happens when I install directly from within vim with:GoInstallBinaries
where I need to press the space bar to carry on the installation process.
Does anyone know of a way to get around this issue?
Hi,
:GoRun doesn't work. it reports "go run: no go files listed".
but ":!go run %" , ":GoRun %" works well.
envionment: Centos7 , vim
When using the go to definition
:GoDef
feature to navigate the source code with multiple vim windows open, each window will operate on the same :GoDefStack
. This means that if you navigated to one area of the code in one window, all the other windows opened in the same vim process will see the same GoDef
stack and subsequently push and pop on the same stack. This becomes a bit confusing as you move back and forth between windows pushing and popping as needed.
There are all sorts of combinations of this behavior that are cumbersome but here is a trivial example to reproduce it using version 1.14:
GoDef
in.GoDef
e.g. function, type, etc. and execute :GoDef
or your equivalent hot-key.:GoDefStack
and observe how you're using the same stack as the first window.:GoDefPop
or your equivalent hot-key and observe how you'll go back to the spot that you previously ran :GoDef
from in the first window. This is confusing because you never navigated anywhere in this window.:GoDefPop
or your equivalent hot-key. Observe how you don't go anywhere because you've already popped in the other window. So you're sort of stuck without a trail back home. :( Now you have to :GoDefStack
to try and figure out where you started from to get back home in this window.While in this trivial example it's not too big a deal, as the levels of the stack grow and you fork to new areas of the code, this begins to get really hairy. Instead, the GoDef
feature would be greatly enhanced if we had independent stacks for each vim window.
The tutorial says "GoWhichErrs", but vim-go recognizes "GoWhicherrs". Which is correct?
I am running Vim 8.0.311 on Windows 10. I have filetype enabled in my .vimrc
filetype plugin on
If I do :filetype?
then Vim reports go
. However, it looks like the contents of ftplugin\go.vim are not being loaded because the setlocal omnifunc
isn't being set and other mappings like gd
aren't being set.
map <C-m> :cprevious<CR>
this breaks hitting enter in a command line buffer:
E11: Invalid in command-line window; <CR> executes, CTRL-C quits
verbose map :
<CR> :cprevious<CR>
is probably more appropriate.
First of all, thanks for writing a great tutorial for vim-go!
Could you give me permission to translate this tutorial to Japanese?
Actually I've done translating 60% of it in my local machine.
If yes, when I finish the translation, can I send it as a pull request to this repository?
Or do you prefer the Japanese translation belong to my fork of this repository?
This is not an issue exactly rather a question. Not sure if it related to vim-go environment also, suspecting it so as I have never seen it in case of vim.
1 > I am seeing +, ~, -, _ symbols just beside the line number in vim-go environment.
Do they mean something.
I tried searching in vim-go doc but unable to find any clue.
2> Secondly I am unable to copy using Shift + Insert after highlighting a piece of code using mouse pointer. Which works on console though. I am using vim-go in a screen environment via putty.
Kindly let me know if I am missing something obvious.
I use neovim as my editor. Recently I find that vim-go doesn't show lint warning when I save my file. And when I switch to vim8, It works.
So I debuged vim-go and found out that, with neovim, vim-go run lint synchronously, which send an extra --include
argument to gometalinter. However vim-go send a abs path while gometalinter use a relative path. That's why I lost the lint info.
It's easy to fix this. But what I don't understand is that, why do vim-go use different argument to call gometalinter when synchronously and asynchronously?
Here is my init.vim:
call plug#begin()
Plug 'airblade/vim-gitgutter'
Plug 'altercation/vim-colors-solarized'
Plug 'bling/vim-airline'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'ervandew/supertab'
Plug 'fatih/vim-go'
Plug 'rking/ag.vim'
Plug 'scrooloose/nerdtree'
Plug 'sirver/ultisnips'
Plug 'tpope/vim-fugitive'
Plug 'vim-airline/vim-airline-themes'
call plug#end()
colorscheme solarized
set autowrite
set background=dark
set clipboard=unnamedplus
set foldmethod=syntax
set foldnestmax=1
set list
set mouse=a
set nofoldenable
set noswapfile
set number
set shiftwidth=4
set tabstop=4
set wildignore=*/vendor/*
let g:SuperTabDefaultCompletionType="context"
"let g:go_autodetect_gopath = 0
let g:go_fmt_command="goimports"
let g:go_fmt_experimental=1
let g:go_list_type="quickfix"
let g:go_metalinter_autosave=1
let mapleader=" "
nmap <C-H> <C-W><C-H>
nmap <C-J> <C-W><C-J>
nmap <C-K> <C-W><C-K>
nmap <C-L> <C-W><C-L>
nmap <C-N> :NERDTreeToggle<CR>
nmap <Leader>a :cclose<CR>
nmap <Leader>m :cprevious<CR>
nmap <Leader>n :cnext<CR>
nmap <Leader>c <Plug>(go-coverage-toggle)
nmap <Leader>d <Plug>(go-def-split)
nmap <Leader>e <Plug>(go-rename)
nmap <Leader>f <Plug>(go-referrers)
nmap <Leader>i <Plug>(go-info)
nmap <Leader>r <Plug>(go-run)
nmap <Leader>s <Plug>(go-implements)
nmap <Leader>t <Plug>(go-test)
nmap <Leader>b :<C-u>call <SID>build_go_files()<CR>
function! s:build_go_files()
let l:file = expand('%')
if l:file =~# '^\f\+_test\.go$'
call go#test#Test(0, 1)
elseif l:file =~# '^\f\+\.go$'
call go#cmd#Build(0)
endif
endfunction
My project requires to set some env var before running go test. How can configure vim-go to do something like source .env.dev && go test ...
upon calling :GoTest
in vim?
Hey,
i followed your tutorial and realised that cnext / cprevious wont switch between two errors. In my setup these errors get populated in the location list. Is there anything i have to reconfigure? Here is my simple init.vim
filetype off
call plug#begin('~/.nvim/plugged')
Plug 'flazz/vim-colorschemes'
Plug 'fatih/vim-go'
Plug 'christoomey/vim-tmux-navigator'
call plug#end()
filetype plugin indent on
syntax on
colorscheme materialtheme
set background=dark
syntax enable
let g:tmux_navigator_no_mappings = 1
nnoremap <M-l> :TmuxNavigateRight<cr>
nnoremap <M-h> :TmuxNavigateLeft<cr>
nnoremap <M-j> :TmuxNavigateDown<cr>
nnoremap <M-k> :TmuxNavigateUp<cr>
tnoremap <silent> <M-l> <C-\><C-n>:TmuxNavigateRight<cr>
tnoremap <silent> <M-h> <C-\><C-n>:TmuxNavigateLeft<cr>
tnoremap <silent> <M-j> <C-\><C-n>:TmuxNavigateDown<cr>
tnoremap <silent> <M-k> <C-\><C-n>:TmuxNavigateUp<cr>
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
augroup reload_nvimrc
autocmd!
autocmd BufWritePost ~/.config/nvim/init.vim nested source ~/.config/nvim/init.vim
Hi @fatih,
Could you please add an explicit LICENSE file to the repo so that it's clear under what terms the content is provided, and under what terms user contributions are licensed?
Generally speaking, the absence of a license means that the default copyright laws apply. This means that you retain all rights to your source code and that nobody else may reproduce, distribute, or create derivative works from your work. This might not be what you intend.
Thanks!
Running go get github.com/fatih/vim-go-tutorial
gives a "no buildable Go source files" error.
Hi,
I am following the tutorial to set up vim-go. There is a specific line:
"And finally be sure to install all necessary Go tools (such as guru, goimports, gocode, etc...)".
Is there a list somewhere of what all these tools are ? Even a short tool of the most commonly used ones would be very helpful.
Thanks for a great tool!
Put your cursor on top of the handler and call :GoReferrers. This calls the referrers mode of vim-go, which finds references to the selected identifier, scanning all necessary packages within the workspace. The result will be a quickfix list, so you should be able to jump to the results easily.
How to jump to the result? I use 'Enter', but nothing happens. There is error "E553: No more items
" in statusbar. I tried find an answer in google but did not find anything.
brew upgrade vim
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (caskroom/versions).
No changes to formulae.
Error: vim 8.0.1553_1 already installed
bash-3.2$ vim golang.go
vim-go requires Vim 7.4.1689 or Neovim, but you're using an older version.
Please update your Vim for the best vim-go experience.
If you really want to continue you can set this to make the error go away:
let g:go_version_warning = 0
Note that some features may error out or behave incorrectly.
Please do not report bugs unless you're using Vim 7.4.1689 or newer.
I have always had issues with YouCompleteMe + any snippet plugin .. Can you talk about your setup on how you manage to achieve code completion.. since vim-go has built-in support for this, I would love to see it here.
After a step-by-step practice, I think the document here should be written like this
let g:go_addtags_transform = 'camelcase'
rather than
let g:go_snippet_case_type = "camelcase"
code example
type foo struct {
ServerName string `json:"serverName"`
}
It's a great tutorial and please forgive me if i am wrong.
Hello, it would be very handy to have Windows instructions, specifically ones which deal with the differences in the way _vimrc is handled. I've edited my _vimrc file so that the first line is Plug 'fatih/vim-go'
but I get an error when I start Vim saying E492: Not an editor command Plug 'fatih/vim-go'
I spent a few month using vim-go without syntax highlighting for Go HTML template. I did not find documentation on the subject and I was using the .gohtml
extension for my templates.
Today, I had a look at /ftdetect/gofiletype.vim
and found the gohtmltmpl
file type. I've just enabled it for .gohtml
and I am very happy to have syntax highlighting in vim!
Maybe it is worth mentioning in the tutorial?
even if add to .vimrc:
let g:go_metalinter_enabled = ['vet','golint', 'errcheck']
Coming from fatih/vim-go#1700
PR incoming :-)
the following does not work when working through Tutorial for vim-go examples under the snippet section: expand panic after typing errp does not work nor does the section on fn,ff,ln,lf ... the json hit tab does work
Snippet:
....
Let's put our cursor just after the newFoo() expression. Let's panic here if the err is non-nil. Type errp in insert mode and just hit tab. You'll see that it'll be expanded and put your cursor inside the panic()` function:
if err != nil {
panic( )
^
cursor position
}
It does not expand
I get this
19 func main() {
20 res, err := newFoo()errp
21
22 our, err := json.Marshal(res)
23 }
In the section Beautify the next line can be found:
"You'll see that it's gray, thus it's not valid. Prepend + to the build word and save it again:"
but I can't see it gray, it was until later that I activate the molokai, that I see it as gray. I am wondering if the theme part should be move a little up.
Hi,
I'm having a weird issue with the vim-go plugin.
I started this tutorial and executed the :GoCoverage
command - as it should be, some parts were highlighted green, others red. I then turned it off again, wrote the rest of the code and executed :GoCoverage
again.
This time, it didn't highlight anything, but colored the whole file like it was a comment.
I am not able to get it being green and red again, I can just turn the Coverage off again and it's back to normal syntax highlighting.
Any idea on how I can debug this further?
I already tried re-opening vim and also executed go test -coverprofile tempfile
, this seems to work just fine (Opened the browser and checked the highlighting).
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.