rkumar (owner)

Revisions

gist: 207771 Download_button fork
public
Public Clone URL: git://gist.github.com/207771.git
Embed All Files: show embed
markdownhelper #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
" 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