Files
Ingo Karkat 24583025b8 Add ingo#convert#ToSingleLineString()
This needs to be used in place of string() when embedding a String in the right-hand side of a mapping; the existing ingo#escape#command#mapescape() would just convert to <CR>, which would still break the mapping when executed. The right way to use it is:

execute printf('map <F12> :call Foo(%s)<CR>', ingo#escape#command#mapescape(string(expr)))
2022-03-20 20:03:51 +01:00

28 lines
877 B
VimL

" ingo/convert.vim: Functions for type conversions.
"
" DEPENDENCIES:
"
" Copyright: (C) 2022 Ingo Karkat
" The VIM LICENSE applies to this script; see ':help copyright'.
"
" Maintainer: Ingo Karkat <ingo@karkat.de>
function! ingo#convert#ToSingleLineString( expr ) abort
"******************************************************************************
"* PURPOSE:
" Convert a:expr to a String that does not contain newline characters, but the
" "\n" notation instead.
"* ASSUMPTIONS / PRECONDITIONS:
" None.
"* EFFECTS / POSTCONDITIONS:
" None.
"* INPUTS:
" a:expr Variable (of arbitrary type, but likely String).
"* RETURN VALUES:
" String.
"******************************************************************************
return substitute(string(a:expr), '\n', "'.\"\\\\n\".'", 'g')
endfunction
" vim: set ts=8 sts=4 sw=4 noexpandtab ff=unix fdm=syntax :