Skip to content

Instantly share code, notes, and snippets.

@tjdevries
Created June 2, 2021 00:55
Show Gist options
  • Save tjdevries/9068778bc4997231efcfb81bd5dde53f to your computer and use it in GitHub Desktop.
Save tjdevries/9068778bc4997231efcfb81bd5dde53f to your computer and use it in GitHub Desktop.
Yo
function s:PerlSubstitute(line1, line2, sstring)
let l:lines = getline(a:line1, a:line2)
" Perl command with 'utf8' enabled
" '#line 1' makes error messages prettier, displayed below:
" Substitution replacement not terminated at PerlSubstitute line 1.
let l:sysresult = systemlist("perl -e 'use utf8;' -e '#line 1 \"PerlSubstitute\"' -pe ". shellescape("s".escape(a:sstring,"%!").";"), l:lines)
if v:shell_error
echo l:sysresult
return
endif
call nvim_buf_set_lines(0, a:line1 - 1, a:line2, v:false, l:sysresult)
endfunction
command! -range -nargs=1 S call s:PerlSubstitute(<line1>, <line2>, <q-args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment