"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " File: ftplugin/markdown.vim " Maintainer: Andrew Nechaev " Version: 0.1.0 " Modified: 2022-05-13 21:00+0400 " License: MIT """""""""""""""""""""""""""""""""""""""""""""""""""""""""""" nnoremap t :call winrestview(toggle({' ': 'x', 'x': '-', '-': ' '})) vnoremap t :call winrestview(toggle({' ': 'x', 'x': '-', '-': ' '})) nnoremap r :call winrestview(toggleState('(', '( ) ')) vnoremap r :call winrestview(toggleState('(', '( ) ')) nnoremap c :call winrestview(toggleState('[', '[ ] ')) vnoremap c :call winrestview(toggleState('[', '[ ] ')) 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