LoginSignup
0
0

More than 5 years have passed since last update.

vaffle.vim 上でも簡単にカレントディレクトリを移動したい

Posted at

動機

上記URLに記載の方法で、vaffle.vim上でもカレントディレクトリを移動させたいなーと思いました。

経緯

vaffle上で上記スクリプトを実行すると、エラーになる。%:p:h のプレフィックスがvaffle://になっているのが原因のよう?

結果

ファイルタイプをチェックして、vaffleを認識して、vaffleの関数で'%:p'のプレフィックスを取り除いてもらって、lcdを実行すればイケました。

command! -nargs=? -complete=dir -bang CD call s:ChangeCurrentDir('<args>', '<bang>')
function! s:ChangeCurrentDir(directory, bang)
    if &filetype ==# 'vaffle'
        " ファイルタイプをチェックしてvaffleを認識。
        " プレフィックスをvaffleの関数で取り除いてもらってlcd実行
        execute 'lcd ' . vaffle#buffer#extract_path_from_bufname(expand('%:p'))
    else
        if a:directory == ''
            lcd %:p:h
        else
            execute 'lcd' . a:directory
        endif
    endif

    if a:bang == ''
        pwd
    endif
endfunction

でも...

vaffle.vim には元々 g:vaffle_auto_cd なる便利設定があることを、このポストを書いている途中で気付きました。この設定は vaffle上でautocdを実現するもので、手動でcdしなくても、自動でやってくれるという優れもの。私のユースケースではこれで十分でした。チャン♪チャン♪

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