Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

function! MyFunction()
  if condition
    <C-W><C-W>
  else
    :some_other_command
  endif
endfunction

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

What can I use instead?

share|improve this question

1 Answer 1

up vote 10 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

 
discard

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.