0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Vim—現在開いているカレントファイルを直接実行する

Last updated at Posted at 2018-08-19

やりたいこと

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オープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?