local partial = require('user.util').partial local nmap = partial(vim.keymap.set, 'n') local imap = partial(vim.keymap.set, 'i') local vmap = partial(vim.keymap.set, 'v') local cmap = partial(vim.keymap.set, 'c') local tmap = partial(vim.keymap.set, 't') -- better navigation for wrapped lines nmap('j', 'gj') nmap('k', 'gk') -- maintain cursor position when joining lines nmap('J', 'mzJ`z') -- retain selection when making changes in visual mode vmap( '', 'gv') vmap( '', 'gv') vmap('g', 'ggv') vmap('g', 'ggv') vmap('>', '>gv') vmap('<', '<gv') -- place destination of important movements in the center of the screen nmap('n', 'nzzzv') nmap('N', 'Nzzzv') nmap('', 'zzzv') nmap('', 'zzzv') -- easier window navigation nmap('', 'j') nmap('', 'k') nmap('', 'h') nmap('', 'l') -- window resizing nmap('', 'resize +1') nmap('', 'resize -1') nmap('', 'vertical resize -1') nmap('', 'vertical resize +1') -- easy tab navigation nmap('', 'tabnext', { silent = true }) nmap('', 'tabprevious', { silent = true }) -- move lines up and down nmap('', [[:move .+1==]], { silent = true }) nmap('', [[:move .-2==]], { silent = true }) vmap('', [[:move '>+1gv=gv]], { silent = true }) vmap('', [[:move '<-2gv=gv]], { silent = true }) imap('', [[:move .+1==gi]], { silent = true }) imap('', [[:move .-2==gi]], { silent = true }) -- move to begin/end of line in insert mode imap('', '^') imap('', '$') -- move to begin of line in command mode ( moves to end by default) cmap('', '') -- navigate items in quickfix and location lists nmap('', 'cnextzz', { silent = true }) nmap('', 'cpreviouszz', { silent = true }) nmap('', 'lnextzz', { silent = true }) nmap('', 'lpreviouszz', { silent = true }) -- navigate diagnostics nmap('j', require('user.util').goto_next_diagnostic) nmap('k', require('user.util').goto_prev_diagnostic) -- quickly open lazy.nvim plugin manager nmap('L', 'Lazy') -- toggle options local toggle_number = function() vim.wo.number = not vim.wo.number vim.wo.relativenumber = false end local toggle_relativenumber = function() vim.wo.relativenumber = not vim.wo.relativenumber vim.wo.number = vim.wo.relativenumber or vim.wo.number end nmap('sn', toggle_number) nmap('sr', toggle_relativenumber) nmap('sl', 'set list! | set list?', { silent = true }) nmap('sw', 'set wrap! | set wrap?', { silent = true }) nmap('sp', 'set spell! | set spell?', { silent = true }) -- quickly change background nmap('bg', [[let &background = &background ==? 'light' ? 'dark' : 'light']]) -- disable highlight until next search nmap('', 'nohlsearch') imap('', 'nohlsearch') -- more convenient way of entering normal mode from terminal mode tmap([[]], [[]]) -- recall older/recent command-line from history cmap('', '') cmap('', '')