Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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've just created a Vim function to replace Windows linebreaks with Unix ones. Now I want to be able to type :linebreak and have it run. Here's my first attempt:

function UseUnixLineBreaks()

cmap linebreak :call UseUnixLineBreaks()<CR>

(By the way, that ^M is a control character - type it with Ctrl+v Ctrl+m)

When I try to run this by typing :linebreak, it does run, but it behaves oddly: each letter of the command appears in sequence, erasing the previous one. For example, I see :l, then :i, then :n, etc. When I type the last letter, it runs immediately.

I want the whole command to appear, so that I can see I've typed it correctly, then press enter to run it.

How can I do this?

share|improve this question
up vote 5 down vote accepted

Figured it out

Apparently what I want is not a mapping at all, but a command. So, the last line should be replaced with:

command Linebreak call UseUnixLineBreaks()

Note the capital "L" - user-defined commands must begin with a capital letter. See :help command.

share|improve this answer

That's how mappings work: the replacement takes place after the entire mapping is entered.

To create command aliases, try the cmdalias.vim script.

On a related note, :setl ff=unix.

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.