vim: change pwd while working with cscope - vim

I'm currently working on project using vim+cscope.
Sometimes, to make some code-exploring tasks easier I use :cd command to navigate to a specific folder withing the project. But then, if i want to issue some cscope command such as Ctrl-] or :cscope find it won't work before i change back to my project's root directory. I understand that's because cscope just tries to open the path as it is written in the cscope_db file without any sophistication.
So how do i make cscope "remember" my project's root directory so wherever i am it will always know to open the right path?

Apparently :set csre did that for me:
basename of cscope.out location (usually the project root directory) will be used as the prefix to construct an absolute path.
Due to some misconfiguration I missed it.

Related

How to search from the root of project - Ag / VIM

I did add let g:ag_working_path_mode="r" to my .vimrc but it doesn't work when I tried to search for example :Ag! jquery in /vagrant/my_prj/app/Controller/MyController.php [Git(master)] and I get No matches for "jquery"
But if searched :Ag! jquery /vagrant/my_prj I get around 800 results.
I do have .git folder in /vagrant/my_prj/ folder.
If you want vim to always cd to the project's root directory, you could use the plugin called rooter: "Rooter changes the working directory to the project root when you open a file or directory."
see: https://github.com/airblade/vim-rooter

: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 keep previous directory in CtrlP?

Using the CtrlP plugin, I'm typing .. several times to get to the root directory of a project, then perform the search from there.
However after I reopen CtrlP it still searches in the directory of the current file.
How can I get it to stick to the directory that I originaly set ?
By reading its documentation, of course.
If you want CtrlP to always open in your project's root directory, if applicable, just add this line to your ~/.vimrc:
let g:ctrlp_working_path_mode=2
But you could also use both :CtrlP to browse in the current directory and :CtrlpRoot to browse in the root of your project.
Or simply use :CtrlPLastMode to launch CtrlP in… the last mode.
If your project doesn't fit CtrlP's definition of a project, a simple mapping could be enough:
nnoremap <key> :CtrlP /path/to/project<cr>
or you could use this option:
let g:ctrlp_root_markers = ['']
edit
My answer was based on the version of CtrlP currently installed on my machine.
The latest version adds an optional argument to :CtrlPLastMode: --dir which does exactly what you are looking for:
:CtrlPLastMode --dir
The g:ctrlp_working_path_mode values are different, too. I believe r is the equivalent of 2.

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

Resources