• Stars
    star
    116
  • Rank 303,972 (Top 6 %)
  • Language
    Vim Script
  • License
    Other
  • Created about 6 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Plugin for the Go programming language

gopher.vim is a Vim plugin for the Go programming language.

The idea is to to provide a "light-weight" experience by off-loading functionality to native Vim features or generic plugins when they offer a good user experience. It's not "hard-core minimalist", but does try to avoid re-implementing things that are always handled well by other features or plugins rather than duplicating them (which is what vim-go does, an approach which does come with some advantages by the way).

It currently implements almost everything from vim-go. See CHANGES.markdown for a more detailed list of changes.

Installation

Installation can be done using the usual methods. You will need Go 1.11 and Vim 8.1.1803 or Neovim 0.4.4. Older versions will not work due to missing features.

Installation of external tools is done automatically on first usage, but can be done manually with :GoSetup.

Quickstart

All gopher.vim mappings start with ; in normal mode, or <C-k> in insert mode. The second letter is identical, so ;t is <C-k>t in insert.

You can change this with the g:gopher_map setting; see :help g:gopher_map for details.

Compiling code

Compiling code is done with the go compiler (that is, the Vim :compiler feature); you can then use :maketo run the command inmakeprg` and populate the quickfix with any errors.

gopher.vim tries to be a bit smart about what to set makeprg to: if a ./cmd/<module-name> package exists then it will compile that instead of the current package, and build tags from the current file are automatically added. There's a bunch of options to tweak the behaviour: see :help gopher-compilers for detailed documentation.

The ;; mapping will write all files and run :make; specifically it runs:

:silent! :wa<CR>:compiler go<CR>:echo &l:makeprg<CR>:silent make!<CR>:redraw!<CR>

:make is a synchronous process, usually Go compile times are fast enough, but there are plugins to make it run in the background if you want (see "Companion plugins" below).

Running tests

Testing is done with the gotest compiler; you can run them with ;t which will run the current test function if you're inside a test, or tests for the current package if you're not.

You can pass additional to :make; e.g. :make -failfast.

Running lint tools

The golint compiler can run lint tools; the error format is compatible with golangci-lint, staticcheck, and go vet (other tools may also work, but are not tested):

:compiler golint
:set makeprg=staticcheck
:make

Mappings

Map ;t to run all tests, instead of current.

" let g:gopher_map = {'_nmap_prefix': '', '_imap_prefix': '' }

    " Quicker way to make, lint, and test code.
    " au FileType go nnoremap MM :wa<CR>:compiler go<CR>:silent make!<CR>:redraw!<CR>
    " au FileType go nnoremap LL :wa<CR>:compiler golint<CR>:silent make!<CR>:redraw!<CR>
    " au FileType go nnoremap TT :wa<CR>:compiler gotest<CR>:silent make!<CR>:redraw!<CR>

    " au FileType go nmap MM <Plug>(gopher-install)
    " au FileType go nmap TT <Plug>(gopher-test)
    " au FileType go nmap LL <Plug>(gopher-lint)

See :help gopher_mappings

Other commands

All motions and text objects that work in vim-go also work in gopher.vim: [[, ]], af, ac, etc.

Overview of other commands:

:GoCoverage – Highlight code coverage.
:GoFrob     – Frob with (modify) code.
:GoGuru     – Get various information using the guru command.
:GoImport   – Add, modify, or remove imports.
:GoRename   – Rename identifier under cursor.
:GoTags     – Add or remove struct tags

Note that many details are different from vim-go; gopher.vim is not intended as a "drop-in" replacement.

See :help gopher for the full reference manual.

Companion plugins

A list of useful companion plugins; this is not an exhaustive list, but rather a "most useful" list. For many alternatives exist as well; I didn't test all options.

See PLUGINS.markdown for some configuration hints for various plugins.

Other resources

Tips

Some things you can stick in your vimrc:

augroup my_gopher
    au!

    " Basic lint on write.
    " autocmd BufWritePost *.go compiler golint | silent make! | redraw!

    " Format buffer on write; need to make a motion for the entire buffer to
    " make this work.
    " Use e.g. ALE or Syntastic for a more advanced experience.
    " autocmd BufWritePre *.go
    "             \  let s:save = winsaveview()
    "             \| exe 'keepjumps %!goimports 2>/dev/null || cat /dev/stdin'
    "             \| call winrestview(s:save)

    " Compile without cgo unless explicitly enabled.
    " autocmd BufReadPre *.go if $CGO_ENABLED is# '' | let $CGO_ENABLED=0 | endif
augroup end

FAQ

I'm missing X from vim-go

That's probably intentional. An important reason for this plugin's existence is to remove features better handled with native Vim features or generic external plugins. See the feature table in CHANGES.markdown.

If you think there's a good reason for something from vim-go to exist in gopher.vim then feel free to open an issue with an explanation why existing Vim features or generic plugins aren't enough.

Some things that were async in vim-go are no longer, what gives?

Async can be nice but it's also hard. For example the code for :GoCoverage is now 120 lines shorter while also fixing a few bugs and adding features.

There is also a user interface aspect: if I ask Vim to do something then I want that done now. When it's run in the background feedback is often poor. Is it still running? Did I miss a message? Who knows, messages are often lost. How do you cancel a background job from the UI? Often you can't. What if I switch buffers or modify a file? Weird Stuffβ„’ happens.

This doesn't mean I'm against async, just not for every last thing. Some things in gopher.vim are still async; it's a trade-off. If you have a good case for something to be async then feel free to open an issue.

The syntax has fewer colours, it's so boring!

I removed a whole bunch of the extra options as it's hard to maintain and not all that useful. It doesn't even work all that well because enabling all options would slow everything down to a crawl and testing all the combinations is tricky.

So the syntax file in gopher.vim has fewer features, but is also much faster and easier to maintain. Maybe I'll add some features back once I figure out a better way to maintain this stuff.

You can still copy vim-go's syntax/go.vim file to your ~/.vim/syntax directory if you want your Christmas tree back πŸŽ„

Why do some commands conflict with vim-go? Why not prefix commands with :Gopher?

This is what I originally did, and found it annoying as it's so much work to type, man! Being compatible probably isn't too useful anyway, so I changed it.

Functions, mappings, settings, etc. are all prefixed with gopher.

History and rationale

I started this repository as a test case for internally vendoring of tools; in vim-go confusion due to using the wrong version of an external tool (too old or new) is common; people have to manually run :GoUpdateBinaries, and if an external tool changes the developers have to scramble to update vim-go to work.

I wanted to experiment with a different approach: vendor external tools in the plugin directory and run those so the correct version is always used. Since this directory is prepended to $PATH other plugins (such as ALE) will also use these vendored tools.

Overall, this seems to work quite well. Starting with a clean slate made it a lot easier to develop this as a proof-of-concept.

A second reason was to see how well a Go plugin would work without adding a lot of "generic" functionality. A lot of effort in vim-go is spent on stuff like completion, linting, and other features that are not specific to Go. I've never used vim-go's linting or gofmt support, as I found that ALE always worked better and gives a more consistent experience across filetypes. Also see my comments here.

When vim-go was started in 2014 (based on older work before that) a lot of the generic tools were non-existent or in their infancy. In the meanwhile these tools have matured significantly; what were the best choices in 2014 are not necessarily the best choices today.

gopher.vim is my idea of "vim-go 2.0". It retains vim-go's commit history. While there have been large changes, it also retains some concepts and ideas. vim-go is the giant's shoulders on which gopher.vim stands.

govim is another attempt at a modern Go plugin, and seems to have the same conceptual approach as vim-go: reinvent all the things. To be honest I didn't look too closely at it (gopher.vim was already fully functional and correct by the time govim was announced).

More Repositories

1

goatcounter

Easy web analytics. No tracking of personal data.
Go
4,235
star
2

uni

Query the Unicode database from the commandline, with good support for emojis
Go
776
star
3

hello-css

A CSS template focused on readability
CSS
178
star
4

find-cursor

Highlight the cursor position in X11
C
167
star
5

zcache

In-memory key:value store/cache (similar to Memcached) library for Go, suitable for single-machine applications
Go
61
star
6

dotfiles

My configuration files
Shell
60
star
7

zli

Go library for writing CLI programs. Includes flag parsing, colours, testing, and various helpful utility functions
Go
39
star
8

jumpy.vim

Filetype-specific mappings for [[, ]], g[, and g]
Vim Script
38
star
9

arp242.net

This is my site. There are many like it, but this one is mine.
HTML
34
star
10

gogo-release

Build cross-platform binaries for Go
Shell
32
star
11

singlepage

Bundle external assets in a HTML file to distribute a stand-alone HTML document.
Go
26
star
12

toml-c

TOML C library
C
26
star
13

info

A simple GNU info replacement which isn't terrible
Go
24
star
14

bestasciitable

The bestβ„’ ASCII table
HTML
20
star
15

isbot

Go library to detect HTTP bots.
Go
19
star
16

follow

Go library to follow a file for changes; e.g. "tail -F".
Go
19
star
17

download-npo

Download episodes from the Dutch npostart.nl βˆ’ Download afleveringen van npostart.nl
Python
18
star
18

undofile_warn.vim

Warn when using the undofile
Vim Script
18
star
19

sconfig

Simple and functional configuration file parser for Go.
Go
17
star
20

vimlog

A ChangeLog for Vim
HTML
16
star
21

packman.vim

Simple Vim plugin/package manager
Shell
14
star
22

runbuf.vim

Run the contents of a buffer in psql, python, bash, etc.
Vim Script
13
star
23

startscreen.vim

Customize Vim's start screen.
Vim Script
12
star
24

testing.vim

Comprehensive testing tool for Vim
Shell
12
star
25

ttftrim

Remove glyps from TTF fonts
Python
11
star
26

zdb

Interact with SQL databases in Go
Go
11
star
27

readon.js

Continue reading a web page from where you left last time
JavaScript
11
star
28

xdg_open.vim

Run xdg-open from Vim; re-implements netrw's gx.
Vim Script
11
star
29

auto_mkdir2.vim

Automatically create directories
Vim Script
10
star
30

zhttp

Martin's HTTP package
Go
10
star
31

MartinFox

Really simple userChrome.css for Firefox 89 to make the active tab stand out more
CSS
10
star
32

switchy.vim

Switch to related files
Vim Script
9
star
33

gadget

Go library to get the browser and OS from the User-Agent header.
Go
9
star
34

zprof

Display runtime profiling data for Go programs over HTTP
Go
9
star
35

my-first-vimrc

A vimrc generator that doesn't add a world of complexity
HTML
9
star
36

ff-hist

Search Firefox history from commandline
Shell
9
star
37

zsrv

Static file server which packs all data in the binary
Go
9
star
38

pkg_clearleaves

Easily remove packages on which no other packages depend
Python
8
star
39

blackmail

Go package to send emails with a friendly API
Go
8
star
40

lpeg.vim

LPeg-based syntax highlighting in Vim
Lua
8
star
41

colorcount

Display the colours used in a PNG image
Go
7
star
42

goatcounter-wordpress

WordPress plugin for GoatCounter
PHP
7
star
43

transip-dynamic

Dynamic DNS for TransIP
Go
6
star
44

imgzoom.js

JavaScript image zoomer
HTML
6
star
45

goimport

Add, remove, or replace imports in Go files
Go
6
star
46

sanitize_files

Basic cleanup of your code
Python
6
star
47

battray

Display tray icon with battery status; can also run scripts when the status changes
Python
5
star
48

helplink.vim

Link to Vim help pages with ease.
Vim Script
5
star
49

zev.vim

Easily apply predefined substitute patterns
Vim Script
5
star
50

zstd

Extensions to Go's stdlib
Go
5
star
51

gomodgraph

'go mod graph' as a nicely indented graph
Go
5
star
52

trackwall

DNS proxy and filter βˆ’ /etc/hosts on steroids.
Go
4
star
53

rogue-clone

The "rogue" game from 4.3BSD-Tahoe, for modern systems.
C
4
star
54

goon

Run Go on another machine such as a QEMU VM or cloud instance
Shell
4
star
55

lazy.vim

The really simple snippet manager
Vim Script
4
star
56

border

Commandline tool to add a border around PNG images
Go
4
star
57

batchy.vim

A little plugin to perform batch operations on files
Vim Script
4
star
58

cantuse

List browsers in which a feature *won't* work
Go
3
star
59

confirm_quit.vim

Ask for confirmation before quitting Vim.
Vim Script
3
star
60

goatcov

Code coverage tool for Go
Go
3
star
61

bsdgrep

BSD grep from FreeBSD for Linux
C
3
star
62

zvalidate

Static validation for Go that returns parsed values
Go
3
star
63

autofox

Automatically configure Firefox
Go
3
star
64

tz

Go timezone convience library
Go
3
star
65

errors

Yet another errors package for Go
Go
3
star
66

wtff

frontend for some ffmpeg operations
Go
3
star
67

sqlbench

Run benchmarks on an SQL database
Go
3
star
68

zlog

Go logging library
Go
3
star
69

acidtab

Go package to print nicely aligned tables in the terminal
Go
3
star
70

git-stats

Aggregate statistics for git repos
Go
3
star
71

slog_align

Less "wall of text"-y slog handler
Go
3
star
72

aurgit

A simple way to manage AUR packages
Python
2
star
73

hubhub

Set of utility functions for working with the GitHub API.
Go
2
star
74

pg_info

Make it a bit easier to read the various pg_stat_* tables in PostgreSQL (WIP!)
Go
2
star
75

complete_email.vim

Allow completion of email addresses so you can use Vim as a basic "address book".
Vim Script
2
star
76

globedit.vim

Use globbing patterns for :edit, :tabedit, etc.
Vim Script
2
star
77

goathost

Shell
2
star
78

z18n

i18n library for Go
Go
2
star
79

RimWorld-RainingBlood

Example RimWorld mod
C#
2
star
80

ADVENT

Colossal Cave Adventure for modern systems, as close to the 1976 source as possible
Fortran
2
star
81

termfo

A terminfo library for Go
Go
2
star
82

jfmt

Format json, nicely
Go
2
star
83

toml-test-matrix

HTML
2
star
84

spamdb-curses

Curses tools to interface with OpenBSD's spamdb(8), which is a part of spamd(8).
Python
1
star
85

json

encoding/json with patches
Go
1
star
86

zstripe

Set of utility functions for working with the Stripe API.
Go
1
star
87

imlib2-heif

Imlib2 plugin for libheif, allowing you to load HEIF, HEIC, and AVIF images (e.g. as used by iPhones)
C
1
star
88

operapass

Read opera password files (a.k.a. "the wand").
Python
1
star
89

markdown-wiki

Simple wiki.
Ruby
1
star
90

har

Read HAR ("HTTP Archive format") files
Go
1
star
91

nordavind

Web based audio player.
CoffeeScript
1
star
92

tpad.zsh

A little script to control some various things on my ThinkPad
Shell
1
star
93

zgo.at

zgo.at website
HTML
1
star
94

synfo.vim

Print information about Vim syntax highlighting and text properties
Vim Script
1
star
95

uni-wasm

WASM demo for uni
JavaScript
1
star
96

robots

Reproduction of the 1980 β€œclassic” robots game for BSD UNIX written by Ken Arnold. You can play it in your browser at: http://arp242.net/robots/
CoffeeScript
1
star