vim creates temporary files in the current working directory - vim

I normally setup my backup directory in my vimrc as follows.
set backupdir=~/vimtmp,/tmp,.
set directory=~/vimtmp,/tmp,.
This works as all the *.*~ goes to the vimtmp folder.
However, certain plugins such as NERDTree, Tagbar create their temporary files in my current working directory. For instance, following files are created when these plugins are started.
[[buffergator-buffers]]
__Tagbar__
NERD_tree_3
This is really annoying issue because when I work with a version control system, these files are being created in some folders and I sometimes push them to the central repo accidentally.
Could you please suggest me some tips to handle this problem? For instance, how can I set current working directory specifically for the plugins so that they will use that directory for their temporary files.
Thank you very much.

After reviewing my own vimrc file, I found that following auto command is causing the problem. I was using this command to automatically save a file when I have created it. However, the side effect of this command was that it saves all buffers (even NERDTree, TagBar etc.) as well. Therefore, it was cluttering my working directory. So, by disabling the following command, I solved the problem.
" evil command
" autocmd BufNewFile * :write

Related

:vsplit autocomplete not working with /django/ directory in VIM

Normally if I type :vsplit /path/to/some/directoryTab, the available directories will autocomplete.
After doing a reinstall of VIM, there is one directory that now will not allow autocomplete, and I can't figure out why. The directory is ~/Sites/django/. Once I type ~/Sites/, Tab will show me drupal and apps directories, but will not show django. If my working directory is inside this django directory, :vsplit won't let me autocomplete either.
I did a ls -haltr on the directory and it looks the same as the others inside the ~/Sites/ directory.
Also, when I use the CtrlP plugin inside this directory, I get the error "==NO ENTRIES==". In other places, CtrlP works fine.
Why might this be happening and how can I fix it?
The directory is getting ignored because it has /django/ in it's path...which was set by my Python linter. The linter causes Vim to ignore /*django*/. To see this, use set wildignore to see what directories are getting ignored.
I just changed the directory to /dj/ and it works fine.
I could have also changed the wildignore directories by using set wig-=my_directory command.

How to make vim javacomplete to work?

