Reputation: 7466
I have troubles consolidating this shell command:
uuidgen | tr -d '\n' | awk '{printf("\"%s\"", $0);}'
into Vimscript like this:
:command UUID execute "normal! \"=system('...')\<CR>p"
My current attempt is:
:command UUID execute "normal! \"=system('uuidgen | tr -d \'\n\' | awk \'{printf(\"\"%s\"\", $0);}\'')\<CR>p"
Which returns Unknown mark
when I run the command. I assume I ended up in escaping hell and don't know how to recover.
Upvotes: 1
Views: 207
Reputation: 825
escaping hell... ;-]
escape('uuidgen | tr -d ''\n'' | awk ''{printf("\"%s\"", $0);}'')','\\/.*$^~[]')
Note double single quotes in first part. Second part is universal snippet for escaping.
escape('string','\\/.*$^~[]')
From here it should by easy
Upvotes: 0
Reputation: 45087
I feel like this can be done simpler with systemlist()
command! UUID put='\"'.systemlist('uuidgen')[0].'\"'
nnoremap <key> "='"'.systemlist('uuidgen')[0].'"'<cr>p
inoremap <key> <c-r>='"'.systemlist('uuidgen')[0].'"'<cr>
If you didn't mind '
then you can use the string()
function which would be even easier.
For more help see:
:h systemlist()
:h string()
Upvotes: 2