Reputation: 33
I'm still learning vim and during my vimtutor session I wrote :!ls
but it couldn't be found. I've also tried :sh
which works fine but I can't figure out why using the bang symbol wouldn't
edit: I was wrong. ':sh' brings up the shell but ls and pwd still don't work with that instance of the shell
edit2: I've been using Powershell and realize now that ls
and pwd
are not commands available to cmd. I added
set shell=powershell.exe
set shellcmdflag=-c
set shellpipe=>
set shellredir=>
into _vimrc gleamed from this question: Vim with Powershell
Upvotes: 0
Views: 1697
Reputation: 172590
You're confusing the "bang" added to commands like :w!
and the separate :!
command, which passes the remainder to the shell. (Also, many built-in commands like :ls
and :pwd
are named by common shell commands found on Unix / Linux.)
If you're on Windows, you simply don't have those common Linux commands like ls
and pwd
. (The equivalents would be dir
and echo %CD%
, resp.)
If you install a Unix emulation layer like the one provided by Cygwin or the GNU Win32 project, you'll get corresponding binaries (ls.exe
) and can then invoke then (or even reconfigure Vim's 'shell'
option to use such shell).
Upvotes: 2
Reputation: 80931
:!
in vim runs the given command through the 'shell'
.
On Windows this is cmd.exe
. ls
is not a valid command on Windows. As such :!ls
will not work on Windows.
:!dir
, on the other hand, will.
Upvotes: 1