diff options
author | max397574 <[email protected]> | 2021-10-05 20:11:45 +0200 |
---|---|---|
committer | max397574 <[email protected]> | 2021-10-05 20:11:45 +0200 |
commit | db2f9b522b74390e3cb7a1b299b08a708cc98391 (patch) | |
tree | a6bc2d1236307765cf2e53b969e4534ab8ba1edc /lua/startuptools.lua | |
parent | 9ff3a1760b9b9e16984bf1245b043fc2404f8f53 (diff) |
feat: ✨added mappings and refactor
Diffstat (limited to 'lua/startuptools.lua')
-rw-r--r-- | lua/startuptools.lua | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/lua/startuptools.lua b/lua/startuptools.lua index 77efa7a..dfa456a 100644 --- a/lua/startuptools.lua +++ b/lua/startuptools.lua @@ -17,17 +17,33 @@ local settings = { }, -- name which will be displayed and command tools = { - [" Find File"] = "Telescope find_files", - [" Find Word"] = "Telescope live_grep", - [" Recent Files"] = "Telescope oldfiles", - [" File Browser"] = "Telescope file_browser", - [" Config Files"] = 'lua require("telescope.builtin").find_files({cwd="~/.config"})', - [" Colorschemes"] = "Telescope colorscheme", - [" New File"] = "lua require'startuptools'.new_file()", + [" Find File"] = {"Telescope find_files", "<leader>ff"}, + [" Find Word"] = {"Telescope live_grep", "<leader>lg"}, + [" Recent Files"] = {"Telescope oldfiles", "<leader>of"}, + [" File Browser"] = {"Telescope file_browser", "<leader>fb"}, + [" Config Files"] = {'lua require("telescope.builtin").find_files({cwd="~/.config"})', "<leader>cf"}, + [" Colorschemes"] = {"Telescope colorscheme", "<leader>cs"}, + [" New File"] = {"lua require'startuptools'.new_file()", "<leader>nf"}, }, - mappings = {}, + options = { + align = "center", + mapping_names = true, + } } +local function create_mappings() + vim.api.nvim_buf_set_keymap( + 0, + "n", + "<CR>", + ":lua require'startuptools'.check_line()<CR>", + opts + ) + for _, cmd in pairs(settings.tools) do + vim.api.nvim_buf_set_keymap(0, "n", cmd[2], "<cmd>"..cmd[1].."<CR>", opts) + end +end + function M.new_file() local name = vim.fn.input "Filename: > " vim.cmd("e " .. name) @@ -37,7 +53,7 @@ function M.check_line() local line = vim.api.nvim_get_current_line() for name, command in pairs(settings.tools) do if line:match(name) then - vim.cmd(command) + vim.cmd(command[1]) end end end @@ -78,23 +94,19 @@ local function set_options() end function M.display() - vim.api.nvim_buf_set_keymap( - 0, - "n", - "<CR>", - ":lua require'startuptools'.check_line()<CR>", - opts - ) + create_mappings() vim.api.nvim_buf_set_keymap(0, "n", "j", "2j", opts) vim.api.nvim_buf_set_keymap(0, "n", "k", "2k", opts) - -- vim.api.nvim_buf_set_keymap(0, "n", "h", "<NOP>", opts) - -- vim.api.nvim_buf_set_keymap(0, "n", "l", "<NOP>", opts) empty() set_lines(#settings.header, settings.header, "TSString") local toolnames = {} - for name, _ in pairs(settings.tools) do + for name, cmd in pairs(settings.tools) do table.insert(toolnames, " ") - table.insert(toolnames, name) + if settings.options.mapping_names then + table.insert(toolnames, name .. " " .. cmd[2]) + else + table.insert(toolnames, name) + end end empty() set_lines(#toolnames, toolnames, "TSString") @@ -105,7 +117,6 @@ end function M.setup(update) settings = vim.tbl_deep_extend("force", settings, update or {}) - vim.cmd [[ autocmd StdinReadPre * let s:std_in=1 autocmd VimEnter * lua if vim.fn.argc() == 0 and vim.fn.exists('std_in') then require"startuptools".display() end |