From c196180d0a22b4516d33ea364d5193aafa602832 Mon Sep 17 00:00:00 2001 From: FollieHiyuki Date: Wed, 13 Oct 2021 23:15:38 +0700 Subject: [PATCH] neovim: clean up mappings: add doc for nvim-treesitter mappings chore: unify the way mappings to a command is called nvim-treesitter: load vim.opt for folding after setup() nvim-lspconfig: emmet_ls is now officially supported upstream --- home/.config/nvim/lua/mappings.lua | 47 ++++++++++++++++++-- home/.config/nvim/lua/modules/editor.lua | 17 ++++++-- home/.config/nvim/lua/modules/lsp.lua | 55 +++++++++++------------- home/.config/nvim/lua/modules/tools.lua | 5 +-- home/.config/nvim/lua/modules/ui.lua | 24 +++++------ home/.config/nvim/lua/plugins.lua | 3 +- 6 files changed, 97 insertions(+), 54 deletions(-) diff --git a/home/.config/nvim/lua/mappings.lua b/home/.config/nvim/lua/mappings.lua index 16bd075..4a179e2 100644 --- a/home/.config/nvim/lua/mappings.lua +++ b/home/.config/nvim/lua/mappings.lua @@ -8,7 +8,7 @@ local function pandoc_convert(ofiletype) local ifilename = vim.fn.expand('%:p') local ofilename = vim.fn.expand('%:p:r') .. '.' .. ofiletype - local cmd + local cmd = nil if ofiletype == 'pdf' then cmd = string.format('pandoc %s -o %s --pdf-engine=xelatex -V "mainfont:Iosevka Etoile" -V "sansfont:Iosevka Aile" -V "monofont:Iosevka" -V "geometry:margin=1in"', ifilename, ofilename) @@ -84,18 +84,34 @@ wk.register({ ['['] = { name = 'Block motions (previous)', d = 'Previous diagnostics', - g = 'Previous git hunk' + g = 'Previous git hunk', + m = 'Previous start of outer class', + M = 'Previous end of outer class', + ['['] = 'Previous start of outer function', + [']'] = 'Previous end of outer function' }, [']'] = { name = 'Block motions (next)', d = 'Next diagnostics', - g = 'Next git hunk' + g = 'Next git hunk', + m = 'Next start of outer class', + M = 'Next end of outer class', + ['['] = 'Next start of outer function', + [']'] = 'Next end of outer function' }, g = { name = 'Goto motions', + c = { + name = 'Comment', + c = 'Current line' + }, d = 'Go to definition', D = 'Go to declaration', i = 'Go to implementation', + n = { + name = 'Incremental selection', + i = 'Initialize selection' + }, r = 'Go to references', R = {':TroubleToggle lsp_references', 'Reference list'} }, @@ -122,6 +138,31 @@ wk.register({ [''] = {':HopPattern', 'Hop to pattern'} }) +----------------- +-- Visual mode -- +----------------- +wk.register({ + a = { + c = 'Outer class', + f = 'Outer function' + }, + + i = { + c = 'Inner class', + f = 'Inner function' + }, + + g = { + c = 'Comment', + n = { + name = 'Incremental selection', + n = 'Increment node', + s = 'Increment scope', + m = 'Decrement node' + } + } +}, {mode = 'v'}) + ----------------------------------- -- Normal mode (with leader key) -- ----------------------------------- diff --git a/home/.config/nvim/lua/modules/editor.lua b/home/.config/nvim/lua/modules/editor.lua index 4721c0c..95ec7fc 100644 --- a/home/.config/nvim/lua/modules/editor.lua +++ b/home/.config/nvim/lua/modules/editor.lua @@ -52,9 +52,6 @@ end -- end function M.treesitter_conf() - vim.api.nvim_command('set foldmethod=expr') - vim.api.nvim_command('set foldexpr=nvim_treesitter#foldexpr()') - -- Additional parser for rest.nvim (*.http files) local parser_configs = require('nvim-treesitter.parsers').get_parser_configs() parser_configs.http = { @@ -68,6 +65,16 @@ function M.treesitter_conf() require('nvim-treesitter.configs').setup { ensure_installed = 'maintained', highlight = {enable = true}, + incremental_selection = { + enable = true, + keymaps = { + init_selection = 'gni', + node_incremental = 'gnn', + scope_incremental = 'gns', + node_decremental = 'gnm' + } + }, + -- indent = {enable = true}, textobjects = { select = { enable = true, @@ -102,6 +109,10 @@ function M.treesitter_conf() }, matchup = {enable = true} } + + -- tree-sitter based folding + vim.opt.foldmethod = 'expr' + vim.opt.foldexpr = 'nvim_treesitter#foldexpr()' end -- function M.spellsitter_conf() diff --git a/home/.config/nvim/lua/modules/lsp.lua b/home/.config/nvim/lua/modules/lsp.lua index 491e868..530fe20 100644 --- a/home/.config/nvim/lua/modules/lsp.lua +++ b/home/.config/nvim/lua/modules/lsp.lua @@ -11,26 +11,26 @@ function M.lsp_conf() end local opts = {noremap = true, silent = true} - buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) - buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - buf_set_keymap('n', 'lx', 'lua vim.lsp.buf.signature_help()', opts) - buf_set_keymap('n', 'la', 'lua vim.lsp.buf.add_workspace_folder()', opts) - buf_set_keymap('n', 'lr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) - buf_set_keymap('n', 'lw', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) - buf_set_keymap('n', 'ld', 'lua vim.lsp.buf.type_definition()', opts) - buf_set_keymap('n', 'ln', 'lua vim.lsp.buf.rename()', opts) - buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) - buf_set_keymap('n', 'le', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) - buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) - buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) - buf_set_keymap('n', 'll', 'lua vim.lsp.diagnostic.set_loclist()', opts) + buf_set_keymap('n', 'gD', ':lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('n', 'gd', ':lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'K', ':lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gi', ':lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', 'lx', ':lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('n', 'la', ':lua vim.lsp.buf.add_workspace_folder()', opts) + buf_set_keymap('n', 'lr', ':lua vim.lsp.buf.remove_workspace_folder()', opts) + buf_set_keymap('n', 'lw', ':lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + buf_set_keymap('n', 'ld', ':lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'ln', ':lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', 'gr', ':lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', 'le', ':lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + buf_set_keymap('n', '[d', ':lua vim.lsp.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']d', ':lua vim.lsp.diagnostic.goto_next()', opts) + buf_set_keymap('n', 'll', ':lua vim.lsp.diagnostic.set_loclist()', opts) if client.resolved_capabilities.document_formatting then - buf_set_keymap('n', 'lo', 'lua vim.lsp.buf.formatting()', opts) + buf_set_keymap('n', 'lo', ':lua vim.lsp.buf.formatting()', opts) elseif client.resolved_capabilities.document_range_formatting then - buf_set_keymap('n', 'lo', 'lua vim.lsp.buf.range_formatting({},{0,0},{vim.fn.line("$"),0})', opts) + buf_set_keymap('n', 'lo', ':lua vim.lsp.buf.range_formatting({},{0,0},{vim.fn.line("$"),0})', opts) end -- Attach lsp_signature.nvim @@ -190,19 +190,14 @@ function M.lsp_conf() -- } -- Emmet - if not lspconf.emmet_ls then - require('lspconfig/configs').emmet_ls = { - default_config = { - cmd = {servers_path .. '/emmet_ls/node_modules/.bin/emmet-ls', '--stdio'}, - filetypes = {'html', 'css'}, - root_dir = function(fname) - return vim.loop.cwd() - end, - settings = {} - } - } - end - lspconf.emmet_ls.setup {capabilities = capabilities} + lspconf.emmet_ls.setup { + cmd = {servers_path .. '/emmet_ls/node_modules/.bin/emmet-ls', '--stdio'}, + filetypes = { + 'html', 'xml', 'css', 'scss', 'sass', + 'javascript', 'javascriptreact' + }, + capabilities = capabilities + } -- HTML lspconf.html.setup { diff --git a/home/.config/nvim/lua/modules/tools.lua b/home/.config/nvim/lua/modules/tools.lua index ab71fea..ed5aecb 100644 --- a/home/.config/nvim/lua/modules/tools.lua +++ b/home/.config/nvim/lua/modules/tools.lua @@ -146,9 +146,6 @@ function M.orgmode_conf() } end -function M.vimtex_conf() -end - function M.spectre_conf() require('spectre').setup() @@ -201,7 +198,7 @@ function M.toggleterm_conf() end -- function M.wilder_conf() --- vim.api.nvim_command [[ call wilder#setup({'modes': [':', '/', '?']}) ]] +-- vim.api.nvim_command [[call wilder#setup({'modes': [':', '/', '?']})]] -- Doesn't work yet. Bugs in Neovim (see neovim/neovim#14809 and gelguy/wilder.nvim#53) -- so can't do multi-line config inside vim.cmd [[ ]] with \ diff --git a/home/.config/nvim/lua/modules/ui.lua b/home/.config/nvim/lua/modules/ui.lua index f171ab9..c2b9aff 100644 --- a/home/.config/nvim/lua/modules/ui.lua +++ b/home/.config/nvim/lua/modules/ui.lua @@ -456,19 +456,19 @@ function M.gitsigns_conf() -- Default keymap options noremap = true, - ['n ]g'] = {expr = true, '&diff ? \']g\' : \'lua require"gitsigns.actions".next_hunk()\''}, - ['n [g'] = {expr = true, '&diff ? \'[g\' : \'lua require"gitsigns.actions".prev_hunk()\''}, + ['n ]g'] = {expr = true, '&diff ? \']g\' : \':lua require"gitsigns.actions".next_hunk()\''}, + ['n [g'] = {expr = true, '&diff ? \'[g\' : \':lua require"gitsigns.actions".prev_hunk()\''}, - ['n gs'] = 'lua require"gitsigns".stage_hunk()', - ['v gs'] = 'lua require"gitsigns".stage_hunk({vim.fn.line("."), vim.fn.line("v")})', - ['n gu'] = 'lua require"gitsigns".undo_stage_hunk()', - ['n gr'] = 'lua require"gitsigns".reset_hunk()', - ['v gr'] = 'lua require"gitsigns".reset_hunk({vim.fn.line("."), vim.fn.line("v")})', - ['n gR'] = 'lua require"gitsigns".reset_buffer()', - ['n gp'] = 'lua require"gitsigns".preview_hunk()', - ['n gb'] = 'lua require"gitsigns".blame_line(true)', - ['n gS'] = 'lua require"gitsigns".stage_buffer()', - ['n gU'] = 'lua require"gitsigns".reset_buffer_index()', + ['n gs'] = ':lua require"gitsigns".stage_hunk()', + ['v gs'] = ':lua require"gitsigns".stage_hunk({vim.fn.line("."), vim.fn.line("v")})', + ['n gu'] = ':lua require"gitsigns".undo_stage_hunk()', + ['n gr'] = ':lua require"gitsigns".reset_hunk()', + ['v gr'] = ':lua require"gitsigns".reset_hunk({vim.fn.line("."), vim.fn.line("v")})', + ['n gR'] = ':lua require"gitsigns".reset_buffer()', + ['n gp'] = ':lua require"gitsigns".preview_hunk()', + ['n gb'] = ':lua require"gitsigns".blame_line(true)', + ['n gS'] = ':lua require"gitsigns".stage_buffer()', + ['n gU'] = ':lua require"gitsigns".reset_buffer_index()', -- Text objects ['o ih'] = ':lua require"gitsigns.actions".select_hunk()', diff --git a/home/.config/nvim/lua/plugins.lua b/home/.config/nvim/lua/plugins.lua index 7a14a9c..4b7fff0 100644 --- a/home/.config/nvim/lua/plugins.lua +++ b/home/.config/nvim/lua/plugins.lua @@ -351,7 +351,7 @@ return packer.startup(function(use) run = 'npm install --prefix server', cmd = 'Bracey' } - use { -- shouldn't be lazy-loaded (global bindings don't work) + use { -- TODO: check out neorg 'kristijanhusak/orgmode.nvim', ft = 'org', config = tools.orgmode_conf @@ -400,7 +400,6 @@ return packer.startup(function(use) 'NTBBloodbath/rest.nvim', keys = {'RestNvim', 'RestNvimPreview', 'RestNvimLast'}, wants = {'plenary.nvim', 'nvim-treesitter'}, - -- run = ':TSInstall http', config = tools.rest_conf } use {