aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzbirenbaum <zacharyobirenbaum@gmail.com>2022-04-25 04:39:51 -0400
committerzbirenbaum <zacharyobirenbaum@gmail.com>2022-04-25 04:39:51 -0400
commitf0717aa4a157bda5b1dc128908adca4bdb7556c6 (patch)
tree2ffda6442d255bb093e4e15844d102a6c77f8e32
parentadd enable flag for new mappings (diff)
finish shortcut method and update readmedev
-rw-r--r--README.md32
-rw-r--r--lua/nvterm/init.lua22
2 files changed, 35 insertions, 19 deletions
diff --git a/README.md b/README.md
index c1188f8..dd06473 100644
--- a/README.md
+++ b/README.md
@@ -45,11 +45,21 @@ require("nvterm").setup({
float = "<A-i>",
horizontal = "<A-h>",
vertical = "<A-v>",
- }
- }
+ },
+ new = {
+ horizontal = "<C-h>",
+ vertical = "<C-v>",
+ },
+ },
+ enable_new_mappings = false,
})
```
-A shortcut is available for setting options of the different terminal types:
+
+```
+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 = {
@@ -62,6 +72,11 @@ require("nvterm").setup({
},
horizontal = { location = "rightbelow", split_ratio = .3, },
vertical = { location = "rightbelow", split_ratio = .5 },
+ mappings{
+ toggle {
+ horizontal = "<A-s>"
+ }
+ }
})
```
@@ -81,8 +96,11 @@ require("nvterm").setup({
},
horizontal = { location = "rightbelow", split_ratio = .3, },
vertical = { location = "rightbelow", split_ratio = .5 },
- }
- }
+ },
+ },
+ toggle {
+ horizontal = "<A-s>",
+ },
})
```
@@ -101,8 +119,8 @@ local ft_cmds = {
}
local mappings = {
{ 'n', '<C-l>', function () terminal.send(ft_cmds[vim.bo.filetype]) end },
- { 'n', '<Leader>s', function () terminal.new_or_toggle('horizontal') end },
- { 'n', '<Leader>v', function () terminal.new_or_toggle('vertical') end },
+ { 'n', '<Leader>s', function () terminal.toggle('horizontal') end },
+ { 'n', '<Leader>v', function () terminal.toggle('vertical') end },
}
local opts = { noremap = true, silent = true }
for _, mapping in ipairs(mappings) do
diff --git a/lua/nvterm/init.lua b/lua/nvterm/init.lua
index 9a1d930..45aa254 100644
--- a/lua/nvterm/init.lua
+++ b/lua/nvterm/init.lua
@@ -70,25 +70,23 @@ local setup_mappings = function (mappings)
end
end
-local map_config_shortcuts = function (config, location, shortcut)
- for _, key in ipairs(shortcut) do
- config[key] = config[key] or {}
- vim.tbl_deep_extend("force", location[key], config[key])
- config[key] = nil
- end
- return config
-end
-
-M.setup = function (config)
- config = config and vim.tbl_deep_extend("force", defaults, config) or defaults
+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
- map_config_shortcuts(config, shortcut_map[1], shortcut_map[2])
+ for _, key in ipairs(shortcut_map[2]) do
+ 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 or nil
setup_mappings(config.mappings)
require("nvterm.terminal").init(config.terminals)