In my .vimrc
I have the following, which in Vim Visual mode inserts an unique alphanumeric string.
vnoremap <leader>u :!pwgen -A 8 1<CR>
For convenience, I want to do the same thing in Vim Insert mode: something like this (not working: .vimrc
):
iabbrev uuid `pwgen -A 8 1`
where the abbreviation uuid
(or :uid:
or similar) triggers the BASH pwgen
command (e.g replacing uuid
with moh6sei5
).
Edit
Per the comment immediately following mentioning Defining linux command inside vim abbreviations
the issue is that strtime
(there) is a native Vim function (:h strftime
), whereas pwgen
is a BASH function. In .vimrc
:
works:
iabbrev xxx <C-r>=strftime('%c')<CR> " Sun 02 Oct 2022 11:03:58 AM PDT
does not work:
iabbrev uidd <C-r>=pwgen -A 8 1<CR> iabbrev uidd <C-r>=!pwgen -A 8 1<CR> iabbrev uidd <C-r>=`pwgen -A 8 1`<CR> ...