If I have a file with a shebang line (e.g. #!/bin/bash
) open in Vim and the file has execute permissions (i.e. chmod +x
) I know I can type this to exec
If you haven't set permissions you can run:
:! sh %
When starting vi, specify file path explicitly, like this "vi ./blablabla"
vi ./yourscript.pl
After that start at anytime with only :!%
The other variant is to invoke the vi command like this
!./%
:!%:p
,without the spaces, is shorter.
If you want an even shorter shortcut, you can create a custom mapping:
nnoremap <F9> :!%:p
or the more "mnemonic":
nnoremap <leader>r :!%:p
None of the previous answers work if your filename/directory path has spaces in it. Simple fix.
:!"%:p"
After you've executed that once, a short :!!
will repeat it.
You can add a key mapping to your .vimrc
map <F5> :!%