Vim Tip #26: Command Line (ex Mode) History


tags: Vim

Vim Tips

You should understand a little about ex Mode before you start looking at this tip. If you use Vim at all, you use ex Mode: every time you type a colon command (:w or :1,5s...) you're using ex Mode. Here's your tip: Vim remembers the history of all the commands you've used in that mode. If you've typed : and then hit up-arrow, you've used that history. But it's a lot more powerful than that. The next simplest use of that history is to type a partial command like :tabnew and then hit the up-arrow: in this case, Vim will only show you previous history lines that started with "tabnew". But there's more! And this is where this gets really entertaining (and powerful). In Normal mode, type q: and you'll find your window split, with the new buffer containing your command line history. This is pretty much a regular buffer. Stop and think about that - I mean, really think about it. You can search it. You can edit it. And not only can you edit one line (and then hit <Return> in Normal Mode to execute that command in its new edited form), you can copy-paste and/or combine lines in any way you see fit before executing them.