Setting up Kakoune for Go
I've been using the Kakoune text editor with Go
for about half a year. If you're not familiar with it, Kakoune is a
modal text editor that's loosely based on vim, but re-designed to make
the editing commands simpler and consistent. Making it work well with Go
required adding just a few lines to the configuration file (usually
~/.config/kak
):
try %{
source-runtime rc/tools/format.kak
}
hook global WinSetOption filetype=go %{
set-option buffer tabstop 4
set-option buffer indentwidth 0
set-option buffer formatcmd 'gofmt'
hook buffer BufWritePre .* format-buffer
}
To clear, this won't turn Kakoune into an IDE -- for that, take a look at kak-lsp or, you know, an actual IDE. It just sets up two things:
- Indentation is done with tabs, and tabs are shown as 4 spaces.
- Go source files are formatted with
gofmt
before saving. To make that work, the configuration above loads the fileformat.kak
, which is installed with Kakoune, and configures it to use thegofmt
command whenever a Go file is saved.