I am using a file with the following format:
something both french and english
fr: du français
fr: du français
en: something in english
en: also in markdown format
What would be ideal for me is to see this in vim:
French | English
--------------------------------------------------------------
du français | something in english
| also in markdown format
I am close to this using fold. But I have two problems.
The first is to hide the "en: " or "fr: " part in each line while keeping the right syntax highlighting. I hacked a bit the syntax highlighting format for markdown.
The second is I don't know how to hide single line with fold. Up until there here is my code:
" multilanguage folders
autocmd BufEnter *.md setlocal foldmethod=expr
" se lance avec execute FrenchView()
fun! FrenchView()
%g/^en: .*$\n^en: /foldclose
%g/^fr: .*$\n^fr: /foldopen
" setlocal foldexpr=getline(v:lnum)=~'^en:\ '?1:0
endfun
" se lance avec execute EnglishView()
fun! EnglishView()
%g/^fr: .*$\n^fr: /foldclose
%g/^en: .*$\n^en: /foldopen
" setlocal foldexpr=getline(v:lnum)=~'^fr:\ '?1:0
endfun
fun! MyFoldLevel(lnum)
if getline(a:lnum)=~'^fr:\ '
if getline(a:lnum+1)=~'^fr:\ '
return '1'
else
return '<1'
endif
else
if getline(a:lnum)=~'^en:\ '
if getline(a:lnum+1)=~'^en:\ '
return '1'
else
return '<1'
endif
else
return 0
endif
endif
endfun
" use with execute MultiView()
fun! MultiView()
setlocal foldexpr=MyFoldLevel(v:lnum)
endfun
:command FR execute FrenchView()
:command EN execute EnglishView()
:command MM execute MultiView()
autocmd BufEnter *.md execute MultiView()
autocmd BufEnter *latest.md set scrollbind
autocmd BufEnter *latest.md execute FrenchView()
autocmd BufEnter *latest.md vsplit
autocmd BufEnter *latest.md execute EnglishView()
autocmd BufEnter *.md setlocal foldmethod=expr
" se lance avec execute FrenchView()
fun! FrenchView()
%g/^en: .*$\n^en: /foldclose
%g/^fr: .*$\n^fr: /foldopen
" setlocal foldexpr=getline(v:lnum)=~'^en:\ '?1:0
endfun
" se lance avec execute EnglishView()
fun! EnglishView()
%g/^fr: .*$\n^fr: /foldclose
%g/^en: .*$\n^en: /foldopen
" setlocal foldexpr=getline(v:lnum)=~'^fr:\ '?1:0
endfun
fun! MyFoldLevel(lnum)
if getline(a:lnum)=~'^fr:\ '
if getline(a:lnum+1)=~'^fr:\ '
return '1'
else
return '<1'
endif
else
if getline(a:lnum)=~'^en:\ '
if getline(a:lnum+1)=~'^en:\ '
return '1'
else
return '<1'
endif
else
return 0
endif
endif
endfun
" use with execute MultiView()
fun! MultiView()
setlocal foldexpr=MyFoldLevel(v:lnum)
endfun
:command FR execute FrenchView()
:command EN execute EnglishView()
:command MM execute MultiView()
autocmd BufEnter *.md execute MultiView()
autocmd BufEnter *latest.md set scrollbind
autocmd BufEnter *latest.md execute FrenchView()
autocmd BufEnter *latest.md vsplit
autocmd BufEnter *latest.md execute EnglishView()
May my complete method is wrong. Furthermore I would like to have the ability to make "language block".
How would you do it?
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment