Rewrite a Vim function to a one-line map

configurationvim

This works:

nmap <silent> <S-t> :call InventTab()<CR>
function InventTab()
    set expandtab!
    if &expandtab
        retab
        echo 'spaces'
    else
        retab!
        echo 'tabs'
    endif
endfunction

I've tried to change it to a one-liner:

nmap <silent> <S-t> :set expandtab!<CR>:if &expandtab<CR>:retab<CR>:echo 'spaces'<CR>:else<CR>:retab!<CR>:echo 'tabs'<CR>:endif<CR>

The problem now is that it it insists on printing "Press ENTER or type command to continue" afterwards. If I add another <CR> it doesn't do that anymore, but then the echo output is cleared.

How should I write this to make sure I see the output but no extra stuff?

Result (see the accepted answer for details):

nmap <silent> <S-t> :set expandtab! ^V| if &expandtab ^V| retab ^V| echo 'spaces' ^V| else ^V| retab! ^V| echo 'tabs' ^V| endif<CR>

Best Answer

Does replacing the <CR>'s you have between commands with ^V| (where ^V is a literal ^V inserted by typing Ctrl-vCtrl-v) work?

Related Question