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?
views:
129answers:
4
+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
2010-07-14 18:40:09
Just watch out for the handful of commands that don't work with `|`!
too much php
2010-07-14 22:53:35
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
2010-07-14 23:36:31
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
2010-07-15 15:23:11
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
2010-07-16 16:05:18