Files
dotfiles/nvim/ftplugin/markdown.vim
T
Fabian IsingandClaude Opus 5.5 925c71cbaa [NVIM] Add markdown table and checklist support
render-markdown (tables/checkboxes only), vim-table-mode, prettier via
conform, cell jumps and checkbox toggle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 21:49:24 +02:00

67 lines
2.8 KiB
VimL

" Table cell jumps without table mode ([| ]| {| }|)
function! s:CellMaps()
nmap <buffer> [<Bar> <Plug>(table-mode-motion-left)
nmap <buffer> ]<Bar> <Plug>(table-mode-motion-right)
nmap <buffer> {<Bar> <Plug>(table-mode-motion-up)
nmap <buffer> }<Bar> <Plug>(table-mode-motion-down)
endfunction
call s:CellMaps()
" Leaving table mode unmaps them, so restore
augroup markdown_cell_maps
autocmd! * <buffer>
autocmd User TableModeDisabled if &filetype ==# 'markdown' | call s:CellMaps() | endif
augroup END
" <Leader>T{h,j,k,l} and <Leader><Arrow> jump one cell
nmap <buffer> <Leader>Th <Plug>(table-mode-motion-left)
nmap <buffer> <Leader>Tj <Plug>(table-mode-motion-down)
nmap <buffer> <Leader>Tk <Plug>(table-mode-motion-up)
nmap <buffer> <Leader>Tl <Plug>(table-mode-motion-right)
nmap <buffer> <Leader><Left> <Plug>(table-mode-motion-left)
nmap <buffer> <Leader><Down> <Plug>(table-mode-motion-down)
nmap <buffer> <Leader><Up> <Plug>(table-mode-motion-up)
nmap <buffer> <Leader><Right> <Plug>(table-mode-motion-right)
" <Leader>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', '<Leader>x', function() toggle(vim.fn.line('.')) end,
{ buffer = true, desc = 'Toggle checkbox' })
vim.keymap.set('x', '<Leader>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('<Esc>'), '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', '<Plug>(md-S-' .. key .. ')', '<S-' .. key .. '>', { buffer = true })
vim.keymap.set('n', '<S-' .. key .. '>', function()
if vim.fn.getline('.'):match('^%s*|') then
return '<Plug>(table-mode-motion-' .. dir .. ')'
end
return '<Plug>(md-S-' .. key .. ')'
end, { buffer = true, expr = true, remap = true, desc = 'Table cell or default' })
end
EOF