diff --git a/README.md b/README.md index 920da1d..1d80054 100644 --- a/README.md +++ b/README.md @@ -27,22 +27,40 @@ vim.g.symbols_outline = { highlight_hovered_item = true, show_guides = true, position = 'right', + keymaps = { + close = "", + goto_location = "", + focus_location = "o", + hover_symbol = "", + rename_symbol = "r", + code_actions = "a", + }, } ``` ```vim " init.vim -let g:symbols_outline = {} -let g:symbols_outline.highlight_hovered_item = v:true -let g:symbols_outline.show_guides = v:true -let g:symbols_outline.position = 'right' +let g:symbols_outline = { + \ "highlight_hovered_item": v:true, + \ "show_guides": v:true, + \ "position": 'right', + \ "keymaps": { + \ "close": "", + \ "goto_location": "", + \ "focus_location": "o", + \ "hover_symbol": "", + \ "rename_symbol": "r", + \ "code_actions": "a", + \ }, +\ } ``` -| Property | Description | Type | Default | -| --- | -- | -- | -- | -| highlight_hovered_item | Whether to highlight the currently hovered symbol (high cpu usage) | boolean | true | -| show_guides | Wether to show outline guides | boolean | true | -| position | Where to open the split window | 'right' or 'left' | 'right' | +| Property | Description | Type | Default | +| ---------------------- | ------------------------------------------------------------------ | ----------------- | ------------------------ | +| highlight_hovered_item | Whether to highlight the currently hovered symbol (high cpu usage) | boolean | true | +| show_guides | Wether to show outline guides | boolean | true | +| position | Where to open the split window | 'right' or 'left' | 'right' | +| keymaps | Which keys do what | table | [here](#default-keymaps) | ### Commands @@ -52,14 +70,14 @@ let g:symbols_outline.position = 'right' | `:SymbolsOutlineOpen` | Open symbols outline | | `:SymbolsOutlineClose` | Close symbols outline | -### Keymaps +### Default keymaps -| Key | Action | -| -- | -- | -| Escape | Close outline | -| Enter | Go to symbol location in code | -| o | Go to symbol location in code without losing focus | -| Ctrl+Space | Hover current symbol | -| r | Rename symbol | -| a | Code actions | +| Key | Action | +| ---------- | -------------------------------------------------- | +| Escape | Close outline | +| Enter | Go to symbol location in code | +| o | Go to symbol location in code without losing focus | +| Ctrl+Space | Hover current symbol | +| r | Rename symbol | +| a | Code actions | diff --git a/lua/symbols-outline.lua b/lua/symbols-outline.lua index c2830b0..a085e62 100644 --- a/lua/symbols-outline.lua +++ b/lua/symbols-outline.lua @@ -67,8 +67,8 @@ end function M._goto_location(change_focus) local current_line = vim.api.nvim_win_get_cursor(M.state.outline_win)[1] local node = M.state.flattened_outline_items[current_line] - vim.api.nvim_win_set_cursor(M.state.code_win, {node.line + 1, - node.character}) + vim.api.nvim_win_set_cursor(M.state.code_win, + {node.line + 1, node.character}) if change_focus then vim.fn.win_gotoid(M.state.code_win) end end @@ -129,27 +129,31 @@ end local function setup_keymaps(bufnr) -- goto_location of symbol and focus that window - vim.api.nvim_buf_set_keymap(bufnr, "n", "", + vim.api.nvim_buf_set_keymap(bufnr, "n", + config.options.keymaps.goto_location, ":lua require('symbols-outline')._goto_location(true)", {}) -- goto_location of symbol but stay in outline - vim.api.nvim_buf_set_keymap(bufnr, "n", "o", + vim.api.nvim_buf_set_keymap(bufnr, "n", + config.options.keymaps.focus_location, ":lua require('symbols-outline')._goto_location(false)", {}) -- hover symbol - vim.api.nvim_buf_set_keymap(bufnr, "n", "", + vim.api.nvim_buf_set_keymap(bufnr, "n", config.options.keymaps.hover_symbol, ":lua require('symbols-outline.hover').show_hover()", {}) -- rename symbol - vim.api.nvim_buf_set_keymap(bufnr, "n", "r", + vim.api.nvim_buf_set_keymap(bufnr, "n", + config.options.keymaps.rename_symbol, ":lua require('symbols-outline.rename').rename()", {}) -- code actions - vim.api.nvim_buf_set_keymap(bufnr, "n", "a", + vim.api.nvim_buf_set_keymap(bufnr, "n", config.options.keymaps.code_actions, ":lua require('symbols-outline.code_action').show_code_actions()", {}) - -- close outline when escape is pressed - vim.api.nvim_buf_set_keymap(bufnr, "n", "", ":bw!",{}) + -- close outline + vim.api.nvim_buf_set_keymap(bufnr, "n", config.options.keymaps.close, + ":bw!", {}) end ---------------------------- diff --git a/lua/symbols-outline/config.lua b/lua/symbols-outline/config.lua index 17dc574..8f6bf17 100644 --- a/lua/symbols-outline/config.lua +++ b/lua/symbols-outline/config.lua @@ -5,7 +5,15 @@ local M = {} local defaults = { highlight_hovered_item = true, show_guides = true, - position = 'right' + position = 'right', + keymaps = { + close = "", + goto_location = "", + focus_location = "o", + hover_symbol = "", + rename_symbol = "r", + code_actions = "a", + } } M.options = {}