LoginSignup
36

More than 5 years have passed since last update.

vimで現在開いているファイルのコピー,リネーム,削除をする

Last updated at Posted at 2016-08-05

vim上でのリネーム方法が思った以上にシンプルなコマンドだったのでメモ
ついでにコピーと削除の方法も記載

リネーム

:f [変更後ファイル名]|call delete(expand('#'))

実行後、「:w」して保存しておかないとファイルが消えるので注意

コピー

:w [コピーファイル名]または :f [コピーファイル名]

前者がコピー元、後者がコピー先のファイルを実行後に表示

削除

:call delete(expand('%'))

あわせて知っておきたい

ファイルをコピー,リネームする場合は現在開いているファイルのパス情報を利用することが多いのでそれの取得方法をメモ

/home/hoge/workspacetmp.txtを開いている状態とする

記号 意味
% カレントファイル ./tmp.txt
%:p フルパス /home/hoge/workspace/tmp.txt
%:h カレントディレクトリ ./
%:t ファイル名 tmp.txt
%:r 拡張子除去 ./tmp
%:e 拡張子のみ txt

p,h,t,r,eは変換子で組み合わせ可
%:p:h -> /home/hoge/workspace

例)バックアップファイルを作成する

:w %.bk

参考サイト

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
36