LoginSignup
0

More than 5 years have passed since last update.

posted at

updated at

VimでEmacsのFind Alternate fileを実現

これは何か?

開くファイルを間違えた時に、正しいファイルで開き直すための機能が、どうやら Vim には無いようです。

Emacs から Vimに乗り換えて一週間、Vim script を勉強しつつ書いてみました。

ソース

command! -nargs=1 -complete=file FindAlternateFile call <sid>Hykw_findAlternateFile(<q-args>)

function! Hykw_findAlternateFile(file)
  let current_bufferNumber = bufnr('%')
  execute "edit " . a:file
  execute "bdelete " . current_bufferNumber
endfunction

使い方

.vim の適当な所にソースを貼り付ければOKです。あとはファイルを間違えて開いた時に

:FindAlternateFile 開き直すファイル名

で呼び出します。ちなみにTabでディレクトリ/ファイル名の補完も効きます。

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
What you can do with signing up
0