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
This commit is contained in:
FollieHiyuki 2021-10-13 23:15:38 +07:00
parent d09754811c
commit c196180d0a
No known key found for this signature in database
GPG Key ID: 813CF484F4993419
6 changed files with 97 additions and 54 deletions

View File

@ -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<CR>', 'Reference list'}
},
@ -122,6 +138,31 @@ wk.register({
['<A-s>'] = {':HopPattern<CR>', '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) --
-----------------------------------

View File

@ -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()

View File

@ -11,26 +11,26 @@ function M.lsp_conf()
end
local opts = {noremap = true, silent = true}
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<Cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<leader>lx', '<Cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<leader>la', '<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<leader>lr', '<Cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<leader>lw', '<Cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<leader>ld', '<Cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<leader>ln', '<Cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', 'gr', '<Cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<leader>le', '<Cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '[d', '<Cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<Cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<leader>ll', '<Cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap('n', 'gD', ':lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', ':lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'K', ':lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', ':lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<leader>lx', ':lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<leader>la', ':lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<leader>lr', ':lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<leader>lw', ':lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<leader>ld', ':lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<leader>ln', ':lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', 'gr', ':lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<leader>le', ':lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '[d', ':lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', ':lua vim.lsp.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<leader>ll', ':lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
if client.resolved_capabilities.document_formatting then
buf_set_keymap('n', '<leader>lo', '<Cmd>lua vim.lsp.buf.formatting()<CR>', opts)
buf_set_keymap('n', '<leader>lo', ':lua vim.lsp.buf.formatting()<CR>', opts)
elseif client.resolved_capabilities.document_range_formatting then
buf_set_keymap('n', '<leader>lo', '<Cmd>lua vim.lsp.buf.range_formatting({},{0,0},{vim.fn.line("$"),0})<CR>', opts)
buf_set_keymap('n', '<leader>lo', ':lua vim.lsp.buf.range_formatting({},{0,0},{vim.fn.line("$"),0})<CR>', 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 {

View File

@ -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 \

View File

@ -456,19 +456,19 @@ function M.gitsigns_conf()
-- Default keymap options
noremap = true,
['n ]g'] = {expr = true, '&diff ? \']g\' : \'<cmd>lua require"gitsigns.actions".next_hunk()<CR>\''},
['n [g'] = {expr = true, '&diff ? \'[g\' : \'<cmd>lua require"gitsigns.actions".prev_hunk()<CR>\''},
['n ]g'] = {expr = true, '&diff ? \']g\' : \':lua require"gitsigns.actions".next_hunk()<CR>\''},
['n [g'] = {expr = true, '&diff ? \'[g\' : \':lua require"gitsigns.actions".prev_hunk()<CR>\''},
['n <leader>gs'] = '<cmd>lua require"gitsigns".stage_hunk()<CR>',
['v <leader>gs'] = '<cmd>lua require"gitsigns".stage_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>',
['n <leader>gu'] = '<cmd>lua require"gitsigns".undo_stage_hunk()<CR>',
['n <leader>gr'] = '<cmd>lua require"gitsigns".reset_hunk()<CR>',
['v <leader>gr'] = '<cmd>lua require"gitsigns".reset_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>',
['n <leader>gR'] = '<cmd>lua require"gitsigns".reset_buffer()<CR>',
['n <leader>gp'] = '<cmd>lua require"gitsigns".preview_hunk()<CR>',
['n <leader>gb'] = '<cmd>lua require"gitsigns".blame_line(true)<CR>',
['n <leader>gS'] = '<cmd>lua require"gitsigns".stage_buffer()<CR>',
['n <leader>gU'] = '<cmd>lua require"gitsigns".reset_buffer_index()<CR>',
['n <leader>gs'] = ':lua require"gitsigns".stage_hunk()<CR>',
['v <leader>gs'] = ':lua require"gitsigns".stage_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>',
['n <leader>gu'] = ':lua require"gitsigns".undo_stage_hunk()<CR>',
['n <leader>gr'] = ':lua require"gitsigns".reset_hunk()<CR>',
['v <leader>gr'] = ':lua require"gitsigns".reset_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>',
['n <leader>gR'] = ':lua require"gitsigns".reset_buffer()<CR>',
['n <leader>gp'] = ':lua require"gitsigns".preview_hunk()<CR>',
['n <leader>gb'] = ':lua require"gitsigns".blame_line(true)<CR>',
['n <leader>gS'] = ':lua require"gitsigns".stage_buffer()<CR>',
['n <leader>gU'] = ':lua require"gitsigns".reset_buffer_index()<CR>',
-- Text objects
['o ih'] = ':<C-U>lua require"gitsigns.actions".select_hunk()<CR>',

View File

@ -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 = {'<Plug>RestNvim', '<Plug>RestNvimPreview', '<Plug>RestNvimLast'},
wants = {'plenary.nvim', 'nvim-treesitter'},
-- run = ':TSInstall http',
config = tools.rest_conf
}
use {