I have a ~/.vimrc that contains just this:

function! NewFile()
        let filename = input("Filename:")
command NewFile :call NewFile()<cr>

(of course my real .vimrc is more complex, but I've recreated this small test case with no plugins etc.)

My intent is to write a function that supports creating a new file according to a template. Some input items will be asked from the vi user, such as the name of the file.

The function isn't that sophisticated yet (understatement!) - all it does is ask for the filename. When I use the command NewFile from the vi command line, it starts, but then once I enter the filename and hit Enter, I get the error:

E488: Trailing characters

Why is that? What am I doing wrong?

1 Answer 1


Remove the trailing <cr> That is only needed for mappings, but not for commands.

  • 2
    Ah, perfect, thank you! I had copied this incantation from a mapping - a bit too closely, it seems. Thanks. Commented Sep 9, 2015 at 15:29
  • 2
    You solved me a problem with same error message with a different context. Thank you ^_^
    – sensorario
    Commented Jan 13, 2017 at 13:55
  • The vim trailing characters command is as meaningful as "E488: blah blah raspberries! - incontempintasmationable epehlsastianitionate wibble, perhaps. But you should not rely on this. It is advised that you seek professional help"
    – markling
    Commented Dec 5, 2021 at 17:46

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.