Add better movement and LSP-related help
This commit is contained in:
parent
3ed9bfaee3
commit
e7a9bf5949
3
init.lua
3
init.lua
|
@ -549,6 +549,9 @@ require('lazy').setup({
|
||||||
-- For example, in C this would take you to the header.
|
-- For example, in C this would take you to the header.
|
||||||
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
|
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
|
||||||
|
|
||||||
|
map('<leader>ch', vim.lsp.buf.hover, '[C]ode [H]over item')
|
||||||
|
map('<leader>cd', vim.diagnostic.open_float, '[C]ode [D]iagnostic for current line')
|
||||||
|
|
||||||
-- The following two autocommands are used to highlight references of the
|
-- The following two autocommands are used to highlight references of the
|
||||||
-- word under your cursor when your cursor rests there for a little while.
|
-- word under your cursor when your cursor rests there for a little while.
|
||||||
-- See `:help CursorHold` for information about when this is executed
|
-- See `:help CursorHold` for information about when this is executed
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
"nvim-scrollview": { "branch": "main", "commit": "401c0498689dcaa54b2e7483d823e33cdc051e72" },
|
"nvim-scrollview": { "branch": "main", "commit": "401c0498689dcaa54b2e7483d823e33cdc051e72" },
|
||||||
"nvim-treesitter": { "branch": "master", "commit": "081dfa6e0f72f0440aefd808a46ea9e4ae48d263" },
|
"nvim-treesitter": { "branch": "master", "commit": "081dfa6e0f72f0440aefd808a46ea9e4ae48d263" },
|
||||||
"nvim-treesitter-context": { "branch": "master", "commit": "e6cc783b74606d97ca9eff6494e3f5c2ca603a50" },
|
"nvim-treesitter-context": { "branch": "master", "commit": "e6cc783b74606d97ca9eff6494e3f5c2ca603a50" },
|
||||||
|
"nvim-treesitter-textobjects": { "branch": "master", "commit": "3a3c6244553f13fdd92d312c82722b57ce6c4bec" },
|
||||||
"nvim-ts-autotag": { "branch": "main", "commit": "0cb76eea80e9c73b88880f0ca78fbd04c5bdcac7" },
|
"nvim-ts-autotag": { "branch": "main", "commit": "0cb76eea80e9c73b88880f0ca78fbd04c5bdcac7" },
|
||||||
"nvim-ts-context-commentstring": { "branch": "main", "commit": "375c2d86cee6674afd75b4f727ce3a80065552f7" },
|
"nvim-ts-context-commentstring": { "branch": "main", "commit": "375c2d86cee6674afd75b4f727ce3a80065552f7" },
|
||||||
"nvim-web-devicons": { "branch": "master", "commit": "3722e3d1fb5fe1896a104eb489e8f8651260b520" },
|
"nvim-web-devicons": { "branch": "master", "commit": "3722e3d1fb5fe1896a104eb489e8f8651260b520" },
|
||||||
|
|
|
@ -7,5 +7,10 @@ return {
|
||||||
},
|
},
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
require('lsp_signature').setup(opts)
|
require('lsp_signature').setup(opts)
|
||||||
|
|
||||||
|
vim.keymap.set('n', '<leader>cph', function()
|
||||||
|
-- NOTE: For now, have to close it manually
|
||||||
|
require('lsp_signature').toggle_float_win()
|
||||||
|
end, { noremap = true, silent = true, desc = '[C]ode [P]arameter [H]elp' })
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
-- https://github.com/nvim-treesitter/nvim-treesitter-context
|
-- https://github.com/nvim-treesitter/nvim-treesitter-context
|
||||||
return {
|
return {
|
||||||
'nvim-treesitter/nvim-treesitter-context',
|
'nvim-treesitter/nvim-treesitter-context',
|
||||||
|
dependencies = { 'nvim-treesitter/nvim-treesitter' },
|
||||||
opts = {},
|
opts = {},
|
||||||
|
config = function(_, opts)
|
||||||
|
require('treesitter-context').setup(opts)
|
||||||
|
vim.keymap.set('n', '<leader>tc', ':TSContextToggle<CR>', { noremap = true, silent = true, desc = '[T]oggle current [C]ontext' })
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,128 @@
|
||||||
|
-- https://github.com/nvim-treesitter/nvim-treesitter-textobjects
|
||||||
|
return {
|
||||||
|
'nvim-treesitter/nvim-treesitter-textobjects',
|
||||||
|
dependencies = { 'nvim-treesitter/nvim-treesitter' },
|
||||||
|
config = function()
|
||||||
|
---@diagnostic disable-next-line: missing-fields
|
||||||
|
require('nvim-treesitter.configs').setup {
|
||||||
|
textobjects = {
|
||||||
|
select = {
|
||||||
|
enable = true,
|
||||||
|
|
||||||
|
-- Automatically jump forward to textobj, similar to targets.vim
|
||||||
|
lookahead = true,
|
||||||
|
|
||||||
|
keymaps = {
|
||||||
|
-- You can use the capture groups defined in textobjects.scm
|
||||||
|
['af'] = { query = '@function.outer', desc = '[A]round a [F]unction' },
|
||||||
|
['if'] = { query = '@function.inner', desc = '[I]nside a [F]unction' },
|
||||||
|
['ac'] = { query = '@class.outer', desc = '[A]round of [C]lass' },
|
||||||
|
['a]'] = { query = '@class.outer', desc = '[A]round of Class' },
|
||||||
|
-- You can optionally set descriptions to the mappings (used in the desc parameter of
|
||||||
|
-- nvim_buf_set_keymap) which plugins like which-key display
|
||||||
|
['ic'] = { query = '@class.inner', desc = '[I]nner part of [C]lass' },
|
||||||
|
['i]'] = { query = '@class.inner', desc = '[I]nner part of Class' },
|
||||||
|
-- You can also use captures from other query groups like `locals.scm`
|
||||||
|
['as'] = { query = '@scope', query_group = 'locals', desc = 'Select language scope' },
|
||||||
|
},
|
||||||
|
-- You can choose the select mode (default is charwise 'v')
|
||||||
|
--
|
||||||
|
-- Can also be a function which gets passed a table with the keys
|
||||||
|
-- * query_string: eg '@function.inner'
|
||||||
|
-- * method: eg 'v' or 'o'
|
||||||
|
-- and should return the mode ('v', 'V', or '<c-v>') or a table
|
||||||
|
-- mapping query_strings to modes.
|
||||||
|
selection_modes = {
|
||||||
|
['@parameter.outer'] = 'v', -- charwise
|
||||||
|
['@function.outer'] = 'V', -- linewise
|
||||||
|
['@class.outer'] = '<c-v>', -- blockwise
|
||||||
|
},
|
||||||
|
-- If you set this to `true` (default is `false`) then any textobject is
|
||||||
|
-- extended to include preceding or succeeding whitespace. Succeeding
|
||||||
|
-- whitespace has priority in order to act similarly to eg the built-in
|
||||||
|
-- `ap`.
|
||||||
|
--
|
||||||
|
-- Can also be a function which gets passed a table with the keys
|
||||||
|
-- * query_string: eg '@function.inner'
|
||||||
|
-- * selection_mode: eg 'v'
|
||||||
|
-- and should return true or false
|
||||||
|
include_surrounding_whitespace = true,
|
||||||
|
},
|
||||||
|
swap = {
|
||||||
|
enable = true,
|
||||||
|
swap_next = {
|
||||||
|
['<leader>cpa'] = { query = '@parameter.inner', desc = '[C]ode [P]arameter [A]djust Next' },
|
||||||
|
},
|
||||||
|
swap_previous = {
|
||||||
|
['<leader>cpA'] = { query = '@parameter.inner', desc = '[C]ode [P]arameter [A]djust Previous' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
move = {
|
||||||
|
enable = true,
|
||||||
|
set_jumps = true, -- whether to set jumps in the jumplist
|
||||||
|
goto_next_start = {
|
||||||
|
[']f'] = { query = '@function.outer', desc = 'Next [F]unction Start' },
|
||||||
|
[']]'] = { query = '@class.outer', desc = 'Next Class Start' },
|
||||||
|
--
|
||||||
|
-- You can use regex matching (i.e. lua pattern) and/or pass a list in a "query" key to group multiple queries.
|
||||||
|
[']o'] = '@loop.*',
|
||||||
|
-- ["]o"] = { query = { "@loop.inner", "@loop.outer" } }
|
||||||
|
--
|
||||||
|
-- You can pass a query group to use query from `queries/<lang>/<query_group>.scm file in your runtime path.
|
||||||
|
-- Below example nvim-treesitter's `locals.scm` and `folds.scm`. They also provide highlights.scm and indent.scm.
|
||||||
|
[']s'] = { query = '@scope', query_group = 'locals', desc = 'Next [S]cope' },
|
||||||
|
[']z'] = { query = '@fold', query_group = 'folds', desc = 'Next Fold' },
|
||||||
|
},
|
||||||
|
goto_next_end = {
|
||||||
|
[']F'] = { query = '@function.outer', desc = 'Next [F]unction End' },
|
||||||
|
[']['] = { query = '@class.outer', desc = 'Next Class End' },
|
||||||
|
},
|
||||||
|
goto_previous_start = {
|
||||||
|
['[f'] = { query = '@function.outer', desc = 'Previous [F]unction Start' },
|
||||||
|
['[['] = { query = '@class.outer', desc = 'Previous Class Start' },
|
||||||
|
},
|
||||||
|
goto_previous_end = {
|
||||||
|
['[F'] = { query = '@function.outer', desc = 'Previous [F]unction End]' },
|
||||||
|
['[]'] = { query = '@class.outer', desc = 'Previous Class End' },
|
||||||
|
},
|
||||||
|
-- Below will go to either the start or the end, whichever is closer.
|
||||||
|
-- Use if you want more granular movements
|
||||||
|
-- Make it even more gradual by adding multiple queries and regex.
|
||||||
|
goto_next = {
|
||||||
|
[']c'] = { query = '@conditional.outer', desc = 'Next [C]onditional' },
|
||||||
|
},
|
||||||
|
goto_previous = {
|
||||||
|
['[c'] = { query = '@conditional.outer', desc = 'Previous [C]onditional]' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local ts_repeat_move = require 'nvim-treesitter.textobjects.repeatable_move'
|
||||||
|
|
||||||
|
-- Repeat movement with ; and ,
|
||||||
|
-- ensure ; goes forward and , goes backward regardless of the last direction
|
||||||
|
vim.keymap.set({ 'n', 'x', 'o' }, ';', ts_repeat_move.repeat_last_move_next)
|
||||||
|
vim.keymap.set({ 'n', 'x', 'o' }, ',', ts_repeat_move.repeat_last_move_previous)
|
||||||
|
|
||||||
|
-- vim way: ; goes to the direction you were moving.
|
||||||
|
-- vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move)
|
||||||
|
-- vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_opposite)
|
||||||
|
|
||||||
|
-- Optionally, make builtin f, F, t, T also repeatable with ; and ,
|
||||||
|
vim.keymap.set({ 'n', 'x', 'o' }, 'f', ts_repeat_move.builtin_f_expr, { expr = true })
|
||||||
|
vim.keymap.set({ 'n', 'x', 'o' }, 'F', ts_repeat_move.builtin_F_expr, { expr = true })
|
||||||
|
vim.keymap.set({ 'n', 'x', 'o' }, 't', ts_repeat_move.builtin_t_expr, { expr = true })
|
||||||
|
vim.keymap.set({ 'n', 'x', 'o' }, 'T', ts_repeat_move.builtin_T_expr, { expr = true })
|
||||||
|
|
||||||
|
-- example: make gitsigns.nvim movement repeatable with ; and , keys.
|
||||||
|
local gs = require 'gitsigns'
|
||||||
|
|
||||||
|
-- make sure forward function comes first
|
||||||
|
local next_hunk_repeat, prev_hunk_repeat = ts_repeat_move.make_repeatable_move_pair(gs.next_hunk, gs.prev_hunk)
|
||||||
|
-- Or, use `make_repeatable_move` or `set_last_move` functions for more control. See the code for instructions.
|
||||||
|
|
||||||
|
vim.keymap.set({ 'n', 'x', 'o' }, ']h', next_hunk_repeat)
|
||||||
|
vim.keymap.set({ 'n', 'x', 'o' }, '[h', prev_hunk_repeat)
|
||||||
|
end,
|
||||||
|
}
|
Loading…
Reference in New Issue