vim - execute - shell command?

I want to add a mapping which will visualize the output of a shell command in a new window. the problem is the command is interrupted when moving the cursor to the top of the file.

:execute ":new \| set nonu \| 0r ! ls \| normal! gg"

I figured out that the problem is with the execute command which considers the part from the symbol ! to the rest of it as a shell command (ls | normal! gg) and that's why it shows an error when being executed.

How to prevent that ?

Upvotes: 0

Views: 403

Answers (2)

FDinoff
FDinoff

Reputation: 31469

When a command doesn't accept <bar> to separate the command. The normal way to fix this is wrap the command in a execute which does except bars

:execute ":new \| set nonu \| execute '0r ! ls' \| normal! gg"

Upvotes: 2

1sloc
1sloc

Reputation: 1180

I'm not sure you can pull that off with :execute. But you can use Clam (e.g. :Clam ls) as a basis and edit plugin/clam.vim in order to fire a gg after execution of the shell command.

Upvotes: 0

Related Questions