[vim] Redo the keys lua module
Return a table from the module so that other modules that require it can access its functions in a namespaced way.
This commit is contained in:
parent
5e5c8f83c8
commit
95081a31a3
3 changed files with 53 additions and 26 deletions
|
@ -56,12 +56,16 @@ vim.cmd [[
|
|||
]]
|
||||
|
||||
require "configuration"
|
||||
require "keys"
|
||||
require "lsp"
|
||||
|
||||
local colors = require "colors"
|
||||
local colors = require 'colors'
|
||||
colors.init()
|
||||
|
||||
local keys = require 'keys'
|
||||
keys.init_key_opts()
|
||||
keys.init_window_key_mappings()
|
||||
keys.init_diagnostic_key_mappings()
|
||||
|
||||
function ErynEnsureMetadataDirectoriesExist()
|
||||
local paths = {
|
||||
vim.opt.backupdir:get(),
|
||||
|
|
|
@ -1,45 +1,57 @@
|
|||
-- Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
local map = vim.keymap.set
|
||||
local function init_key_opts()
|
||||
vim.g.mapleader = ","
|
||||
end
|
||||
|
||||
vim.g.mapleader = ","
|
||||
local function window_key_mappings()
|
||||
local map = vim.keymap.set
|
||||
local options = { silent = true }
|
||||
|
||||
local options = { silent = true }
|
||||
-- Allow starting commands with ; instead of typing Shift-;. Save lots of keypresses!
|
||||
map('n', ';', ':')
|
||||
|
||||
-- Allow starting commands with ; instead of typing Shift-;. Save lots of keypresses!
|
||||
map('n', ';', ':')
|
||||
map('n', '<C-h>', '<C-w>h', options)
|
||||
map('n', '<C-j>', '<C-w>j', options)
|
||||
map('n', '<C-k>', '<C-w>k', options)
|
||||
map('n', '<C-l>', '<C-w>l', options)
|
||||
|
||||
map('n', '<C-h>', '<C-w>h', options)
|
||||
map('n', '<C-j>', '<C-w>j', options)
|
||||
map('n', '<C-k>', '<C-w>k', options)
|
||||
map('n', '<C-l>', '<C-w>l', options)
|
||||
map('n', '<C-n>', ':bn<CR>', options)
|
||||
map('n', '<C-p>', ':bp<CR>', options)
|
||||
|
||||
map('n', '<C-n>', ':bn<CR>', options)
|
||||
map('n', '<C-p>', ':bp<CR>', options)
|
||||
|
||||
map('n', '<leader><space>', function()
|
||||
vim.cmd [[ setlocal invhlsearch ]]
|
||||
end, options)
|
||||
map('n', '<leader><space>', function()
|
||||
vim.cmd [[ setlocal invhlsearch ]]
|
||||
end, options)
|
||||
end
|
||||
|
||||
--
|
||||
-- Language Server mappings
|
||||
--
|
||||
|
||||
-- Basic diagnostic mappings, these will navigate to or display diagnostics
|
||||
local diagnostic_options = { noremap=true, silent=true }
|
||||
map('n', '<leader>d', vim.diagnostic.open_float, diagnostic_options)
|
||||
map('n', '[d', vim.diagnostic.goto_prev, diagnostic_options)
|
||||
map('n', ']d', vim.diagnostic.goto_next, diagnostic_options)
|
||||
map('n', '<leader>q', vim.diagnostic.setloclist, diagnostic_options)
|
||||
local function diagnostic_mappings()
|
||||
local map = vim.keymap.set
|
||||
local options = { noremap=true, silent=true }
|
||||
|
||||
function set_up_local_lsp_mappings(buffer_number)
|
||||
-- Basic diagnostic mappings, these will navigate to or display diagnostics
|
||||
map('n', '<leader>d', vim.diagnostic.open_float, options)
|
||||
map('n', '[d', vim.diagnostic.goto_prev, options)
|
||||
map('n', ']d', vim.diagnostic.goto_next, options)
|
||||
map('n', '<leader>q', vim.diagnostic.setloclist, options)
|
||||
end
|
||||
|
||||
local function set_up_local_lsp_mappings(buffer_number)
|
||||
local map = vim.keymap.set
|
||||
local options = { noremap=true, silent=true, buffer=buffer_number }
|
||||
|
||||
map('n', 'ga', vim.lsp.buf.code_action, options)
|
||||
map('n', 'gD', vim.lsp.buf.declaration, options)
|
||||
map('n', 'gd', vim.lsp.buf.definition, options)
|
||||
map('n', 'gk', vim.lsp.buf.hover, options)
|
||||
map('n', 'gi', vim.lsp.buf.implementation, options)
|
||||
map('n', 'gK', vim.lsp.buf.signature_help, options)
|
||||
map('n', '<C-i>', function()
|
||||
vim.lsp.buf.inlay_hint.enable(buffer_number, not vim.lsp.inlay_hint.is_enabled())
|
||||
end, options)
|
||||
map('n', '<leader>D', vim.lsp.buf.type_definition, options)
|
||||
map('n', '<leader>rn', vim.lsp.buf.rename, options)
|
||||
map('n', '<leader>ca', vim.lsp.buf.code_action, options)
|
||||
|
@ -50,3 +62,10 @@ function set_up_local_lsp_mappings(buffer_number)
|
|||
vim.lsp.buf.format { async = true }
|
||||
end, options)
|
||||
end
|
||||
|
||||
return {
|
||||
init_key_opts = init_key_opts,
|
||||
init_window_key_mappings = window_key_mappings,
|
||||
init_diagnostic_key_mappings = diagnostic_mappings,
|
||||
init_lsp_key_mappings = set_up_local_lsp_mappings,
|
||||
}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
-- Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
|
||||
local clangd_extensions = require 'clangd_extensions'
|
||||
local cmp = require 'cmp'
|
||||
local keys = require 'keys'
|
||||
local lspconfig = require 'lspconfig'
|
||||
|
||||
local keys = require 'keys'
|
||||
|
||||
cmp.setup {
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
|
@ -51,7 +55,7 @@ local cmp_capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|||
|
||||
local on_attach = function(client, buffer_number)
|
||||
vim.api.nvim_buf_set_option(buffer_number, "omnifunc", "v:lua.vim.lsp.omnifunc")
|
||||
keys.set_up_local_lsp_mappings(buffer_number)
|
||||
keys.init_lsp_key_mappings(buffer_number)
|
||||
end
|
||||
|
||||
lspconfig.clangd.setup {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue