mirror of
https://github.com/inkarkat/vim-ingo-library.git
synced 2026-05-29 11:18:51 +02:00
24583025b8
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)))
28 lines
877 B
VimL
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 :
|