local cmd = vim.cmd local map = vim.keymap.set local dap = require 'dap' local treeapi = require 'nvim-tree.api' 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') local function fzy_ignore(patterns) local pattern_cmd = {} for _, p in ipairs(patterns) do table.insert(pattern_cmd, string.format("-E '%s'", p)) end return table.concat(pattern_cmd, ' ') end -- fzy mappings if vim.fn.executable('fzy') then _G.fzy_edit = require('fzy.edit').fzy_edit map( '', 'e', string.format( ':call v:lua.fzy_edit("fd -t f -t l")', fzy_ignore{ '*.git/*', '*node_modules*', '*.pyc', '*migrations*', '*result*', '*.direnv/*', } ), { noremap=true, silent=true } ) _G.fzy_buffers = require('fzy.buffers').fzy_buffers map('', 'b', ':call v:lua.fzy_buffers()', { noremap=true, silent=true } ) _G.fzy_jmp = require('fzy.jump').fzy_jmp map('', 'f', ':call v:lua.fzy_jmp()', { noremap=true, silent=true} ) else print('fzy not in PATH!') end -- 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) buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', options) 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 -- dap -- Start debugging session map("n", "ds", function() dap.continue() require 'dapui'.open() vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("=", false, true, true), "n", false) -- Spaces buffers evenly end) -- Set breakpoints, get variable values, step into/out of functions, etc. map("n", "dl", require("dap.ui.widgets").hover) map("n", "dc", dap.continue) map("n", "db", dap.toggle_breakpoint) map("n", "dn", dap.step_over) map("n", "di", dap.step_into) map("n", "do", dap.step_out) map("n", "dC", dap.clear_breakpoints) -- Close debugger and clear breakpoints map("n", "de", function() dap.clear_breakpoints() require 'dapui'.close() dap.terminate() vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("=", false, true, true), "n", false) end) local function toggle_tree() treeapi.tree.toggle({ find_file = true }) end -- nvim-tree map('n', 'tt', toggle_tree) map('n', 'tf', treeapi.tree.focus) return M