tags:

views:

129

answers:

4

I've been trying to find something that will let me run multiple commands on the same line in vim, akin to using semicolons to separate commands in *nix systems or & in windows. Is there a way to do this?

+6  A: 

The command seperator in vim is |.

Daenyth
+13  A: 

A bar | will allow you to do this. From :help bar

'|' can be used to separate commands, so you can give multiple commands in one line. If you want to use '|' in an argument, precede it with '\'.

Example:

:echo "hello" | echo "goodbye"

Output:

hello
goodbye
michaelmichael
Just watch out for the handful of commands that don't work with `|`!
too much php
When you find yourself wanting to use multiple commands in a `map` statement (and believe me, you will), check out `:help map_bar`.
Bill Odom
That's true. I asked that very question on superuser a few months ago. My `.vimrc` doesn't support an escaped bar (`\|`) for mappings. I learned I have to actually type out `<bar>`.
michaelmichael
A: 

I've always used ^J -- to enter one: CTRL-V-CTRL-J

eruciform
A: 

You could define a function that executes your commands.

function Func()
     :command
     :command2 
endfunction

And place this in, for example, your vimrc. Run the function with

exec Func()
fulhack