Skip to content

Instantly share code, notes, and snippets.

@JeffCarpenter
Created May 20, 2021 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffCarpenter/e3d21be20b7bfa4308653e0229a3006b to your computer and use it in GitHub Desktop.
Save JeffCarpenter/e3d21be20b7bfa4308653e0229a3006b to your computer and use it in GitHub Desktop.
Dump current Vim Buffer
" 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