Update keymap settings for neovim 0.7.0

pull/2/head
Ensar Sarajčić 2022-04-27 16:07:16 +02:00
parent 78c30af4f2
commit 774d6d028e
4 changed files with 103 additions and 46 deletions

View File

@ -30,13 +30,13 @@ require("lsp")
vim.cmd("syntax on") vim.cmd("syntax on")
require("init.colors") require("init.colors")
vim.api.nvim_set_keymap("n", "Q", "gq", {}) vim.keymap.set("n", "Q", "gq", {noremap = false})
vim.api.nvim_set_keymap("i", "<C-U>", "<C-G>u<C-U>", {noremap = true}) vim.keymap.set("i", "<C-U>", "<C-G>u<C-U>")
vim.cmd("command! Wq :wq") vim.cmd("command! Wq :wq")
vim.cmd("command! W :w") vim.cmd("command! W :w")
vim.api.nvim_set_keymap("n", "<Leader>c", ":ccl <bar> lcl<CR>", {noremap = true}) vim.keymap.set("n", "<Leader>c", ":ccl <bar> lcl<CR>")
-- Allow recursive searches -- Allow recursive searches
vim.cmd("set path+=**") vim.cmd("set path+=**")

View File

@ -9,21 +9,15 @@ function M.setup()
require "jdtls".setup_dap() require "jdtls".setup_dap()
require "jdtls.setup".add_commands() require "jdtls.setup".add_commands()
local on_attach = function(client, bufnr) local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc"
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
local function buf_set_option(...)
vim.api.nvim_buf_set_option(bufnr, ...)
end
buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
local default_opts = {noremap = true, silent = true}
common_config.on_attach(client, bufnr) common_config.on_attach(client, bufnr)
buf_set_keymap("n", "<A-CR>", "<cmd>lua require('jdtls').code_action()<CR>", default_opts) local code_action_fun = function()
buf_set_keymap("n", "<Leader>ac", "<cmd>lua require('jdtls').code_action()<CR>", default_opts) require "jdtls".code_action()
end
vim.keymap.set("n", "<A-CR>", code_action_fun)
vim.keymap.set("n", "<Leader>ac", code_action_fun)
end end
local root_markers = {"gradlew", "pom.xml"} local root_markers = {"gradlew", "pom.xml"}

View File

@ -5,28 +5,90 @@
local M = {} local M = {}
M.on_attach = function(client, bufnr) M.on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc"
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
local function buf_set_option(...)
vim.api.nvim_buf_set_option(bufnr, ...)
end
buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
local default_opts = {noremap = true, silent = true}
-- Lsp keymaps -- Lsp keymaps
buf_set_keymap("n", "<C-]>", "<cmd>lua vim.lsp.buf.definition()<CR>", default_opts) local opts = {buffer = bufnr}
buf_set_keymap("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", default_opts) vim.keymap.set(
buf_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", default_opts) "n",
buf_set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", default_opts) "<C-]>",
buf_set_keymap("n", "<Leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", default_opts) function()
buf_set_keymap("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", default_opts) vim.lsp.buf.definition()
buf_set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", default_opts) end,
buf_set_keymap("n", "<A-CR>", "<cmd>lua vim.lsp.buf.code_action()<CR>", default_opts) opts
buf_set_keymap("n", "<Leader>ac", "<cmd>lua vim.lsp.buf.code_action()<CR>", default_opts) )
buf_set_keymap("n", "<Leader>a", "<cmd>lua vim.lsp.buf.code_action_range()<CR>", default_opts) vim.keymap.set(
"n",
"gD",
function()
vim.lsp.buf.declaration()
end,
opts
)
vim.keymap.set(
"n",
"gr",
function()
vim.lsp.buf.references()
end,
opts
)
vim.keymap.set(
"n",
"gi",
function()
vim.lsp.buf.implementation()
end,
opts
)
vim.keymap.set(
"n",
"<Leader>rn",
function()
vim.lsp.buf.rename()
end,
opts
)
vim.keymap.set(
"n",
"<C-k>",
function()
vim.lsp.buf.signature_help()
end,
opts
)
vim.keymap.set(
"n",
"K",
function()
vim.lsp.buf.hover()
end,
opts
)
vim.keymap.set(
"n",
"<A-CR>",
function()
vim.lsp.buf.code_action()
end,
opts
)
vim.keymap.set(
"n",
"<Leader>ac",
function()
vim.lsp.buf.code_action()
end,
opts
)
vim.keymap.set(
"n",
"<Leader>a",
function()
vim.lsp.buf.code_action_range()
end,
opts
)
end end
return M return M

View File

@ -4,7 +4,15 @@
local dap = require("dap") local dap = require("dap")
vim.cmd [[ au FileType dap-repl lua require('dap.ext.autocompl').attach() ]] vim.api.nvim_create_autocmd(
"FileType",
{
pattern = "dap-repl",
callback = function(args)
require("dap.ext.autocompl").attach()
end
}
)
-- Nvim DAP Treesitter integration -- Nvim DAP Treesitter integration
require("nvim-dap-virtual-text").setup() require("nvim-dap-virtual-text").setup()
@ -52,19 +60,12 @@ dap.listeners.after["event_initialized"]["me"] = function()
for _, keymap in pairs(keymaps) do for _, keymap in pairs(keymaps) do
if keymap.lhs == "K" then if keymap.lhs == "K" then
table.insert(keymap_restore, keymap) table.insert(keymap_restore, keymap)
api.nvim_buf_del_keymap(buf, "n", "K") vim.keymap.del("n", "K", {buffer = buf})
end end
end end
end end
vim.keymap.set( vim.keymap.set(
"n", {"n", "v"},
"K",
function()
dapui.eval()
end
)
vim.keymap.set(
"v",
"K", "K",
function() function()
dapui.eval() dapui.eval()
@ -74,7 +75,7 @@ end
dap.listeners.after["event_terminated"]["me"] = function() dap.listeners.after["event_terminated"]["me"] = function()
for _, keymap in pairs(keymap_restore) do for _, keymap in pairs(keymap_restore) do
api.nvim_buf_set_keymap(keymap.buffer, keymap.mode, keymap.lhs, keymap.rhs, {silent = keymap.silent == 1}) vim.keymap.set(keymap.mode, keymap.lhs, keymap.rhs, {silent = keymap.silent == 1, buffer = keymap.buffer})
end end
keymap_restore = {} keymap_restore = {}
end end