やりたいこと
Vimの中から現在開いているスクリプトを直接実行したい。
Vimの例
Vimで実行権限のあるファイルを開いてから
vim ./example.sh
コマンド入力
:! %:p
でOK
Vim じゃない例
こんな感じ。
echo '#/bin/sh' > ./example.sh
echo 'echo ok' >> ./example.sh
chmod +x ./example.sh
./example.sh
ok
結果
$ vim ./example.sh
ok
コマンドの意味
-
:
-コマンドモードの開始
-
!
-外部コマンドを実行する
-
%:p
-カレントファイルのフルパス
ショートカットをマッピングする例
~/.vimrc
を編集する
F5キーにマップする場合
map <F5> :! %:p
Enterも打ちたくない場合
map <F5> :! %:p<Cr>
Links
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。