feat(config): Allow configuring keymaps

Closes #1
This commit is contained in:
simrat39
2021-04-28 15:03:40 -07:00
parent abe479fe69
commit 067fd91f16
3 changed files with 58 additions and 28 deletions

View File

@@ -27,22 +27,40 @@ vim.g.symbols_outline = {
highlight_hovered_item = true,
show_guides = true,
position = 'right',
keymaps = {
close = "<Esc>",
goto_location = "<Cr>",
focus_location = "o",
hover_symbol = "<C-space>",
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": "<Esc>",
\ "goto_location": "<Cr>",
\ "focus_location": "o",
\ "hover_symbol": "<C-space>",
\ "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' |
| keymaps | Which keys do what | table | [here](#default-keymaps) |
### Commands
@@ -52,10 +70,10 @@ 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 |

View File

@@ -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", "<Cr>",
vim.api.nvim_buf_set_keymap(bufnr, "n",
config.options.keymaps.goto_location,
":lua require('symbols-outline')._goto_location(true)<Cr>",
{})
-- 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)<Cr>",
{})
-- hover symbol
vim.api.nvim_buf_set_keymap(bufnr, "n", "<C-space>",
vim.api.nvim_buf_set_keymap(bufnr, "n", config.options.keymaps.hover_symbol,
":lua require('symbols-outline.hover').show_hover()<Cr>",
{})
-- 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()<Cr>",
{})
-- 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()<Cr>",
{})
-- close outline when escape is pressed
vim.api.nvim_buf_set_keymap(bufnr, "n", "<Esc>", ":bw!<Cr>",{})
-- close outline
vim.api.nvim_buf_set_keymap(bufnr, "n", config.options.keymaps.close,
":bw!<Cr>", {})
end
----------------------------

View File

@@ -5,7 +5,15 @@ local M = {}
local defaults = {
highlight_hovered_item = true,
show_guides = true,
position = 'right'
position = 'right',
keymaps = {
close = "<Esc>",
goto_location = "<Cr>",
focus_location = "o",
hover_symbol = "<C-space>",
rename_symbol = "r",
code_actions = "a",
}
}
M.options = {}