From 9c4caee64674a322336e694c4feac07be3d0e40a Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Sat, 23 Jul 2016 13:20:29 +0100 Subject: [PATCH] Customise vim-surround for markdown link syntax --- after/ftplugin/markdown.vim | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/after/ftplugin/markdown.vim b/after/ftplugin/markdown.vim index f6ad3c2..f03c0de 100644 --- a/after/ftplugin/markdown.vim +++ b/after/ftplugin/markdown.vim @@ -1,6 +1,39 @@ +" Enable spelling except in Windows terminal vim. if !has("win32") || has("gui_running") setlocal spell endif + +" Max 80 chars wide. setlocal textwidth=80 -" Use tabwidth of 4 to be markdown complient +" Use tabwidth of 4 to be markdown complient. setlocal tabstop=4 shiftwidth=4 softtabstop=4 + +" Custom surround for markdown link syntax. +" "ys{motion}[" makes link out of "word" -> "[word]()" +autocmd FileType markdown let b:surround_91 = "[\r]()" +" "ys{motion}]" makes link out of "url" -> "[](url)" +autocmd FileType markdown let b:surround_93 = "[](\r)" + +finish " Experiment functionality (disabled). {{{ + +nnoremap yh :set opfunc=yhg@ +function! yh(type, ...) + let save_reg_h = getreg('h') + " Mark positions + let begin = getpos("'[")[1:2] + let end = getpos("']")[1:2] + " Append after the end mark. + call cursor(end) + call setreg('h', ']()') + normal "hp + " Prepend before the begin mark. + call cursor(begin) + call setreg('h', '[') + normal "hP + " Place cursor at final ) + call cursor(end) + normal f) + call setreg('h', save_reg_h) +endfunction + +" }}}