External commands on Windows
From Vim Tips Wiki
Tip 1504 Previous Next Created: February 6, 2007 Complexity: basic Author: Tim Keating Version: n/a
If you want to execute an external command on Windows, you need to know one trick. Let's say you're building a command to check out the file you're working on (using Perforce as an example):
map <F6> :!p4 edit %
However, that will just populate the command line. To force the command to execute without having to hit Enter, you need to embed a CR (carriage return). On Linux, you do this with Ctrl+V Ctrl+M. On Windows, the default is that Ctrl+V is paste, and you have to use Ctrl+Q instead:
map <F6> :!p4 edit %Ctrl+Q Ctrl+M
Which will look like:
map <F6> :!p4 edit %^M
[edit] Comments
TO DO
Fix the above tip to incorporate the good sense in the following comment (use "<CR>" rather than trying to embed an 0x0d byte). The old method of embedding ^M should be mentioned.
Furthermore, there is no reason for this to be a Windows only tip. Linux beginners would need to know to embed CR also, and should learn that "<CR>" is almost always the best procedure.
You could use <CR> (4 characters), which should work when your 'cpo' does not have < included. See
Even with < in 'cpo', you would be able to enter a mapping this way – you need to use <special> modifier. See
One more thing: Ctrl-V is mapped only when your _vimrc contains the following line:
source $VIMRUNTIME/mswin.vim
You can use :sil[ent][!] {command} to execute external commands silently on Windows.
To execute my Python scripts I use:
map <F5> <Esc>:!python %<CR>
