Vim swp files interfere with repository vimdiff

ぃ、小莉子 提交于 2019-12-06 04:04:54

Yes, (maybe), and yes.

To turn off swap files:

set nobackup
set nowritebackup
set noswapfile

To change location of swap files (my preferred choice):

" Set the directory of the swap file
" The // indicates that the swap name should be globally unique
set directory=~/.vim/tmp//,/tmp

Here I set it up in a tmp directory under .vim. See :h 'directory' to find out what each part of the option represents.

As for getting Vimdiff to ignore the swap files, I'm not quite sure. But the error is probably occurring because when you're checking the diffs with Mercurial, you have the same files already open in MacVim. If you just close the files before performing the diff, then you should be fine.

I would suggest a different approach: instead of using mercurial command-line interface to view differences between files, use one of vim plugins that adds VCS support, in this case you will neither need to close anything nor do something with swap file.

For example, with my aurum you may use <leader>aD (mapped to :AuVimDiff) to view differences between currently opened buffer and its version in repository and then <Leader>X to switch back to normal view (if you have not edited anything it will even restore opened/closed folds). If you do let g:aurum_vimdiffusewin=1 and use vertical or horizontal (depending on 'diffopt') equally sized splits then my script will reuse one of adjacent windows.

With <leader>agD you can view all changes to all files in repository in a multiple tabs in a vimdiff split (excluding added and removed files): it is mapped to :AuVimDiff full. As far as I know this functionality is almost unique: there is some script for mercurial which does the same job, but it is not integrated with other VCS plugins. Again, <leader>X to close all tabs. Buffers which were already open won’t get closed, others will.

Another plugin which I may recommend is VCSCommand.

I know this question is more than a year old now, but might I recommend lawrencium, a plugin integrating mercurial into vim, inspired by the fantastic fugitive plugin for git. They make what you're doing (and a lot of other CVS things) much easier with a few simple commands. They didn't pay me to say this; the plugins are just really good!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!