From b904c00d887ebba23fc301d3b6fadb25ad9a134d Mon Sep 17 00:00:00 2001 From: Mark Campbell Date: Wed, 20 Mar 2024 16:04:33 -0500 Subject: [PATCH] Fix newlines not being properly escaped Closes #28 https://github.com/ruby-formatter/rufo-vim/issues/28 --- autoload/rufo.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/autoload/rufo.vim b/autoload/rufo.vim index fe423a9..dde5238 100644 --- a/autoload/rufo.vim +++ b/autoload/rufo.vim @@ -61,7 +61,9 @@ function! s:format(start_line, end_line) abort silent exec l:buffer_number . 'bdelete' endif - let l:selection = join(getline(a:start_line, a:end_line), "\n") + let l:lines = getline(a:start_line, a:end_line) + let l:escaped_lines = map(l:lines, 'substitute(v:val, "\\\\n", "\\\\\\\\n", "g")') + let l:selection = join(l:escaped_lines, "\n") let l:out = systemlist('echo ' . shellescape(l:selection) . '| rufo') return [s:formatting_failed(v:shell_error), l:out] endf