Xavier Nayrac

Rubyiste accro au TDD, serial blogger, apprenti data scientist, heureux utilisateur de Vim, accordéoniste.
Si vous vous sentez particulièrement généreux, suivez moi sur Twitter.

Vim - un plugin pour markdown - partie 4

| Comments

Niveau : intermédiaire

Maintenant on fait tous les titres, jusqu’au niveau 6 donc.

autoload/quickmarkdown.vim
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
function s:build_big_title(char)
  let s:line_content = substitute(getline("."), '.', a:char, 'g')
  call append('.', s:line_content)
endfunction

function s:build_little_title(str)
  call setline(line('.'), a:str . getline('.'))
endfunction

function! quickmarkdown#title1()
  call s:build_big_title("=")
endfunction

function! quickmarkdown#title2()
  call s:build_big_title("-")
endfunction

function! quickmarkdown#title3()
  call s:build_little_title("### ")
endfunction

function! quickmarkdown#title4()
  call s:build_little_title("#### ")
endfunction

function! quickmarkdown#title5()
  call s:build_little_title("##### ")
endfunction

function! quickmarkdown#title6()
  call s:build_little_title("###### ")
endfunction
plugin/quickmarkdown.vim
1
2
3
4
5
6
command! QuickMarkdownTitle1 call quickmarkdown#title1()
command! QuickMarkdownTitle2 call quickmarkdown#title2()
command! QuickMarkdownTitle3 call quickmarkdown#title3()
command! QuickMarkdownTitle4 call quickmarkdown#title4()
command! QuickMarkdownTitle5 call quickmarkdown#title5()
command! QuickMarkdownTitle6 call quickmarkdown#title6()

J’ai aussi changé mon mapping pour qu’il soit plus homogène.

En qwerty:

.vimrc
1
2
3
4
5
6
nmap <Leader>m1 :QuickMarkdownTitle1<Enter>
nmap <Leader>m2 :QuickMarkdownTitle2<Enter>
nmap <Leader>m3 :QuickMarkdownTitle3<Enter>
nmap <Leader>m4 :QuickMarkdownTitle4<Enter>
nmap <Leader>m5 :QuickMarkdownTitle5<Enter>
nmap <Leader>m6 :QuickMarkdownTitle6<Enter>

En azerty:

.vimrc
1
2
3
4
5
6
nmap <Leader>m& :QuickMarkdownTitle1<Enter>
nmap <Leader>mé :QuickMarkdownTitle2<Enter>
nmap <Leader>m" :QuickMarkdownTitle3<Enter>
nmap <Leader>m' :QuickMarkdownTitle4<Enter>
nmap <Leader>m( :QuickMarkdownTitle5<Enter>
nmap <Leader>m- :QuickMarkdownTitle6<Enter>

En bépo:

.vimrc
1
2
3
4
5
6
nmap <Leader>m" :QuickMarkdownTitle1<Enter>
nmap <Leader>m« :QuickMarkdownTitle2<Enter>
nmap <Leader>m» :QuickMarkdownTitle3<Enter>
nmap <Leader>m( :QuickMarkdownTitle4<Enter>
nmap <Leader>m) :QuickMarkdownTitle5<Enter>
nmap <Leader>m@ :QuickMarkdownTitle6<Enter>

À demain.

Articles connexes

Commentaires