LoginSignup
1
0

More than 5 years have passed since last update.

vimで開いているファイルのgitでのtop階層をカレントにする方法

Last updated at Posted at 2017-03-29

TOP階層の取得方法

git rev-parse --show-toplevel

コマンド

vim
nnoremap <leader>cg :<C-u>cd %:h\|cd `git rev-parse --show-toplevel`|"

\cg<CR>で移動することを想定しています。
コマンドの最後に<CR>を書いていないのは、毎回コマンドが見れるからです。
最後の|"は、後ろに変な文字があったら大変なので書いています。
一回cd %:hしているのは、ファイル指定でTOP階層を取得する方法がわからなかったからです。

プラグイン

tpope/vim-fugitiveを導入している場合は、:Gcdでカレントにできます。

詳しくは:h gcd

1
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
1
0