Skip to content

Instantly share code, notes, and snippets.

@mengwangk
Last active September 23, 2023 13:47
Show Gist options
  • Save mengwangk/132766f0c44973c60fd202201c4b053f to your computer and use it in GitHub Desktop.
Save mengwangk/132766f0c44973c60fd202201c4b053f to your computer and use it in GitHub Desktop.
Neovim Plugins and Configuration Recipes | 3
local M = {}
local function default_on_open(term)
vim.cmd "startinsert"
vim.api.nvim_buf_set_keymap(term.bufnr, "n", "q", "<cmd>close<CR>", { noremap = true, silent = true })
end
function M.open_term(cmd, opts)
opts = opts or {}
opts.size = opts.size or vim.o.columns * 0.5
opts.direction = opts.direction or "float"
opts.on_open = opts.on_open or default_on_open
opts.on_exit = opts.on_exit or nil
opts.dir = opts.dir or "git_dir"
local Terminal = require("toggleterm.terminal").Terminal
local new_term = Terminal:new {
cmd = cmd,
dir = opts.dir,
auto_scroll = false,
close_on_exit = false,
on_open = opts.on_open,
on_exit = opts.on_exit,
}
new_term:open(opts.size, opts.direction)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment