4

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>
3

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

  • It still runs, but no echo output... – l0b0 Aug 4 '11 at 13:37
  • Strange it works for me when I have nmap <silent> <S-t> :set expandtab! ^V| if &expandtab ^V| retab ^V| echo 'spaces' ^V| else ^V| retab! ^V| echo 'tabs' ^V| endif<CR>. Maybe try it without any plugins loaded and see if anything changes? – jw013 Aug 4 '11 at 13:49
  • That works for me as well - I understood "between commands" as "between retab and echo". Excellent! – l0b0 Aug 4 '11 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.