" Table cell jumps without table mode ([| ]| {| }|) function! s:CellMaps() nmap [ (table-mode-motion-left) nmap ] (table-mode-motion-right) nmap { (table-mode-motion-up) nmap } (table-mode-motion-down) endfunction call s:CellMaps() " Leaving table mode unmaps them, so restore augroup markdown_cell_maps autocmd! * autocmd User TableModeDisabled if &filetype ==# 'markdown' | call s:CellMaps() | endif augroup END " T{h,j,k,l} and jump one cell nmap Th (table-mode-motion-left) nmap Tj (table-mode-motion-down) nmap Tk (table-mode-motion-up) nmap Tl (table-mode-motion-right) nmap (table-mode-motion-left) nmap (table-mode-motion-down) nmap (table-mode-motion-up) nmap (table-mode-motion-right) " x toggles a checkbox; adds one to plain lines and list items lua << EOF local function toggle(lnum) local line = vim.fn.getline(lnum) local indent, marker, state, rest = line:match('^(%s*)([-*+] )%[([ xX])%] ?(.*)$') if not indent then indent, marker, state, rest = line:match('^(%s*)(%d+[.)] )%[([ xX])%] ?(.*)$') end if indent then state = state == ' ' and 'x' or ' ' else indent, marker, rest = line:match('^(%s*)([-*+] )(.*)$') if not indent then indent, marker, rest = line:match('^(%s*)(%d+[.)] )(.*)$') end if not indent then indent, rest = line:match('^(%s*)(.*)$') marker = '- ' end state = ' ' end vim.fn.setline(lnum, indent .. marker .. '[' .. state .. '] ' .. rest) end vim.keymap.set('n', 'x', function() toggle(vim.fn.line('.')) end, { buffer = true, desc = 'Toggle checkbox' }) vim.keymap.set('x', 'x', function() local a, b = vim.fn.line('v'), vim.fn.line('.') for l = math.min(a, b), math.max(a, b) do toggle(l) end vim.api.nvim_feedkeys(vim.keycode(''), 'n', false) end, { buffer = true, desc = 'Toggle checkboxes' }) -- Shift+arrows jump cells on table rows, keep their default elsewhere for key, dir in pairs({ Left = 'left', Down = 'down', Up = 'up', Right = 'right' }) do vim.keymap.set('n', '(md-S-' .. key .. ')', '', { buffer = true }) vim.keymap.set('n', '', function() if vim.fn.getline('.'):match('^%s*|') then return '(table-mode-motion-' .. dir .. ')' end return '(md-S-' .. key .. ')' end, { buffer = true, expr = true, remap = true, desc = 'Table cell or default' }) end EOF