Suppose you run the following piece of vimscript:
let @z = system("date")
This will put a string version of the current date into the z register, but the string will end with a newline that I don’t want. Is there a built-in way (similar to Perl’s chomp) to get rid of a string’s trailing newlines?
callsyntax? Why not just giveChompa parameter calledstringand then passa:stringtosubstitute? – bdesham Apr 09 '15 at 15:03Chomp()is passing whatever arguments it gets on tosystem(), stripping the trailing newline from its output, and returning that. – jamessan Apr 09 '15 at 15:22system()has an optional{input}argument, and this handles any of these generically. If you don't need this, just do it the conventional way. – Ingo Karkat Apr 09 '15 at 16:12\n\+$with\d*\n\+$, any trailing digits will be removed as well. However, I probably would not combine that very application-specific cutting with the generic removal of the trailing newline, and rather do a secondsubstitute(l:result, '\d*$', '', '')after receiving the chompedl:result, to have cleaner code. – Ingo Karkat Dec 01 '20 at 17:43