replace utils.map with vim.keymap.set

This commit is contained in:
Vladan Popovic 2024-06-10 13:12:26 +02:00
parent fa255704a1
commit 0e55059a63
4 changed files with 27 additions and 30 deletions

View file

@ -1,15 +1,15 @@
local utils = require('utils') local utils = require('utils')
-- Clear trailing whitespace -- Clear trailing whitespace
utils.map("n", "<C-w>", "<cmd>let _s=@/<Bar>:%s/\\s\\+$//e<Bar>:let @/=_s<Bar><CR>") vim.keymap.set("n", "<C-w>", "<cmd>let _s=@/<Bar>:%s/\\s\\+$//e<Bar>:let @/=_s<Bar><CR>")
-- Use tab and shift+tab to cycle buffers -- Use tab and shift+tab to cycle buffers
utils.map("n", "<tab>", "<cmd>bn<cr>") vim.keymap.set("n", "<tab>", "<cmd>bn<cr>")
utils.map("n", "<S-tab>", "<cmd>bp<cr>") vim.keymap.set("n", "<S-tab>", "<cmd>bp<cr>")
-- Turn spellchecker on and off -- Turn spellchecker on and off
utils.map("n", "<leader>se", "<cmd>setlocal spell spelllang=en_us<cr>") vim.keymap.set("n", "<leader>se", "<cmd>setlocal spell spelllang=en_us<cr>")
utils.map("n", "<leader>sq", "<cmd>setlocal nospell<cr>") vim.keymap.set("n", "<leader>sq", "<cmd>setlocal nospell<cr>")
utils.map("n", "<F3>", "<cmd>set nonumber!<CR>") vim.keymap.set("n", "<F3>", "<cmd>set nonumber!<CR>")
utils.map("n", "<leader>fe", "<cmd>Oil<CR>") vim.keymap.set("n", "<leader>fe", "<cmd>Oil<CR>")

View file

@ -3,15 +3,15 @@ local on_attach = function(client, bufnr)
local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
-- Mappings. -- Mappings.
utils.map("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>") vim.keymaps.set("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>")
utils.map("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>") vim.keymaps.set("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>")
utils.map("n", "<M-k>", "<cmd>lua vim.lsp.buf.type_definition()<CR>") vim.keymaps.set("n", "<M-k>", "<cmd>lua vim.lsp.buf.type_definition()<CR>")
utils.map("n", "<M-r>", "<cmd>lua vim.lsp.buf.rename()()<CR>") vim.keymaps.set("n", "<M-r>", "<cmd>lua vim.lsp.buf.rename()()<CR>")
utils.map("n", "[d", "<cmd>lua vim.diagnostic.goto_prev()<CR>") vim.keymaps.set("n", "[d", "<cmd>lua vim.diagnostic.goto_prev()<CR>")
utils.map("n", "]d", "<cmd>lua vim.diagnostic.goto_next()<CR>") vim.keymaps.set("n", "]d", "<cmd>lua vim.diagnostic.goto_next()<CR>")
utils.map("n", "<leader>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>") vim.keymaps.set("n", "<leader>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>")
utils.map("n", "<leader>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>") vim.keymaps.set("n", "<leader>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>")
utils.map("n", "<leader>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>") vim.keymaps.set("n", "<leader>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>")
if client.supports_method("textDocument/formatting") then if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })

View file

@ -20,15 +20,18 @@ telescope.setup {
}, },
} }
vim.keymap.set('n', '<leader>ss', telescope.extensions.luasnip.luasnip, {})
vim.keymap.set('n', '<leader>ff', builtin.find_files, {}) vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.git_files, {}) vim.keymap.set('n', '<leader>ffg', builtin.git_files, {})
vim.keymap.set('n', '<leader>fs', telescope.extensions.luasnip.luasnip, {}) vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>gg', builtin.live_grep, {}) vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>bb', builtin.buffers, {}) vim.keymap.set('n', '<leader>fs', builtin.lsp_dynamic_workspace_symbols, {})
vim.keymap.set('n', '<leader>hh', builtin.help_tags, {}) vim.keymap.set('n', '<leader>fsd', builtin.lsp_document_symbols, {})
vim.keymap.set('n', '<leader>ss', builtin.lsp_dynamic_workspace_symbols, {}) vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
vim.keymap.set('n', '<leader>sd', builtin.lsp_document_symbols, {}) vim.keymap.set('n', '<leader>fd', builtin.diagnostics, {})
vim.keymap.set('n', '<leader>dd', builtin.diagnostics, {})
-- Use telescope for lsp definitions, calls and references
vim.keymap.set('n', '<leader>gd', builtin.lsp_definitions, {}) vim.keymap.set('n', '<leader>gd', builtin.lsp_definitions, {})
vim.keymap.set('n', '<leader>gr', builtin.lsp_references, {}) vim.keymap.set('n', '<leader>gr', builtin.lsp_references, {})
vim.keymap.set('n', '<leader>gi', builtin.lsp_implementations, {}) vim.keymap.set('n', '<leader>gi', builtin.lsp_implementations, {})

View file

@ -7,10 +7,4 @@ function utils.opt(scope, key, value)
if scope ~= 'o' then scopes['o'][key] = value end if scope ~= 'o' then scopes['o'][key] = value end
end end
function utils.map(mode, lhs, rhs, opts)
local options = { noremap = true, silent = true }
if opts then options = vim.tbl_extend('force', options, opts) end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
return utils return utils