How to search from the root of project - Ag / VIM - 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

Related

vim: change pwd while working with cscope

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.

: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.

Where do I save pathogen.vim so that the plugin installs

I've just downloaded the file pathogen.vim from vim.org
Where do I save this file so that it becomes part of gVim? In one of the runtimepath locations?
Does this .vim need to go in either of these locations?:
- C:\Program Files (x86)\Vim73\
- C:\Program Files (x86)\Vim\vimfiles\
You don't need pathogen to install plugins.
For the nth time this week, put your plugins into the C:\Users\username\vimfiles directory and your settings into the C:\Users\username\_vimrc file. You must create those directories/files yourself.
What you should have:
C:\Users\username\_vimrc
C:\Users\username\vimfiles\
C:\Users\username\vimfiles\autoload\
C:\Users\username\vimfiles\autoload\pathogen.vim
C:\Users\username\vimfiles\bundle\
Many Vim plugins have UNIX-oriented instructions and Vim itself is mostly UNIX-oriented so you'd better learn a thing or two about the UNIX command line.
If you are using windows, I recommend that you install your gVim into a custom directory instead of under Program Files or Program Files (x86) directories.
This makes things a lot easier going forward.
For instance, in a location like this:-
Install gvim in your user's home directory (e.g. C:\Users\whytheq\) (where whytheq is your user name) so it becomes C:\Users\whytheq\Vim73\.
Then, create a _vimrc file (with no file extension) there as well with the following contents:
set nocp
call pathogen#infect()
syntax on
filetype plugin indent on
Next, create a folder under C:\Users\whytheq\Vim73 called vimfiles with two subfolders beneath that, autoload and bundle.
Then, download the pathogen.vim file and moved it into the autoload folder.

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.

Resources