[nvim] feat: update mapping API
nvim 0.7 has a dedicated keymap.set function
This commit is contained in:
parent
9ff24a5559
commit
bc67eb8ffe
@ -3,30 +3,30 @@
|
|||||||
-- License : GPLv3
|
-- License : GPLv3
|
||||||
-- Description : neovim mappings file
|
-- Description : neovim mappings file
|
||||||
|
|
||||||
utils.map("n", "<space>", "<leader>")
|
vim.keymap.set({ "n", "v" }, "<space>", "<Nop>", { silent = true })
|
||||||
utils.map("n", "<leader>y", "\"+y")
|
vim.g.mapleader = " "
|
||||||
utils.map("n", "<leader>p", "\"+P")
|
|
||||||
utils.map("n", "<leader><enter>", "<cmd>w! | !compiler %<CR>")
|
|
||||||
utils.map("n", "<leader>u", "<cmd>PackerSync<CR>")
|
|
||||||
utils.map("n", "<leader>c", "<cmd>ColorizerToggle<CR>")
|
|
||||||
|
|
||||||
-- LSP
|
-- Dealing with word wrap
|
||||||
utils.map("n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>")
|
vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'",
|
||||||
utils.map("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>")
|
{ expr = true, silent = true })
|
||||||
utils.map("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>")
|
vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'",
|
||||||
utils.map("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>")
|
{ expr = true, silent = true })
|
||||||
utils.map("n", "<leader>ln", "<cmd>lua vim.diagnostic.goto_next()<CR>")
|
|
||||||
utils.map("n", "<leader>lp", "<cmd>lua vim.diagnostic.goto_prev()<CR>")
|
vim.keymap.set("n", "<leader>y", "\"+y")
|
||||||
utils.map("n", "<leader>lf", "<cmd>lua vim.lsp.buf.formatting()<CR>")
|
vim.keymap.set("n", "<leader>p", "\"+P")
|
||||||
|
vim.keymap.set("n", "<leader><enter>", "<cmd>w! | !compiler %<CR>")
|
||||||
|
vim.keymap.set("n", "<leader>u", function() require("packer").sync() end)
|
||||||
|
|
||||||
-- telescope
|
-- telescope
|
||||||
utils.map("n", "<leader>ff", "<cmd>Telescope find_files<CR>")
|
vim.keymap.set("n", "<leader>ff",
|
||||||
utils.map("n", "<leader>fb", "<cmd>Telescope buffers<CR>")
|
function() require("telescope.builtin").find_files() end)
|
||||||
utils.map("n", "<leader>fl", "<cmd>Telescope live_grep<CR>")
|
vim.keymap.set("n", "<leader>fb",
|
||||||
|
function() require("telescope.builtin").buffers() end)
|
||||||
|
vim.keymap.set("n", "<leader>fl",
|
||||||
|
function() require("telescope.builtin").live_grep() end)
|
||||||
|
|
||||||
-- colorscheme
|
-- colorscheme
|
||||||
utils.map("n", "<C-s>", "<cmd>lua require(\"astronomy\").toggle_variant()<CR>")
|
vim.keymap.set("n", "<C-s>", function() require("astronomy").toggle_variant() end)
|
||||||
|
|
||||||
-- snippets
|
-- snippets
|
||||||
utils.map("i", "<C-E>", "<Plug>luasnip-next-choice", {})
|
vim.keymap.set({ "i", "s" }, "<C-E>", "<Plug>luasnip-next-choice")
|
||||||
utils.map("s", "<C-E>", "<Plug>luasnip-next-choice", {})
|
|
||||||
|
@ -84,25 +84,27 @@ local enhance_server_opts = {
|
|||||||
|
|
||||||
local on_attach = function(_, bufnr)
|
local on_attach = function(_, bufnr)
|
||||||
local opts = { buffer = bufnr }
|
local opts = { buffer = bufnr }
|
||||||
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
|
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
||||||
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
|
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
|
||||||
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
|
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
|
||||||
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
|
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||||||
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
|
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
|
||||||
vim.keymap.set('n', '<leader>wa',
|
vim.keymap.set("n", "<leader>ln", vim.diagnostic.goto_next, opts)
|
||||||
|
vim.keymap.set("n", "<leader>lp", vim.diagnostic.goto_prev, opts)
|
||||||
|
vim.keymap.set("n", "<leader>lf", vim.lsp.buf.formatting, opts)
|
||||||
|
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
|
||||||
|
vim.keymap.set("n", "<leader>wa",
|
||||||
vim.lsp.buf.add_workspace_folder, opts)
|
vim.lsp.buf.add_workspace_folder, opts)
|
||||||
vim.keymap.set('n', '<leader>wr',
|
vim.keymap.set("n", "<leader>wr",
|
||||||
vim.lsp.buf.remove_workspace_folder, opts)
|
vim.lsp.buf.remove_workspace_folder, opts)
|
||||||
vim.keymap.set('n', '<leader>wl', function()
|
vim.keymap.set("n", "<leader>wl", function()
|
||||||
vim.inspect(vim.lsp.buf.list_workspace_folders())
|
vim.inspect(vim.lsp.buf.list_workspace_folders())
|
||||||
end, opts)
|
end, opts)
|
||||||
vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, opts)
|
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, opts)
|
||||||
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
|
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
|
||||||
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
|
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts)
|
||||||
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, opts)
|
vim.keymap.set("n", "<leader>so",
|
||||||
vim.keymap.set('n', '<leader>so',
|
require("telescope.builtin").lsp_document_symbols, opts)
|
||||||
require('telescope.builtin').lsp_document_symbols, opts)
|
|
||||||
vim.api.nvim_create_user_command("Format", vim.lsp.buf.formatting, {})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- nvim-cmp supports additional completion capabilities
|
-- nvim-cmp supports additional completion capabilities
|
||||||
|
@ -22,12 +22,6 @@ function M.add_rtp(path)
|
|||||||
rtp = rtp .. "," .. path
|
rtp = rtp .. "," .. path
|
||||||
end
|
end
|
||||||
|
|
||||||
-- map a key with optional options
|
|
||||||
function M.map(mode, keys, action, options)
|
|
||||||
options = options or {}
|
|
||||||
vim.api.nvim_set_keymap(mode, keys, action, options)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- see if a file exists
|
-- see if a file exists
|
||||||
function M.file_exists(file)
|
function M.file_exists(file)
|
||||||
local f = io.open(file, "rb")
|
local f = io.open(file, "rb")
|
||||||
|
Reference in New Issue
Block a user