I have the following configuration in my .vimrc file to switch between a .c File and it's corresponding .h File

function SwitchHeader()
        e %:r.c

When i enter :call SwitchHeader() into the vim command line The message appears Bestätigen sie die EINGABETASTE oder geben sie einen Befehl ein which i would translate to Hit the enter key or enter a command

How can i avoid having to press enter every time i call the function, when i bind key i can use <cr> at the end of the line to insert an Enter, but how can do this in the function.

  • I copied your function to a file, ~/enter.vim, created three files, enter.cpp, 'enter.c` and enter.h, and executed vim -N -u NONE --cmd 'filetype on' -c 'so ~/enter.vim' enter.cpp. Then executing :call SwitchHeader() switches between those files, but there is no "Hit Enter" message. So I don't see the problem. You might take a look at :help hit-enter-prompt and see if that provides a clue.
    – garyjohn
    Feb 18, 2015 at 17:54
  • Prefix your :write and :edit commands with :silent.
    – Heptite
    Feb 18, 2015 at 18:20
  • Sorry, i don't know where to put the :silent, cut you explain that further or provide and example? Feb 18, 2015 at 18:44
  • Looks like you already have a solution, but for future reference, :silent just prefixes normal :-commands, e.g.: :silent :write, :silent :edit ..., etc.
    – Heptite
    Feb 18, 2015 at 22:18

4 Answers 4



execute ':edit ' . expand('%:r') . '.EXT'

(Note: replace .EXT by whatever you want it to be in each branch)

Also: have a look at http://www.vim.org/scripts/script.php?script_id=31

  • Ok, this solution works, but strangly only if i substitute both edit command in the if block, but it works. Feb 18, 2015 at 19:19

For everyone having the same problem: i found this vim plugin http://www.vim.org/scripts/script.php?script_id=31 which seems to have more options, like splitting the pane and so. I didn't try it, but you might give it a try.

  • "i found" is a bit ... strange. i posted it 1 hour ago :)
    – akira
    Feb 18, 2015 at 19:28
  • Ohh, sorry, your answer worked for me so i didn't follow the link and didn't realize that you posted the same link Feb 18, 2015 at 19:42

In 'quick-and-dirty' scripts, the solution is often to insert the literal character into the file. In this case you would type control+v followed by the return key, to insert a character looks like an ^L but you can tell it isn't caret-ell because the cursor moves across it as one character.

Characters entered into the file this way do not tend to survive copy-and-paste, and various other means of transmission, however, they can get the job done. Sometimes it is even necessary to wrap them in a call to execute normal. For example:

execute 'normal (...commands that might generate enter prompt...)^L'

Try :set cmdheight=2

From :help messages

To reduce the number of hit-enter prompts:  
- Set 'cmdheight' to 2 or higher.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .