From fa4c72d08e5b664e55d2aaa7bd47d01fa9c8eed8 Mon Sep 17 00:00:00 2001 From: Oliver Hartmann Date: Thu, 16 Sep 2021 10:02:10 +0200 Subject: [PATCH] Some refactoring --- init.lua | 45 +------------------------------------------- lua/keymappings.lua | 18 ++++++++++++++++++ lua/my_telescope.lua | 28 +++++++++++++++++++++++++++ lua/mylsp.lua | 39 ++++++++++++++++++++------------------ 4 files changed, 68 insertions(+), 62 deletions(-) create mode 100644 lua/my_telescope.lua diff --git a/init.lua b/init.lua index d42d29f..ffba7d3 100644 --- a/init.lua +++ b/init.lua @@ -56,10 +56,6 @@ utils.opt('o', 'showmatch', true) -------------------- AUTOCOMMANDS -------------------------- require("autocommands") --------------------- MAPPINGS ------------------------------ --- to navigate the completion menu -utils.map('i', '', 'pumvisible() ? "\\" : "\\"', {expr = true}) -utils.map('i', '', 'pumvisible() ? "\\" : "\\"', {expr = true}) -------------------- TREE-SITTER --------------------------- local ts = require 'nvim-treesitter.configs' ts.setup {ensure_installed = 'maintained', highlight = {enable = true}} @@ -67,46 +63,7 @@ ts.setup {ensure_installed = 'maintained', highlight = {enable = true}} -------------------- FZF ----------------------------------- --utils.map('n', '', ':FZF') -------------------- TELESCOPE ----------------------------- -utils.map('n', 'f', 'Telescope find_files') -utils.map('n', '', 'Telescope find_files') -utils.map('n', 'g', 'Telescope git_files') -utils.map('n', 'o', 'Telescope oldfiles') -utils.map('n', 'h', 'Telescope command_history') -utils.map('v', 'h', 'Telescope command_history') -utils.map('n', '', 'Telescope commands') -utils.map('n', 'b', 'Telescope buffers') -utils.map('n', 'r', 'Telescope lsp_references') -utils.map('n', '', 'Telescope lsp_document_symbols') -utils.map('n', '', 'Telescope lsp_document_symbols') -utils.map('n', 'v', 'Telescope lsp_document_diagnostics') -local actions = require('telescope.actions') -require('telescope').setup{ - defaults = { - mappings = { - i = { - [""] = actions.select_tab, - [""] = actions.select_default, - } - }, - }, - pickers = { - -- Your special builtin config goes in here - buffers = { - sort_lastused = true, - previewer = false, - theme = "dropdown", - mappings = { - i = { - [""] = actions.delete_buffer, - [""] = actions.select_default, - }, - n = { - [""] = actions.delete_buffer, - } - } - } - } -} +require('my_telescope') -------------------- LSP ----------------------------------- require('mylsp') diff --git a/lua/keymappings.lua b/lua/keymappings.lua index 12f532b..65718f9 100644 --- a/lua/keymappings.lua +++ b/lua/keymappings.lua @@ -60,3 +60,21 @@ utils.map('v', 'ΓΌ', "y:let @/='=escape(@\",'/\\')':set hls", { -- Close Buffer utils.map('n', '', ':bd') + +-- to navigate the completion menu +utils.map('i', '', 'pumvisible() ? "\\" : "\\"', {expr = true}) +utils.map('i', '', 'pumvisible() ? "\\" : "\\"', {expr = true}) + +-- Telescope +utils.map('n', 'f', 'Telescope find_files') +utils.map('n', '', 'Telescope find_files') +utils.map('n', 'g', 'Telescope git_files') +utils.map('n', 'o', 'Telescope oldfiles') +utils.map('n', 'h', 'Telescope command_history') +utils.map('v', 'h', 'Telescope command_history') +utils.map('n', '', 'Telescope commands') +utils.map('n', 'b', 'Telescope buffers') +utils.map('n', 'r', 'Telescope lsp_references') +utils.map('n', '', 'Telescope lsp_document_symbols') +utils.map('n', '', 'Telescope lsp_document_symbols') +utils.map('n', 'v', 'Telescope lsp_document_diagnostics') diff --git a/lua/my_telescope.lua b/lua/my_telescope.lua new file mode 100644 index 0000000..812f9f6 --- /dev/null +++ b/lua/my_telescope.lua @@ -0,0 +1,28 @@ +local actions = require('telescope.actions') +require('telescope').setup{ + defaults = { + mappings = { + i = { + [""] = actions.select_tab, + [""] = actions.select_default, + } + }, + }, + pickers = { + -- Your special builtin config goes in here + buffers = { + sort_lastused = true, + previewer = false, + theme = "dropdown", + mappings = { + i = { + [""] = actions.delete_buffer, + [""] = actions.select_default, + }, + n = { + [""] = actions.delete_buffer, + } + } + } + } +} diff --git a/lua/mylsp.lua b/lua/mylsp.lua index 2c812fc..d9a47c2 100644 --- a/lua/mylsp.lua +++ b/lua/mylsp.lua @@ -35,29 +35,32 @@ local on_attach = function(client, bufnr) -- Mappings. local opts = { noremap=true, silent=true } - utils.map('n', ',', 'lua vim.lsp.diagnostic.goto_prev()') - utils.map('n', ';', 'lua vim.lsp.diagnostic.goto_next()') - utils.map('n', 'a', 'Telescope lsp_code_actions') - utils.map('n', 'd', 'lua vim.lsp.buf.definition()') - utils.map('n', 'e', 'lua vim.lsp.buf.declaration()') - utils.map('n', 'h', 'lua vim.lsp.buf.hover()') - utils.map('n', 'c', 'lua vim.lsp.buf.outgoing_calls()') - utils.map('n', 'C', 'lua vim.lsp.buf.incoming_calls()') - utils.map('n', 'm', 'lua vim.lsp.buf.rename()') - -- utils.map('n', 'r', 'lua vim.lsp.buf.references()') - utils.map('n', 's', 'lua vim.lsp.buf.document_symbol()') - utils.map('n', '', 'Telescope lsp_dynamic_workspace_symbols') - utils.map('n', 'D', 'lua vim.lsp.buf.type_definition()') - utils.map('n', '', 'lua vim.lsp.buf.signature_help()') - - utils.map('n', '', ':ClangdSwitchSourceHeader') + utils.map('n', ',', 'lua vim.lsp.diagnostic.goto_prev()', opts) + utils.map('n', ';', 'lua vim.lsp.diagnostic.goto_next()', opts) + utils.map('n', 'a', 'Telescope lsp_code_actions', opts) + utils.map('n', 'd', 'lua vim.lsp.buf.definition()', opts) + utils.map('n', 'e', 'lua vim.lsp.buf.declaration()', opts) + utils.map('n', 'h', 'lua vim.lsp.buf.hover()', opts) + utils.map('n', 'c', 'lua vim.lsp.buf.outgoing_calls()<, optsCR>') + utils.map('n', 'C', 'lua vim.lsp.buf.incoming_calls()', opts) + utils.map('n', 'm', 'lua vim.lsp.buf.rename()', opts) + -- utils.map('n', 'r', 'lua vim.lsp.buf.references()') + utils.map('n', 's', 'lua vim.lsp.buf.document_symbol()', opts) + utils.map('n', '', 'Telescope lsp_dynamic_workspace_symbols', opts) + utils.map('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + utils.map('n', '', 'lua vim.lsp.buf.signature_help()', opts) + utils.map('n', 'r', 'Telescope lsp_references') + utils.map('n', '', 'Telescope lsp_document_symbols') + utils.map('n', '', 'Telescope lsp_document_symbols') + utils.map('n', 'v', 'Telescope lsp_document_diagnostics') + utils.map('n', '', ':ClangdSwitchSourceHeader', opts) -- Set some keybinds conditional on server capabilities if client.resolved_capabilities.document_formatting then - utils.map('n', 'f', 'lua vim.lsp.buf.formatting()') + utils.map('n', 'f', 'lua vim.lsp.buf.formatting()', opts) end if client.resolved_capabilities.document_range_formatting then - utils.map('v', 'f', 'lua vim.lsp.buf.range_formatting()') + utils.map('v', 'f', 'lua vim.lsp.buf.range_formatting()', opts) end -- Set autocommands conditional on server_capabilities