-- set the leader key to space vim.api.nvim_set_keymap('n', '', '', {}) vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- helper function for easier mappings local map = function(mode, lhs, rhs, opts) return vim.api.nvim_set_keymap(mode, lhs, rhs, vim.tbl_extend('keep', opts or {}, { nowait = true, silent = true, noremap = true, })) end -- remap semi-colon to be colon in normal an visual mode map('n', ';', ':') map('v', ';', ':') -- deactivate ex-mode and man-pages map('n', 'Q', '') map('n', 'K', '') -- Keeping it centered when searching and jumping to next entry map('n', 'n', 'nzzzv') map('n', 'N', 'Nzzzv') -- j and k for wrapped lines map('n', 'j', 'gj') map('n', 'k', 'gk') -- sane yanking and copying to clipboard/alfred-history map('n', 'Y', 'y$') map('n', 'yy', 'yy call system("nc localhost 8377", @0)') map('v', 'y', 'y call system("nc localhost 8377", @0)') map('v', 'Y', 'y call system("nc localhost 8377", @0)') -- Swap v and CTRL-V, because Block mode is more useful map('n', 'v', '') map('n', '', 'v') map('v', 'v', '') map('v', '', 'v') -- add undo-repo-breakpoints automatically when writing long text map('i', ',', ',u') map('i', '.', '.u') map('i', '!', '!u') map('i', '?', '?u') -- bubbling of lines/selections with alt + hjkl map('n', '˚', ':move .-2', { noremap = false }) map('n', '∆', ':move .+1', { noremap = false }) map('n', '˙', '<<', { noremap = false }) map('n', '¬', '>>', { noremap = false }) map('v', '˚', ":move '<-2gv", { noremap = false }) map('v', '∆', ":move '>+1gv", { noremap = false }) map('v', '˙', 'gv', { noremap = false }) -- use the arrowkeys for usefull stuff in normal mode -- switching buffers map('n', '', 'bfirst') map('n', '', 'blast') map('n', '', 'bp') map('n', '', 'bn') -- easieser splits map('n', '\\', 'vl') map('n', '-', 'sj') -- fzf-lua map('n', ',', 'lua require("fzf-lua").files()') map('n', '.', 'lua require("fzf-lua").buffers()') map('n', '/', 'lua require("fzf-lua").search_history()') map('n', ';', 'lua require("fzf-lua").command_history()') map('n', '`', 'lua require("fzf-lua").files({ cwd = "~/" })') map('n', 'a', 'lua require("fzf-lua").live_grep()') map('n', 'b', 'lua require("fzf-lua").git_branches()') map('n', 'c', 'lua require("fzf-lua").git_bcommits()') map('n', ']', 'lua require("fzf-lua").lines()') -- lsp and diagnostics map('n', 'gd', 'lua vim.lsp.buf.definition()') map('n', 'gi', 'lua vim.lsp.buf.implementation()') map('n', 'gr', 'lua vim.lsp.buf.references()') map('n', 'd', 'lua vim.lsp.buf.declaration()') map('n', 'e', 'lua vim.diagnostic.goto_next()') map('n', 'f', 'lua vim.lsp.buf.formatting()') map('n', 'h', 'lua vim.lsp.buf.hover()') map('n', 'r', 'lua vim.lsp.buf.rename()') map('n', 'x', 'lua vim.lsp.buf.code_action()') -- git map('n', 'l', 'FloatermNew lazygit') map('n', 'gb', 'FloatermNew git blame %') map('n', 'gd', 'DiffviewOpen') map('n', 'gc', 'DiffviewClose') map('n', 'gh', 'DiffviewFileHistory') map('n', 'gf', "execute '/\\v^[<\\|=>]{7}/'") -- floaterm map('n', '-', 'FloatermNew nnn') map('n', 't', 'FloatermNew') -- vsnip snippets expansion map('i', '', 'vsnip#available(1) ? "(vsnip-expand-or-jump)" : ""', { expr = true, noremap = false }) map('s', '', 'vsnip#available(-1) ? "(vsnip-jump-prev)" : ""', { expr = true, noremap = false }) -- other useful mappings map('n', '', 'checktimeredraw!'); map('n', 've', 'e $MYVIMRC') map('n', 'vr', 'source $MYVIMRC') map('n', 'w', 'set wrap! wrap?')