diff options
-rw-r--r-- | README.md | 58 | ||||
-rw-r--r-- | lua/nvterm/init.lua | 51 |
2 files changed, 28 insertions, 81 deletions
@@ -1,12 +1,10 @@ -# NvChad Official Terminal Plugin +# NvChad terminal Plugin -## Setup +## Install -### Installation +- Simply install the plugin with packer as you would for any other: -Simply install the plugin with packer as you would for any other: - -``` +```lua use { "NvChad/nvterm", config = function () @@ -16,8 +14,9 @@ use { ``` ### Configuration -Pass a table of configuration options to the plugin's `.setup()` function above. -A sample configuration table with the default options is shown below: + +- Pass a table of configuration options to the plugin's `.setup()` function above. +- Default configuration table ```lua require("nvterm").setup({ @@ -40,26 +39,9 @@ require("nvterm").setup({ close_on_exit = true, auto_insert = true, }, - mappings = { - toggle = { - float = "<A-i>", - horizontal = "<A-h>", - vertical = "<A-v>", - }, - new = { - horizontal = "<C-h>", - vertical = "<C-v>", - }, - }, - enable_new_mappings = false, }) ``` -``` -By default, the mappings for creating a new terminal rather than toggling the current one are disabled. -If `enable_new_mappings` is set to true, `new` will be set to any mappings passed in the configuration table under `new` or the defaults. -``` -A shortcut is available for setting options of the different terminal types and mappings: ```lua require("nvterm").setup({ float = { @@ -72,11 +54,6 @@ require("nvterm").setup({ }, horizontal = { location = "rightbelow", split_ratio = .3, }, vertical = { location = "rightbelow", split_ratio = .5 }, - mappings{ - toggle { - horizontal = "<A-s>" - } - } }) ``` @@ -104,9 +81,29 @@ require("nvterm").setup({ }) ``` +### Functions + +Use the below functions to map them for keybindings + +#### Toggle + +```lua +require("nvterm.terminal").toggle "float" +require("nvterm.terminal").toggle "horizontal" +require("nvterm.terminal").toggle "vertical" +``` + +#### Spawn new terminals + +```lua +require("nvterm.terminal").new "horizontal" +require("nvterm.terminal").new "vertical" +``` + ### Additional Functionality NvTerm provides an api for you to send commands to the terminal. You can create different ones for different filetypes like so: + ```lua require("nvterm").setup() @@ -131,4 +128,3 @@ end `terminal.send` also takes a 'type' parameter, so you can choose what type of terminal to send the command to. By default, it runs the command in the last opened terminal, or a vertical one if none exist. `terminal.send(ft_cmds[vim.bo.filetype], "float")` will run the command in a floating terminal - diff --git a/lua/nvterm/init.lua b/lua/nvterm/init.lua index c354e6b..3794f35 100644 --- a/lua/nvterm/init.lua +++ b/lua/nvterm/init.lua @@ -20,18 +20,6 @@ local defaults = { close_on_exit = true, auto_insert = true, }, - mappings = { - toggle = { - float = "<A-i>", - horizontal = "<A-h>", - vertical = "<A-v>", - }, - new = { - horizontal = "<leader>h", - vertical = "<leader>v", - }, - }, - enable_new_mappings = false, } local set_behavior = function(behavior) @@ -60,47 +48,10 @@ local set_behavior = function(behavior) end end -M.create_mappings = function(method, map_table, opts) - opts = opts or {} - vim.tbl_deep_extend("force", { noremap = true, silent = true }, opts) - for type, mapping in pairs(map_table) do - vim.keymap.set({ "n", "t" }, mapping, function() - require("nvterm.terminal")[method](type) - end, opts) - end -end - -local setup_mappings = function(mappings) - for method, map_table in pairs(mappings) do - M.create_mappings(method, map_table) - end -end - -local map_config_shortcuts = function(config) - local shortcuts = { - { config.terminals.type_opts, { "horizontal", "vertical", "float" } }, - { config.mappings, { "toggle", "new" } }, - } - - for _, shortcut_map in ipairs(shortcuts) do - for _, key in ipairs(shortcut_map[2]) do - config[key] = config[key] or {} - shortcut_map[1][key] = shortcut_map[1][key] or {} - shortcut_map[1][key] = vim.tbl_deep_extend("force", shortcut_map[1][key], config[key] or {}) - end - end - - return config -end - M.setup = function(config) config = config and vim.tbl_deep_extend("force", defaults, config) or defaults - set_behavior(config.behavior) - config = map_config_shortcuts(config) - config.mappings.new = config.enable_new_mappings and config.mappings.new or nil - - setup_mappings(config.mappings) + set_behavior(config.behavior) require("nvterm.terminal").init(config.terminals) end |