goplay.nvim is a local go playground for Neovim. Goplay.nvim uses locally installed Go tool to prepare and run the code from the playground.
Install the plugin via your favorite plugins manager, e.g.:
use "jeniasaigak/goplay.nvim"
Then you may add the following Lua code to setup the plugin:
require('goplay').setup()
goplay.nvim comes with the following defaults:
{
template = require("goplay.templates").default, -- template which will be used as the default content for the playground
mode = "vsplit", -- current/split/[vsplit] specifies where the playground will be opened
playgroundDirName = "goplayground", -- a name of the directory under GOPATH/src where the playground will be saved
tempPlaygroundDirName = "goplayground_temp", -- a name of the directory under GOPATH/src where the temporary playground will be saved. This option is used when you need to execute a file
output_mode = "formatted", -- [formatted]/raw mode to display output
}
Command | Lua | Description |
---|---|---|
:GPOpen |
require("goplay").goPlaygroundOpen() |
opens a playground; this command will prepare playground directory & files if needed |
:GPToggle |
require("goplay").goPlaygroundToggle() |
executes open command if the playground is closed, or close command otherwise |
:GPExec |
require("goplay").goExecPlayground() |
executes the code at the playground and prints the results |
:GPClose |
require("goplay").goPlaygroundClose() |
close a playground |
:GPClear |
require("goplay").deletePlayground() |
removes the playground folder |
:GPExecFile |
require("goplay").goExecFileAsPlayground() |
simply execute lines from currently opened buffer as go file and show the results |
Here are recommended keybindings to use:
vim.api.nvim_set_keymap('n', '<leader>gpt', ':GPToggle<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>gpe', ':GPExec<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>gpf', ':GPExecFile<CR>', { noremap = true, silent = true })