Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a function, and I want to execute a key command, but I get the error Trailing characters:

function! MyFunction()
  if condition

It doesn't like the <C-W><C-W>

What can I use instead?

share|improve this question
up vote 13 down vote accepted

The general answer is to use the :normal command, like

:exe "normal \<C-W>\<C-w>"

The :execute approach is the readable way to get :normal to recognize special characters like control-key combinations. The other approach is

:normal ^W^W

where each^W is one character inserted by typing Ctrl-vCtrl-w.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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