Created
May 20, 2021 22:14
-
-
Save JeffCarpenter/e3d21be20b7bfa4308653e0229a3006b to your computer and use it in GitHub Desktop.
Dump current Vim Buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" courtesy of the gocode autocompletion project | |
" https://github.com/nsf/gocode/blob/9d1e0378d35b0527c9aef0d17c0913fc38d88b81/vim/autoload/gocomplete.vim#L6-L19 | |
fu! s:dumpCurrentBuffer() | |
let buf = getline(1, '$') | |
if &encoding != 'utf-8' | |
let buf = map(buf, 'iconv(v:val, &encoding, "utf-8")') | |
endif | |
if &l:fileformat == 'dos' | |
" XXX: line2byte() depend on 'fileformat' option. | |
" so if fileformat is 'dos', 'buf' must include '\r'. | |
let buf = map(buf, 'v:val."\r"') | |
endif | |
let file = tempname() | |
call writefile(buf, file) | |
return file | |
endf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment