I'm trying to get vim to execute the script I'm editing with a key mapping, say ctrl + x, so I used this in vimrc
:map <C-x> :!exec_file %<CR>
To pass the file name to a script I wrote which parses the extension and calls the appropriate interpreter, this works great so far.
However, I was wondering if I can call bash
directly with the script name and have it execute it since most scripts I edit have a shebang line, so I tried this mapping instead:
:map <C-x> :!bash %<CR>
But it doesn't work, is it possible to execute a script by passing its name to bash ?
:!%
suffice?exec_file
does, but without having to rely on the extension. Maybe use this only as a fallback when there's no shebang line. FWIW, shebang lines generally only make sense when you want to make a script executable, as calling interpreters will file arguments always works.map <f4> :!%:p<cr>
.:p
will expand to the full path of the script.