2

To take a short cut in writing markdown files I need an abbreviation which can combine these abbreviations,

autocmd FileType * iabbrev pythoncode ```python```<left><left><left><cr>jjO<C-R>=Eatchar('\s')<cr>    
autocmd FileType * iabbrev vimcode ```vim```<left><left><left><cr>jjO<C-R>=Eatchar('\s')<cr>    
autocmd FileType * iabbrev bashcode ```bash```<left><left><left><cr>jjO<C-R>=Eatchar('\s')<cr>

into one,

autocmd FileType * iabbrev [aLanguage]code ```[aLanguage]```<left><left><left><cr>jjO<C-R>=Eatchar('\s')<cr> 

I don't know how to start with. In the input the "code" can be put ahead, resulting in the command being code[aLanguage], if it is more eligible.

Lerner Zhang
  • 740
  • 7
  • 19

1 Answers1

3

You could use a loop and exec:

for l in ["python", "vim", "bash"]
    exec 'autocmd FileType * iabbrev' l."code ```" l."```<left><left><left><cr>jjO<C-R>=Eatchar('\s')<cr>"
endfor
Lerner Zhang
  • 740
  • 7
  • 19
muru
  • 24,838
  • 8
  • 82
  • 143