vim: doc, odt, pdf und Co.
Grad auf Reddit gesehen und finde es erwähnenswert: mit diesem Schnipsel kann man Word-Dokumente, LibreOffice-Dokumente etc direkt in vim öffnen (RO). Natürlich müssen die benötigten Tools installiert sein (antiword, pandoc, odt2txt etc).
augroup read_special_files
au!
au BufWinEnter *.{doc,docx,epub,odp,odt,pdf,rtf} call s:filter_special_files()
augroup END
fu! s:filter_special_files() abort
if get(b:, 'did_filter_special_file', 0)
return
endif
let fname = shellescape(expand('%:p'), 1)
let ext = expand('%:e')
let ext2filter_cmd = {
\ 'doc' : '%!antiword '.fname,
\ 'docx': '%!pandoc -f docx -t markdown '.fname,
\ 'epub': '%!pandoc -f epub -t markdown '.fname,
\ 'odp' : '%!odt2txt '.fname,
\ 'odt' : '%!odt2txt '.fname,
\ 'pdf' : '%!pdftotext -nopgbrk -layout -q -eol unix '.fname.' -',
\ 'rtf' : '%!unrtf --text',
\ }
setl ma noro
sil exe has_key(ext2filter_cmd, ext)
\? ext2filter_cmd[ext]
\: ''
setl noma ro nomod
let b:did_filter_special_file = 1
endfu
Und das ganze funktioniert dann auch noch verdammt gut. Geil.
1 thought on “vim: doc, odt, pdf und Co.”
vim: doc, odt, pdf und Co. http://blog.datentraeger.li/?p=967
Comments are closed.