local wk = require('which-key') local map = vim.keymap.set vim.cmd([[ augroup keys_user_config autocmd! autocmd BufWritePost keys.lua source augroup end ]]) wk.setup({ key_labels = { [''] = 'SPC', [''] = 'RET', [''] = 'TAB' } }) vim.opt.timeoutlen = 500 vim.g.mapleader = ' ' -- Handy to remap semi-colon to colon map({ 'n', 'v' }, ';', ':') map({ 'n', 'v' }, 'q;', 'q:') -- System clipboard via -> y | p map({ 'n', 'v' }, 'y', '"+y') map( 'n', 'Y', '"+Y') map({ 'n', 'v' }, 'p', '"+p') map({ 'n', 'v' }, 'P', '"+P') -- Common short-hands map('n', 'w', 'w') map('n', 'q', 'q') map('n', 'o', 'only') map('n', '', 'nohlsearch') wk.register({ [''] = { 'Telescope find_files', 'File file in project' }, ['/'] = { 'Telescope live_grep', 'Search project' }, [''] = { 'NERDTreeToggle', 'Toggle NERDTree' }, f = { name = 'file', e = { 'Telescope find_files cwd=~/.config/nvim', 'Find file in .config/nvim' }, E = { 'e ~/.config/nvim', 'Browse .config/nvim' }, f = { 'Telescope find_files cwd=~/ hidden=true no_ignore=true no_ignore_parent=true follow=true theme=dropdown', 'Find file' }, F = { 'Telescope find_files theme=dropdown', 'File file from here' }, l = { 'NERDTreeFind', 'Locate file' }, r = { 'Telescope oldfiles', 'Recent files' }, }, e = { name = 'editor', p = { name = 'packer', s = { 'PackerSync', 'Packer Sync' }, c = { 'PackerCompile', 'Packer Compile' }, l = { 'PackerClean', 'Packer Clean' }, } }, g = { name = 'git', s = { 'Git', 'Status' }, p = { 'Git push', 'Push' }, P = { 'Git push --force-with-lease', 'Push (force with lease)' }, f = { 'Git fetch', 'Fetch' }, r = { name = 'rebase', o = { 'Git rebase origin/main', 'origin/main' }, O = { 'Git rebase --interactive origin/main', '-i origin/main' }, m = { 'Git rebase origin/master', 'origin/master' }, M = { 'Git rebase --interactive origin/master', '-i origin/master' }, r = { 'Git rebase ', 'rebase ...' }, } }, i = { name = 'insert', e = { 'Telescope emoji theme=dropdown', 'emoji' }, }, n = { name = 'line numbers', a = { 'set number norelativenumber', 'absolute' }, r = { 'set number relativenumber', 'relative' }, } }, { prefix = '' }) vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('UserLspConfig', {}), callback = function(ev) -- Enable completion triggered by vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' -- Buffer local mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions local opts = { buffer = ev.buf } vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) -- vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) -- vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) -- vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) -- vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) -- vim.keymap.set('n', 'wl', function() -- print(vim.inspect(vim.lsp.buf.list_workspace_folders())) -- end, opts) -- vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) -- vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) -- vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, opts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) vim.keymap.set('n', 'F', function() vim.lsp.buf.format { async = true } end, opts) end, })