I confess that I am a beginner in using vim and this question might be as dumb as it sounds. These are what I've done so far :
I downloaded the latest zip file format of the script from here.
I unzipped it to the .vim directory that placed the files javacomplete.vim, java_parser.vim and Reflection.java inside the ~/.vim/autoload directory by default.
The following option is set (much better, I've added it to my .vimrc file):
:setlocal omnifunc=javacomplete#Complete
java and javac are set properly in the system path variable (they work from the command line).
Assuming that that's all I need to do, pressing <C-x><C-o> (in the insert mode) doesn't do any auto-completion inside a .java file.
What am I doing wrong here?
If you're using Vim 7.2, there's a few issues related to how the plugin locates the java-based Reflection helper.
If you have .class listed in your wildignore or suffixes, then it can't actually locate the class file to execute.
I have a clone that I modified to get around that on github : https://github.com/cilquirm/javacomplete
Give that a go and see if it works for you

Plugins in gVim not working

I need help in installing some of the popular plugins in Vim. I just started learning this editor and is very excited to use the popular plugins. I'm using gVim in Windows XP and have extracted the .vim files and copied them to the Program Files folder of Vim.
Inside my "F:\Program Files\Vim" folder, there are exactly two folders the "vim73" and the "vimfiles" folder. I put the .vim files (EasyMotion.vim) into the "plugin" folder inside the "vimfiles" folder.
When I run gVim, the plugins doesn't work, and in my case, the EasyMotion plugin is not working. I typed the "/w" to make the EasyMotion plugin work (as stated on its usage on its github account) and nothing seems to work.
Am I missing out something here? Are there extra commands to put in the vimrc file to recognize those plugins?
Cheers!
Never touch Program Files. There is a vim setting called 'runtimepath' (see the :help 'rtp') that says where Vim is going to locate the plugins. For each directory in the runtimepath, Vim will source every .vim file found in the plugin subfolder, and lookup for functions containing # in their names in the .vim files of the autoload folder. It will also lookup filetype plugins in the ftplugin folder when 'ft' is set.
Normally you should have %HOMEPATH%\Vim\vimfiles in your runtimepath (:echo &rtp to know). Unzip Easymotion there, NOT in Program Files.
Due to that structure, vim plugins mix up in the same 2-3 folders. However it is possible to install every plugin in its own subfolder if you play with runtimepath. The pathogen plugin is dedicated to that. It makes it possible to have every plugin in its own subfolder, and adds every plugin root folder to the runtimepath. The Readme is self-explanatory.
As #benoit said, you should never in general put files into your vim73 folder
(notable exceptions exist, but you'll know when you encounter them).
On windows, Vim searches for configuration files (those include _vimrc and your
plugins) in several directories, in a certain order. First it will look in
$HOME ... which is your c:\documents and settings\username\ folder
$VIM ... which is the folder where you installed or extracted Vim
$VIMRUNTIME ... which is your \vim73 folder ...
and so on ...
What this means? It means it will first look in $HOME before looking in let's
say, your Vim install folder. So it is a nice way of separating plugins which
you just want to test out before being sure you're gonna be keeping them.
For example, you could organize your Vim related files in this manner:
- install vim to c:\vim or c:\program files\vim\
(vim's program files will go in \...\vim\vim73\)
- put your _vimrc in \vim\
- put your vimfiles in \vim\vimfiles\
- and put your temporary vimfiles in c:\documents and settings\username\vimfiles\
That way when you're done with them, you can just delete that last
\username\vimfiles\ folder.

When open vim, search a file down a tree structure and execute it if exists

I am new at using vim daily. I am doing my best to setup an good environment. I work a lot with Django projects. And I want to simulate a project like setup when I edit a file inside a django project.
Let's asume this directory structure:
/projects
/django-app1
manage.py
settings.py
.project
/django-app1
manage.py
settings.py
.project
What I want is place a file called .project that contains vim commands that will execute if I open any file whitin the directory structure
Why? Here is my vimrc https://github.com/mariocesar/dotfiles/blob/master/.vimrc#L151 you can see that I am using a snippet to load the virtualenv if it's exist on the enviroment variables, it's very cool but I don't think is efficient to do that every time I open a file, or even better add some extra paths to sys.path, as I have projects with a site-packages directories.
So:
How Can I detect a specific named file, looking down the current directory when open a file with vim?
How Can I execute this file as a vim script?
There exist several plugins named local_vimrc that fulfil your need. Here is mine.
BTW, your question is a duplicate of Vim: apply settings on files in directory
EDIT: Recent implementations of local_vimrc plugins use vim7 capabilities. Somehow, this is equivalent to:
source <c-r>=findfile('.local_vimrc',expand('<afile>').';')<cr>
(thanks sehe for reminding me of ';')
"Somehow", because, many important features are missing:
the possibility to source all files found, in the downward order.
the optional specification of a root directory pattern (like '$HOME\|/opt/projects/ for instance)
external paths like scp://, ftp://, http:// must be handled correctly (I haven't tested how they'd behave with findfile())
it should be possible to force the execution of the local vimrc(s) before a template-expander plugin triggers the expansion of a templare-file (the typical application is the generation of header-gates in C/C++ .h files)
Hence my preference for the full plugin way, and not just a one-liner that will irritate us from time to time.
NB: my plugin is very old, it's pre-vim7. As it works (recursively), I've never feel the need to rewrite it with the modern vim7 list manipulations functions.
When starting vim
I think
vim +'source **/.project'
should do the trick nicely.
If you have a recent bash, you could also more directly
vim -S **/.project
When loading a python file
To act when opening/loading a certain file:
autocmd BufReadPost *.py source %:h/**/.project
Loads any .project file found in the subtree containing the file being opened
autocmd BufReadPost *.py source %:h/.project
Loads any .project file found in precisely the same directory containing the file being opened
To remove the above auto commands (remember: adding the same command twice will execute them twice)
autocmd! BufReadPost *.py

Moving vimfiles location breaks snipmate.vim?

I'm working on moving my whole vim config to my Dropbox folder in order share it between machines more effectively. To do this, I've changed my .vimrc to the following:
set runtimepath+=$HOME/My\ Documents/Dropbox/vim
source $HOME\My Documents\Dropbox\vim\vimrc.vim
vimrc.vim looks like this:
set nocompatible
filetype on
filetype plugin on
filetype indent on
syntax enable
The problem is then that snipMate.vim no longer works. I know that there aren't any plugins interfering with it, as I've done a fresh install of vim and removed all the other plugins. It worked perfectly before I moved the plugins to the dropbox folder. I think it may have something to do with the fact that the after directory in vimfiles doesn't seem to be getting read once I move the plugin folder to the dropbox (i.e. after/snipmate.vim only shows up in :scriptnames when I have vimfiles as the plugin folder). I've tried explicitly sourcing the script in the after directory by adding the following to my .vimrc:
source $HOME\My Documents\Dropbox\vim\after\plugin\snipMate.vim
but snipmate still doesn't work.
Any ideas on fixing this?
You have to add the after directory to 'runtimepath' if you want Vim to look for it.
set runtimepath^=$HOME/My\ Documents/Dropbox/vim
set runtimepath+=$HOME/My\ Documents/Dropbox/vim/after
This follows the normal behavior of having your personal vim directory sourced first, then the system-wide stuff, and finally your personal after directory.

Resources