This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" place this in .vimrc file | |
" after marking a block, using key (,m) will prompt for a char | |
" which will be placed on both sides of the block | |
" A block start char such as {, [ or ( will be replaced by its corresponding | |
" end character. | |
" Useful if creating Markdown documents, or in README, TODO etc files | |
vmap ,m <ESC>:call VisualMarkdownTagWrap()<CR> | |
function! VisualMarkdownTagWrap() | |
let a:tag = input( "Chars to wrap block: ") | |
let braces_at_start = ['[','{','(','[','<'] | |
let braces_at_end = [']','}',')',']','>'] | |
let a:jumpright = 0 + len( a:tag ) | |
normal `< | |
let a:init_line = line( "." ) | |
exe "normal i".a:tag | |
normal `> | |
let a:end_line = line( "." ) | |
" Don't jump if we're on a new line | |
if( a:init_line == a:end_line ) | |
" Jump right to compensate for the | |
" characters we've added | |
exe "normal ".a:jumpright."l" | |
endif | |
let m = index(braces_at_start,a:tag) | |
if m >= 0 | |
"exe "normal a".strpart(braces_at_end,m,1) | |
exe "normal a".get(braces_at_end,m,"") | |
else | |
exe "normal a".a:tag | |
endif | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment