2022-05-13 19:17:41 +03:00
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
|
" File: ftplugin/markdown.vim
|
|
|
|
|
" Maintainer: Andrew Nechaev <i@geekfrom.ru>
|
2022-05-13 20:04:10 +03:00
|
|
|
" Version: 0.1.0
|
2022-05-16 12:48:45 +03:00
|
|
|
" Modified: 2022-05-16 13:48+0400
|
2022-05-13 19:17:41 +03:00
|
|
|
" License: MIT
|
|
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
|
|
2022-05-16 12:48:45 +03:00
|
|
|
set textwidth=120
|
|
|
|
|
set formatoptions+=t
|
|
|
|
|
set colorcolumn=-1
|
|
|
|
|
set wm=0
|
|
|
|
|
set wrap linebreak
|
|
|
|
|
|
2022-05-16 12:16:15 +03:00
|
|
|
nnoremap <buffer> <silent> <Leader>t :call winrestview(<SID>toggle({' ': 'x', 'x': '-', '-': ' '}))<cr>:w!<cr>
|
|
|
|
|
vnoremap <buffer> <silent> <Leader>t :call winrestview(<SID>toggle({' ': 'x', 'x': '-', '-': ' '}))<cr><esc>:w!<cr>
|
2022-05-13 19:17:41 +03:00
|
|
|
|
2022-09-01 21:38:33 +03:00
|
|
|
nnoremap <buffer> <silent> <Leader>r :call winrestview(<SID>toggleState('(', '( ) '))<cr>A
|
2022-05-13 19:17:41 +03:00
|
|
|
vnoremap <buffer> <silent> <Leader>r :call winrestview(<SID>toggleState('(', '( ) '))<cr>
|
2022-09-01 21:38:33 +03:00
|
|
|
nnoremap <buffer> <silent> <Leader>c :call winrestview(<SID>toggleState('[', '[ ] '))<cr>A
|
2022-05-13 19:17:41 +03:00
|
|
|
vnoremap <buffer> <silent> <Leader>c :call winrestview(<SID>toggleState('[', '[ ] '))<cr>
|
|
|
|
|
|
2022-09-01 22:29:12 +03:00
|
|
|
inoremap <buffer> <CR> <CR><Esc>:call <SID>auto_list()<CR>A
|
|
|
|
|
nnoremap <buffer> o o<Esc>:call <SID>auto_list()<CR>A
|
|
|
|
|
nnoremap <buffer> O O<Esc>:call <SID>auto_list()<CR>A
|
|
|
|
|
|
2022-05-13 19:17:41 +03:00
|
|
|
set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
|
|
|
|
|
|
2022-05-13 20:04:10 +03:00
|
|
|
function s:toggle(dict)
|
2022-05-13 19:17:41 +03:00
|
|
|
let view = winsaveview()
|
2022-05-13 20:04:10 +03:00
|
|
|
execute 'keeppatterns s/^\s*\(-\s*\|+\s*\|*\s\)\?\s*[\[(]\zs.\ze[\])]/\=get(a:dict, submatch(0), a:0 ? a:1 : " ")/e'
|
2022-05-13 19:17:41 +03:00
|
|
|
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
|
|
|
|
|
|
2022-09-01 22:29:12 +03:00
|
|
|
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
|