diff options
author | max397574 <[email protected]> | 2021-12-05 20:32:39 +0100 |
---|---|---|
committer | max397574 <[email protected]> | 2021-12-05 20:32:39 +0100 |
commit | 6de8c98b8e8798e99eaf20a033c6754790251f6c (patch) | |
tree | 1d74e36923c909ee443a71b461a5da709704d190 /lua/startup | |
parent | e8514ac83e552fc5840b6db2723ce6dde9a12155 (diff) |
feat(utils): add user mapping to help
Diffstat (limited to 'lua/startup')
-rw-r--r-- | lua/startup/utils.lua | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/lua/startup/utils.lua b/lua/startup/utils.lua index 050df57..0dd6b3b 100644 --- a/lua/startup/utils.lua +++ b/lua/startup/utils.lua @@ -76,36 +76,63 @@ function U.empty(amount) end end +local function parse_mapping(mapping) + mapping = string.gsub(mapping, "C%-", "ctrl+") + mapping = string.gsub(mapping, "c%-", "ctrl+") + mapping = string.gsub(mapping, "%<leader%>","leader+") + mapping = string.gsub(mapping, "%<(.+)%>", "%1") + return mapping +end + ---open float with all the keybindings function U.key_help() local ns = vim.api.nvim_create_namespace("Float help") local settings = require("startup").settings local buf = vim.api.nvim_create_buf(false, true) + local user_mappings = require"startup".user_mappings set_buf_opt(buf, "bufhidden", "wipe") local lines = { " Startup.nvim Mappings ", "", - " Execute command: " .. settings.mappings.execute_command, - " Open file: " .. settings.mappings.open_file, - " Open file in split: " .. settings.mappings.open_file_split, - " Open section: " .. settings.mappings.open_section, - "", + " Execute command: " .. parse_mapping(settings.mappings.execute_command) , + " Open file: " .. parse_mapping(settings.mappings.open_file) , + " Open file in split: " .. parse_mapping(settings.mappings.open_file_split) , + " Open section: " .. parse_mapping(settings.mappings.open_section) , } + if not vim.tbl_isempty(user_mappings) then + table.insert(lines,"") + table.insert(lines," User Mappings:") + table.insert(lines,"") + for rhs, lhs in pairs(user_mappings) do + table.insert(lines," "..lhs..":"..U.spaces(35-#lhs)..parse_mapping(rhs)) + end + end vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines) + local height = 6 + if not vim.tbl_isempty(user_mappings) then + height = 9+vim.tbl_count(user_mappings) + end help_window = vim.api.nvim_open_win(buf, false, { relative = "cursor", - width = 30, - height = 6, + width = 55, + height = height, col = 0, row = 1, border = "shadow", style = "minimal", }) + if not vim.tbl_isempty(user_mappings) then + vim.api.nvim_buf_add_highlight(buf, ns, "Special", 7, 1, -1) + for i = 9, 9+vim.tbl_count(user_mappings), 1 do + vim.api.nvim_buf_add_highlight(buf, ns, "String", i, 36, -1) + vim.api.nvim_buf_add_highlight(buf, ns, "Number", i, 1, 35) + end + end vim.api.nvim_win_set_option(help_window, "winblend", 20) vim.api.nvim_buf_add_highlight(buf, ns, "Special", 0, 1, -1) for i = 2, 5, 1 do - vim.api.nvim_buf_add_highlight(buf, ns, "String", i, 21, -1) - vim.api.nvim_buf_add_highlight(buf, ns, "Number", i, 1, 20) + vim.api.nvim_buf_add_highlight(buf, ns, "String", i, 24, -1) + vim.api.nvim_buf_add_highlight(buf, ns, "Number", i, 1, 23) end set_buf_opt(buf, "modifiable", false) vim.cmd( @@ -321,6 +348,8 @@ end ---set all the options that should be set for the startup buffer function U.set_buf_options() local settings = require("startup").settings + local last_status = vim.api.nvim_get_option("laststatus") + local tab_line = vim.api.nvim_get_option("showtabline") set_buf_opt(0, "bufhidden", "wipe") set_buf_opt(0, "buftype", "nofile") vim.cmd([[set wrap]]) @@ -333,6 +362,10 @@ function U.set_buf_options() set_buf_opt(0, "filetype", "startup") set_buf_opt(0, "swapfile", false) vim.cmd([[setlocal nonu nornu]]) + vim.api.nvim_set_current_dir( + vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ':h') + ) + vim.cmd([[autocmd BufEnter * lua if vim.opt.filetype~="startup" then vim.opt.laststatus=]]..last_status..[[;vim.opt.showtabline=]]..tab_line..[[ end]]) end ---validate the settings |