function map(mode, shortcut, command) vim.keymap.set(mode, shortcut, command, { noremap = true, silent = true }) end vim.g.mapleader = ' ' -- -- buffers map('n', 'b', ':buffers:buffer') map('n', '', ':bprevious') map('n', '', ':bnext') map('i', '', ':bprevious') map('i', '', ':bnext') --windows map('n', '', ':wincmd h') map('n', '', ':wincmd j') map('n', '', ':wincmd k') map('n', '', ':wincmd l') map('i', '', ':wincmd h') map('i', '', ':wincmd j') map('i', '', ':wincmd k') map('i', '', ':wincmd l') -- remove word map('n', '', 'db') vim.cmd([[map! ]]) -- TODO: figure out how to do that with lua map('n', '', 'dw') map('i', '', 'dw') -- remove whitespace around cursor map({ 'n', 'i' }, '', function() local row, pos_cursor = unpack(vim.api.nvim_win_get_cursor(0)) pos_cursor = pos_cursor + 1 -- api / lua is off by one local line = vim.api.nvim_get_current_line() local pos_start, pos_end = 0, 0 while (pos_start ~= nil) do if (pos_start <= pos_cursor and pos_end >= pos_cursor) then local before = line:sub(1, pos_start - 1) local after = line:sub(pos_end + 1) local space = '' if (before:len() > 0 and after:len() > 0) then space = ' ' end vim.api.nvim_set_current_line(before .. space .. after) vim.api.nvim_win_set_cursor(0, { row, pos_start - 1 }) break end pos_start, pos_end = line:find('%s+', pos_end + 1) end end ) -- move buffer without moving cursor map('n', '', '') map('n', '', '') -- system clipboard map('v', 'y', '"+y') map('n', 'p', '"+p') -- toggle between beginning of line and beginning of text map({ 'n', 'i', 'v' }, '', function() local row, col = unpack(vim.api.nvim_win_get_cursor(0)) if (col == 0) then local col_new = vim.api.nvim_get_current_line():match('^%s*'):len() vim.api.nvim_win_set_cursor(0, { row, col_new }) else vim.api.nvim_win_set_cursor(0, { row, 0 }) end end ) map('n', '', '==') -- re-indent line