Somewhat workaround if you have recent vim with <cmd>
support:
cnoremap <C-u> <cmd>let g:CCtrlU = strpart(getcmdline(),0,getcmdpos()-1)<CR><C-u>
cnoremap <C-y> <C-r>=get(g:, "CCtrlU", "")<CR><cmd>let g:CCtrlU = ''<CR>
With <cmd>
it is possible to run arbitrary vimscript without changing modes,
so here with
<C-u>
part of the cmdline is saved from beginning to the cursor pos, then original <C-u>
deletes what it should.
<C-y>
uses expression register =
to output saved cmdline (g:CCtrlU
is in safe form, checking existence with default value ""
) and then cleans up variable that holds saved cmdline.
PS, alternatively if you don't mind <C-u>
to cut text into unnamed register, it could be simplified to:
cnoremap <C-u> <cmd>let @" = strpart(getcmdline(),0,getcmdpos()-1)<CR><C-u>
cnoremap <C-y> <C-r>"
PPS, and if you don't have <cmd>
in your vim you could try this with <expr>
and additional func:
func! CCtrlU() abort
let @" = strpart(getcmdline(),0,getcmdpos()-1)
return "\<C-u>"
endfunc
cnoremap <expr> <C-u> CCtrlU()
cnoremap <C-y> <C-r>"
<c-u>
can be done with:h CmdlineChanged
and:h getcmdline()
but modifying the command line with a mapping is the non trivial part.