---@format disable local map = require('my.functions').map vim.g.mapleader = ' ' -- vim.g.maplocalleader = ' ' -- (2 spaces) local format = string.format -- buffers map('n', 'b', ':buffers:buffer', 'Show open buffers') for key, cmd in pairs({ Left = 'bprevious', Right = 'bnext' }) do map('n', format('', key), format(':%s', cmd)) map('i', format('', key), format(':%s', cmd)) end ---- move buffer without moving cursor map({ 'n', 'v' }, '', '') map({ 'n', 'v' }, '', '') -- windows for key, letter in pairs({ Left = 'h', Down = 'j', Up = 'k', Right = 'l' }) do map('n', format('', key), format(':wincmd %s', letter)) map('i', format('', key), format(':wincmd %s', letter)) end -- remove word map('n', '', 'db') map('n', '', 'db') vim.cmd([[map! ]]) -- map('c', … doesn't work vim.cmd([[map!  ]]) map('n', '', 'db') -- terminal sends M-BS for C-BS vim.cmd([[map! ]]) 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 ) -- system clipboard (clipboard = , selection = middle mouse button) map({ 'v', 'n' }, 'y', '"+y', 'Yank to system clipboard') map({ 'v', 'n' }, '', '"*y', 'Yank to system selection') map('n', 'p', '"+p', 'Paste from system clipboard') map('n', 'P', '"+P', 'Paste from system clipboard') map('n', '', '"*p', 'Paste from system selection') map('n', '', '"*P', 'Paste from system selection') -- 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', 'v' }, '', '==') -- re-indent line -- select text with shift + arrow for _, key in ipairs({ 'Left', 'Up', 'Down', 'Right' }) do map({ 'n', 'i' }, format('', key), format('v<%s>', key)) map({ 'v' }, format('', key), format('<%s>', key)) end map('n', '', '', 'Follow symbol') map('n', '', '', 'Go back to previous pos') map('v', 'f', 'gq', 'Reformat text') map('n', '', ':bdelete', 'Close buffer') -- use ui.select for spelling suggestions so dressing can make it look nice local function spellsugg_select() local word = vim.fn.expand('') local suggestions = vim.fn.spellsuggest(word) vim.ui.select(suggestions, {}, vim.schedule_wrap(function(selected) if selected then vim.api.nvim_feedkeys('ciw' .. selected, 'n', true) vim.api.nvim_feedkeys( vim.api.nvim_replace_termcodes('', true, true, true), 'n', true) end end)) end map('n', 'z=', spellsugg_select) -- use easier keys for spell map('n', '', '[s', 'Previous misspelled word') -- map('n', '', ']s', 'Next misspelled word') -- map('n', '', spellsugg_select, 'Spelling suggestions') --