Last active
September 23, 2023 13:47
-
-
Save mengwangk/132766f0c44973c60fd202201c4b053f to your computer and use it in GitHub Desktop.
Neovim Plugins and Configuration Recipes | 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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