"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " File: ftplugin/markdown.vim " Maintainer: Andrew Nechaev " Version: 0.1.0 " Modified: 2022-05-16 13:48+0400 " License: MIT """""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set textwidth=120 set formatoptions+=t set colorcolumn=-1 set wm=0 set wrap linebreak nnoremap t :call winrestview(toggle({' ': 'x', 'x': '-', '-': ' '})):w! vnoremap t :call winrestview(toggle({' ': 'x', 'x': '-', '-': ' '})):w! nnoremap r :call winrestview(toggleState('(', '( ) '))A vnoremap r :call winrestview(toggleState('(', '( ) ')) nnoremap c :call winrestview(toggleState('[', '[ ] '))A vnoremap c :call winrestview(toggleState('[', '[ ] ')) inoremap :call auto_list()A nnoremap o o:call auto_list()A nnoremap O O:call auto_list()A set tabstop=2 softtabstop=2 shiftwidth=2 expandtab function s:toggle(dict) let view = winsaveview() execute 'keeppatterns s/^\s*\(-\s*\|+\s*\|*\s\)\?\s*[\[(]\zs.\ze[\])]/\=get(a:dict, submatch(0), a:0 ? a:1 : " ")/e' return view endfunction function s:toggleState(search, replacement) let view = winsaveview() execute 'keeppatterns s/^\s*\(-\s*\|+\s*\|*\s\)\?\zs\(\[.\]\|(.)\)\?\s*\ze/\=match(submatch(0), a:search) != -1 ? "" : a:replacement/e' return view endfunction function! s:auto_list() let l:current_text = getline(line("."))< let l:preceding_line = getline(line(".") - 1) if l:preceding_line =~ '\v^\s*\d+\.' let l:list_index = matchstr(l:preceding_line, '\v\d+') let l:next = l:list_index + 1 let l:whitespaces = matchstr(l:preceding_line, '\v^\s*') call setline(".", l:whitespaces.l:next.". ".l:current_text) elseif l:preceding_line =~ '^\s*\(-\s*\|+\s*\|*\s\)\?\(\[.\]\|\(.\)\)\?' let l:starter = matchstr(l:preceding_line, '^\s*\(-\s*\|+\s*\|*\s\)\?\(\[.\]\|(.)\)\?\s*') call setline(".", l:starter.l:current_text) endif endfunction