简体   繁体   中英

Vim: split specific filetype by default

When editing Git commits in Vim, I'd like to automatically split the window on open so that I can edit the commit message in the top pane while keeping the commit change list in the bottom panel.

I have the ftplugin with a gitcommit.vim file for setting some other Git-commit-specific options, but when I add split to it, I get 3 panes (presumably because the second pane also splits, and then something prevents further recursion into infinity?).

I'd also like it to switch to the second panel and move the line that says # Changes to be committed: to the top of the buffer for when I am doing commit-amends and the message is already long. Then, I'd like it to move back to the top buffer. I know what to type to do that, but I'd like it to happen automatically, if possible.

Here is a command to put in your ~/.vim/ftplugin/gitcommit.vim file:

command! -buffer -nargs=0 Changes :execute "normal! \<c-w>s\<c-w>jgg"<bar>call search('^# Changes')<bar>execute "normal! zt\<c-w>p"

This provides :Changes command which does what you want. I hesitate to have it fire off immediately as for most commits I doubt you will need this functionality.

I also agree with @mMontu that you should check out Fugitive as well as this Vimcasts post: The Fugitive Series - a retrospective .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM