linux vim golang 插件,使用vim-go插件进行golang开发

Go (golang) support for Vim, which comes with pre-defined sensible settings (like auto gofmt on save), with autocomplete, snippet support, improved syntax highlighting, go toolchain commands, and more. If needed vim-go installs all necessary binaries for providing seamless Vim integration with current commands. It's highly customizable and each individual feature can be disabled/enabled easily.

Features

Improved Syntax highlighting with items such as Functions, Operators, Methods.

Auto completion support via gocode

Better gofmt on save, which keeps cursor position and doesn't break your undo history

Go to symbol/declaration with :GoDef

Look up documentation with :GoDoc inside Vim or open it in browser

Automatically import packages via :GoImport or plug it into autosave

Compile your package with :GoBuild, install it with :GoInstall or test them with :GoTest (also supports running single tests via :GoTestFunc)

Quickly execute your current file/files with :GoRun

Automatic GOPATH detection based on the directory structure (i.e. gb projects, godep vendored projects)

Change or display GOPATH with :GoPath

Create a coverage profile and display annotated source code to see which functions are covered with :GoCoverage

Call gometalinter with :GoMetaLinter, which invokes all possible linters (golint, vet, errcheck, deadcode, etc..) and shows the warnings/errors

Lint your code with :GoLint

Run your code through :GoVet to catch static errors

Advanced source analysis tools utilizing guru, such as :GoImplements, :GoCallees, and :GoReferrers

Precise type-safe renaming of identifiers with :GoRename

List all source files and dependencies

Unchecked error checking with :GoErrCheck

Integrated and improved snippets, supporting ultisnips or neosnippet

Share your current code to play.golang.org with :GoPlay

On-the-fly type information about the word under the cursor. Plug it into your custom vim function.

Go asm formatting on save

Tagbar support to show tags of the source code in a sidebar with gotags

Custom vim text objects such as a function or inner function list.

Jump to function or type declarations with :GoDecls or :GoDeclsDir

A async launcher for the go command is implemented for Neovim, fully async building and testing (beta).

Integrated with the Neovim terminal, launch :GoRun and other go commands in their own new terminal. (beta)

Alternate between implementation and test code with :GoAlternate

Checkout the official tutorial that goes literally over all features and shows many tips and tricks. It shows how to install vim-go and explains many unknown use cases. Recommended for beginners as well as advanced users: https://github.com/fatih/vim-go-tutorial

Install

Master branch is supposed to be a development branch. So stuff here can break and change. Please try use always the latest release

Vim-go follows the standard runtime path structure, so I highly recommend to use a common and well known plugin manager to install vim-go. Do not use vim-go with other Go oriented vim plugins. For Pathogen just clone the repo. For other plugin managers add the appropriate lines and execute the plugin's install command.

Pathogen

git clone https://github.com/fatih/vim-go.git ~/.vim/bundle/vim-go

vim-plug

Plug 'fatih/vim-go'

NeoBundle

NeoBundle 'fatih/vim-go'

Vundle

Plugin 'fatih/vim-go'

Vim packages (since Vim 7.4.1528)

git clone https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go

Please be sure all necessary binaries are installed (such as gocode, godef, goimports, etc.). You can easily install them with the included :GoInstallBinaries command. If invoked, all necessary binaries will be automatically downloaded and installed to your $GOBIN environment (if not set it will use $GOPATH/bin). Note that this command requires git for fetching the individual Go packages. Additionally, use :GoUpdateBinaries to update the installed binaries.

Optional

Autocompletion is enabled by default via . To get real-time completion (completion by type) install:neocomplete for Vim or deoplete and deoplete-go for NeoVim or SimpleAutoCmplPop

To display source code tag information on a sidebar install tagbar.

For snippet features install: neosnippet or ultisnips.

Screenshot color scheme is a slightly modified molokai: fatih/molokai.

For a better documentation viewer checkout: go-explorer.

Usage

Many of the plugin's features are enabled by default. There are no additional settings needed. All usages and commands are listed in doc/vim-go.txt. Note that help tags needs to be populated. Check your plugin manager settings to generate the documentation (some do it automatically). After that just open the help page to see all commands:

:help vim-go

Example Mappings

vim-go has several  mappings which can be used to create custom mappings. Unless otherwise specified, none of these mappings are enabled by default. Here some examples you might find useful:

Run commands such as go run for the current file with r or go build and go test for the current package withb and t respectively. Display beautifully annotated source code to see which functions are covered withc.

au FileType go nmap r (go-run)

au FileType go nmap b (go-build)

au FileType go nmap t (go-test)

au FileType go nmap c (go-coverage)

By default the mapping gd is enabled, which opens the target identifier in current buffer. You can also open the definition/declaration, in a new vertical, horizontal, or tab, for the word under your cursor:

au FileType go nmap ds (go-def-split)

au FileType go nmap dv (go-def-vertical)

au FileType go nmap dt (go-def-tab)

Open the relevant Godoc for the word under the cursor with gd or open it vertically with gv

au FileType go nmap gd (go-doc)

au FileType go nmap gv (go-doc-vertical)

Or open the Godoc in browser

au FileType go nmap gb (go-doc-browser)

Show a list of interfaces which is implemented by the type under your cursor with s

au FileType go nmap s (go-implements)

Show type info for the word under your cursor with i (useful if you have disabled auto showing type info viag:go_auto_type_info)

au FileType go nmap i (go-info)

Rename the identifier under the cursor to a new name

au FileType go nmap e (go-rename)

More  mappings can be seen with :he go-mappings. Also these are just recommendations, you are free to create more advanced mappings or functions based on :he go-commands.

Settings

Below are some settings you might find useful. For the full list see :he go-settings.

By default syntax-highlighting for Functions, Methods and Structs is disabled. To change it:

let g:go_highlight_functions = 1

let g:go_highlight_methods = 1

let g:go_highlight_fields = 1

let g:go_highlight_types = 1

let g:go_highlight_operators = 1

let g:go_highlight_build_constraints = 1

Enable goimports to automatically insert import paths instead of gofmt:

let g:go_fmt_command = "goimports"

By default vim-go shows errors for the fmt command, to disable it:

let g:go_fmt_fail_silently = 1

Disable auto fmt on save:

let g:go_fmt_autosave = 0

Disable opening browser after posting your snippet to play.golang.org:

let g:go_play_open_browser = 0

By default when :GoInstallBinaries is called, the binaries are installed to $GOBIN or $GOPATH/bin. To change it:

let g:go_bin_path = expand("~/.gotools")

let g:go_bin_path = "/home/fatih/.mypath" "or give absolute path

Disable updating dependencies when installing/updating binaries:

let g:go_get_update = 0

有疑问加站长微信联系(非本文作者)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值