local cmd = vim.cmd local map = vim.keymap.set local u = require 'utils' local M = {} -- map the leader key map('n', '', '', {}) vim.g.mapleader = ' ' local options = { silent = true } map('n', '', ':nohlsearch', options) map('n', 'n', ':bnext', options) map('n', 'p', ':bprev', options) -- search matches in the middle of the window map('n', 'n', 'nzzzv', options) map('n', 'N', 'Nzzzv', options) -- remain in visual after indenting map('v', '<', '', '>gv', options) -- Not an editor command: Wqa cmd(':command! WQ wq') cmd(':command! WQ wq') cmd(':command! Wq wq') cmd(':command! Wqa wqa') cmd(':command! W w') cmd(':command! Q q') -- lspconfig function M.on_attach(client, bufnr) local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', options) vim.keymap.set('n', 'gd', function() local params = vim.lsp.util.make_position_params() vim.lsp.buf_request(0, 'textDocument/definition', params, function(_, result) if not result or vim.tbl_isempty(result) then return vim.lsp.buf.definition() end local def = vim.islist(result) and result[1] or result local uri = def.uri or def.targetUri local range = def.range or def.targetSelectionRange or def.targetRange local cursor = vim.api.nvim_win_get_cursor(0) local line, col = cursor[1] - 1, cursor[2] if uri == vim.uri_from_bufnr(0) and line >= range.start.line and line <= range['end'].line and col >= range.start.character then require('fzf-lua').lsp_references() else vim.lsp.buf.definition() end end) end, { buffer = bufnr, silent = true }) buf_set_keymap('n', 'ga', 'lua vim.lsp.buf.code_action()', options) buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', options) buf_set_keymap('n', 'L', 'lua vim.lsp.buf.signature_help()', options) buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', options) buf_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', options) buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', options) buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', options) map('n', 'ff', function() vim.lsp.buf.format { async = true } end) end -- vim.api.nvim_exec([[ -- " Use and to navigate through popup menu -- inoremap pumvisible() ? "\" : "\" -- inoremap pumvisible() ? "\" : "\" -- -- ]], false) -- abbreviations local star = '★' local stars = {} for n = 1, 5 do table.insert(stars, star) u.iabbrev(n .. '*', table.concat(stars)) end map('n', 'tt', 'Lexplore') return M