From e54b4af46f8a658e4d3c5144828c7859a59461cc Mon Sep 17 00:00:00 2001 From: max397574 Date: Sun, 24 Oct 2021 15:22:47 +0200 Subject: =?UTF-8?q?feat(plugins):=20=E2=9C=A8added=20key=20help?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/startup.lua | 7 +++++++ lua/startup/themes/default.lua | 1 + lua/startup/utils.lua | 40 ++++++++++++++++++++++++++++++++++++++++ readme.md | 1 + 4 files changed, 49 insertions(+) diff --git a/lua/startup.lua b/lua/startup.lua index 87bf597..23a4917 100644 --- a/lua/startup.lua +++ b/lua/startup.lua @@ -84,6 +84,13 @@ local function create_mappings(mappings) "lua require('startup').open_file_vsplit()", opts ) + vim.api.nvim_buf_set_keymap( + 0, + "n", + settings.mappings.open_help, + "lua require'startup.utils'.key_help()", + opts + ) if mappings ~= {} then for _, cmd in pairs(mappings) do vim.api.nvim_buf_set_keymap( diff --git a/lua/startup/themes/default.lua b/lua/startup/themes/default.lua index 407cdba..43dc299 100644 --- a/lua/startup/themes/default.lua +++ b/lua/startup/themes/default.lua @@ -55,6 +55,7 @@ local settings = { open_file = "o", open_file_split = "", open_section = "", + open_help = "?", }, colors = { background = "#1f2227", diff --git a/lua/startup/utils.lua b/lua/startup/utils.lua index aa343b8..eb522b5 100644 --- a/lua/startup/utils.lua +++ b/lua/startup/utils.lua @@ -1,5 +1,6 @@ U = {} local flag = false +local settings = require "startup.config" local function start_timeout() flag = true vim.defer_fn(function() @@ -20,6 +21,45 @@ function U.spaces(amount) return string.rep(" ", amount) end +function U.key_help() + local buf = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe") + vim.api.nvim_buf_set_keymap( + buf, + "n", + "", + "q", + { noremap = true, silent = true, nowait = true } + ) + vim.api.nvim_buf_set_keymap( + buf, + "n", + "q", + "q", + { noremap = true, silent = true, nowait = true } + ) + local lines = { + "startup.nvim mapping:", + "", + "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, + } + vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines) + local win = vim.api.nvim_open_win(buf, true, { + relative = "cursor", + width = 30, + height = 6, + col = 1, + row = 1, + border = "shadow", + style = "minimal", + }) + vim.api.nvim_win_set_option(win, "winblend", 20) + vim.api.nvim_buf_set_option(buf, "modifiable", false) +end + function U.default_header() local header = { " /$$ ", diff --git a/readme.md b/readme.md index 3c2b914..f570c1f 100644 --- a/readme.md +++ b/readme.md @@ -82,6 +82,7 @@ settings = { open_file = , open_file_split = , open_section = , + open_help = , }, colors = { background = , -- hex color code -- cgit v1.2.3