local function map(mode, lhs, rhs, opts) local options = { noremap = true, silent = true, } if opts then options = vim.tbl_extend('force', options, opts) end vim.keymap.set(mode, lhs, rhs, options) end -- Save File map( { 'i', 'v', 'n', 's', }, '', 'w', { desc = 'Save file', } ) map('i', '', '"+pa', { desc = 'Paste from clipboard', }) map('n', '', 'm`op``', { desc = 'Paste below', }) map('n', '', 'm`Op``', { desc = 'Paste above', }) map( { 'n', 'x', }, '', '"+y', { desc = 'Copy to clipboard', } ) map( { 'n', 'x', }, '', '"+ydd', { desc = 'Cut to clipboard', } ) -- Reselect the text that has just been pasted, see also https://stackoverflow.com/a/4317090/6064933. map('n', '', "printf('`[%s`]', getregtype()[0])", { expr = true, desc = 'reselect last pasted area', }) map( { 'i', 'v', 'n', 's', }, '', 'wq!', { desc = 'Force Save file and quit', } ) -- Select all text in the current buffer map('n', '', ':keepjumps normal! ggyG', { desc = 'Select all', }) -- quit map('n', '', 'wqa!', { desc = 'Quit all', }) -- go to beginning and end in insert mode map('i', '', '^i', { desc = 'Go to beginning of line', }) map('i', '', '', { desc = 'Go to end of line', }) -- Go to the beginning and end of current line in insert mode quickly map('i', '', '') map('i', '', '') -- insert semicolon in the end map('i', '', 'miA;`ii', { desc = 'insert semicolon in the end', }) -- Turn the word under cursor to upper case map('i', '', 'viwUea') -- Turn the current word into lower case map('i', '', 'b~lea') -- Undo map('i', '', 'u') -- navigate within insert mode map('i', '', '', { desc = 'Move Left', }) map('i', '', '', { desc = 'Move Right', }) map('i', '', '', { desc = 'Move Down', }) map('i', '', '', { desc = 'Move Up', }) -- Copy whole buffer map('n', '', '%y+', { desc = 'Copy whole buffer', }) -- Go to start or end of line easier map( { 'n', 'x', }, 'H', '^', { desc = 'Go to beginning of line', } ) map( { 'n', 'x', }, 'L', 'g_', { desc = 'Go to end of line', } ) -- Change text without putting it into the vim register, map( { 'n', 'x', }, 'c', '"_c', { desc = 'Change without yanking', } ) map( { 'n', 'x', }, 'C', '"_C', { desc = 'Change without yanking', } ) map( { 'n', 'x', }, 'cc', '"_cc', { desc = 'Change without yanking', } ) map( { 'n', 'x', }, 'x', '"_x', { desc = 'delete without yanking', } ) -- Better escape using jk in insert and terminal mode map('i', 'jk', '') map('i', 'kj', '') map('i', 'jj', '') -- Terminal Mappings map('t', 'jk', '') map('t', 'kj', '') map('t', '', '') -- Move with shift-arrows map('n', '', '', { desc = 'Move window to the left', }) map('n', '', '', { desc = 'Move window down', }) map('n', '', '', { desc = 'Move window up', }) map('n', '', '', { desc = 'Move window to the right', }) -- Search map( { 'n', 'x', }, 'gw', '*N', { desc = 'Search word under cursor', } ) -- Some cool remaps map('n', 'n', 'nzzzv') map('n', 'N', 'Nzzzv') map('n', 'J', 'mzJ`z') map('n', '}', '}zzzv') map('n', '{', '{zzzv') map('n', 'g,', 'g,zvzz') map('n', 'g;', 'g;zvzz') map('n', '', 'zz') map('n', '', 'zz') map('n', '^', 'g^') map('n', '0', 'g0') -- Do not include white space characters when using $ in visual mode, map('x', '$', 'g_') -- Always use very magic mode for searching map('n', '/', [[/\v]]) -- Add undo break-points map('i', '?', '?u') map('i', '!', '!u') map('i', ',', ',u') map('i', '.', '.u') map('i', ';', ';u') -- compromised backward search when comma is being used as localleader map('n', '', ',') -- Better up/down map({ 'n', 'x' }, 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) map({ 'n', 'x' }, '', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) map({ 'n', 'x' }, 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) map({ 'n', 'x' }, '', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) -- Move text up and down map('n', '', 'm .+1==', { desc = 'Move Down' }) map('n', '', 'm .-2==', { desc = 'Move Up' }) map('i', '', 'm .+1==gi', { desc = 'Move Down' }) map('i', '', 'm .-2==gi', { desc = 'Move Up' }) map('v', '', ":m '>+1gv=gv", { desc = 'Move Down' }) map('v', '', ":m '<-4gv=gv", { desc = 'Move Up' })