I want to :retab selection in my vimscript function.

When I write execute "normal! :'<,'>retab" nothing happens.

If I write:

let cmd = "normal! :'<,'>retab"
echom cmd

The output is what I would expect: normal! :<a:firstline>,<a:lastline>retab

If I do this however...

let cmd = "normal! :'<,'>retab"
echom cmd
execute cmd

The output is empty...

I eventually used the feedkeys function, to simulate what I wanted to achieve. Just for the completion sake, it's call feedkeys(":'<,'>retab\<CR>", 'n').

I narrowed the problem down to the fact, that : character is in the command, but it's quite weird... Is this prohibited in vimscript?

1 Answer 1


You're missing a final <CR> at the end of your normal command. If at the end of normal you have an incomplete command, it will cancel it as if <Esc> or <C-c> was pressed.

So this should fix it:

execute "normal! :'<,'>retab\<CR>"

(Using \r inside the double quotes is also possible.)

But in this case, there's probably no need to use normal or execute, since retab itself is already an Ex command, so you can simply use this directly:


That's a perfectly valid command in Vimscript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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