Vim Ctrl+P file search is Ignoring Directories With Dashes - vim

I am using the vim Ctrl+P plugin for file searching,
All that is listed in my .vimrc is
let g:ctrlp_working_path_mode = 0
let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|CVS$\|build|\.svn$\|target$',
\ 'file': '\.class$\|\.so$',
\ }
let g:ctrlp_extensions = ['dir', 'mixed']
But it does not seem to index any directories that have a - in them. Does anyone know how to fix this?

If you use CtrlP, be careful which version you use. There is no longer maintained kien/ctrlp.vim, and its active fork ctrlpvim/ctrlp.vim.
Also, if you need to speed up your CtrlP, you should consider to use Silver Searcher. The integration with Vim can provide ag.vim plugin. About ignore setting you can check this answer.

Related

Vim ctrlp only works with a git repo

The vim plugin ctrl p only works for me into git repo.
Why does it need a .git file?
Be work i mean it is searching my entire machine when no .git file is found.
my settings
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_match_window = 'top,order:ttb,min:1,max:30,results:30'
let g:ctrlp_custom_ignore = 'node_modules\|vendor/|DS_Store\|git'
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.idea/*,*/.DS_Store,*/vendor
Also tried:
let g:ctrlp_working_path_mode = 'r'
let g:ctrlp_working_path_mode = 'c'
I'm not entirely sure what you are after, it sounds like you want ctrlp to pick up all files system wide and not just the "project" root directory.
The g:ctrlp_working_path_mode flags you set would either tell ctrlp c - only show me files from current loaded buffers directory including subdirectories, or r the first project root directory as identified with some sort of hidden repository directory like .git. Neither of which suggests what I think you are asking for...
So I'll go out of a limb and suggest that you can probably update the global variable:
let g:ctrlp_cmd = 'CtrlP /'
To look for all files, on a linux system. As detailed in the reader:
Run :CtrlP or :CtrlP [starting-directory] to invoke CtrlP in find file mode.
Or test the above with CtrlP / in command mode first.
Again, I've guessed what you wanted here...

Vim/Ag: files whitelist in AgFromSearch

I am using vim with Ag.vim(silver-searcher) and i came across a problem.
the Ag plugin defines Ex mode commands such as :Ag and :AgFromSearch.
but while :Ag lets me pass options to the shell's ag command such as -G which lets me whitelist files, :AgFromSearch doesn't let me..
so my question is - is there any pretty solution to this? or should i just imitate the way the plugin implements :AgFromSearch with :Ag and pass through it the options?
Ag.vim is deprecated; you should consider moving back to using Ack.vim.
The maintainer of Ack.vim is open to supporting the Ag community.
The :AckFromSearch allows for passing extra options like the -G. You first must configure the Ack.vim to use Ag, by adding this to .vimrc:
let g:ackprg = 'ag --vimgrep'
And, then you can do :AckFromSearch like the following:
:AckFromSearch -G '.*py'
Since moving back to the Ack.vim plugin, I use this feature quite frequently and have mapped ,* to :AgFromSearch in vim.

Search whole project by default with Vim/Ack

I would like to use Ack (or similar plugin if something else can do the job) to search my whole project in Vim by default, rather than just the current directory. Ideally I'd end up with a process that works like using Cmd+Shift+F in Sublime. How can I do this?
An option like CtrlP's let g:ctrlp_working_path_mode = 'r' that makes it search within the nearest parent directory that contains a file like .git would be perfect. (https://github.com/kien/ctrlp.vim#basic-options)
I think Rooter is what you want. For example:
let g:rooter_patterns = ['Rakefile', '.git/']
I don't think Ack (or grep/vimgrep) can detect your "project root". If you often work on several projects, you could add this block in your vimrc:
let g:projectA_path="/path/to/A"
let g:projectB_path="/path/to/B"
let g:projectC_path="/path/to/C"
also define some functions/commands, like AckA, AckB, AckC...
basically the func/command just does:
exec 'Ack! '. pattern . " " . g:projectA_path
the pattern is the argument you passed in. then, in future, you could do:
:AckA foo
or
:call AckA("foo")
for quick grepping/acking in projectA.
I didn't think of a simpler way to do it. glad to see if there is better solution.
Most of the time I don't need to cd the project root, but stay in the same working directory.
So there is a simpler solution, based on answer of Kent, without cd'ing the project root, installing additional plugins and using ag:
let g:ackprg = 'ag --vimgrep --smart-case'
function! Find_git_root()
return system('git rev-parse --show-toplevel 2> /dev/null')[:-2]
endfunction
command! -nargs=1 Ag execute "Ack! <args> " . Find_git_root()
And to use it call :Ag <keyword>
I have this line in my .vimrc:
cnoreabbrev ack cd ~/your-project <bar> Ack! <Space>
Whenever you type :ack and hit the space the rest will be added to the command line and you can add the keyword.

How to make Syntastic search for javac config file in project

I'm using Syntastic with vim and I've added external libraries to its classpath (using SyntasticJavacEditClasspath). This creates a file in the current working directory (which was my project folder). This is all fine. However, whenever I restart vim, Syntastic seems to search for the .syntastic_javac_config file in the current working directory only, and the cwd is, of course, randomly whereever I left it in my last operation. So it doesn't find the file and I get a bunch of incorrect import errors. Can Syntastic be told to search the file's parents for the config file? If not, is there a way of using vim where this typically works? (I've only been using vim for a couple of months so I might be clueless.)
According to the official manual, the snippet should solve the problem. Put it in your .vimrc, change the javascript, jscs, etc. to required values
function! FindConfig(prefix, what, where)
let cfg = findfile(a:what, escape(a:where, ' ') . ';')
return cfg !=# '' ? ' ' . a:prefix . ' ' . shellescape(cfg) : ''
endfunction
autocmd FileType javascript let b:syntastic_javascript_jscs_args =
\ get(g:, 'syntastic_javascript_jscs_args', '') .
\ FindConfig('-c', '.jscs', expand('<afile>:p:h', 1))

How to customize folding in vim-latex for my sections/commands?

I've installed the vim-latex-suite and I'd like to customize the folding for use with the labbook package. The labbook package uses \labday, \experiment, and \subexperiment in place of \chapter, \section, and \subsection.
I'd like to customize the folding options with vim-latex-suite in Vim so that \labday, \experiment, and \subexperiment are folded like the traditional sectioning commands.
I've tried adding to my ~/.vim/after/ftplugin/tex.vim the following (but it didn't work)
" Folding sections
let g:Tex_FoldedSections = ',labday,experiment,subexperiment'
" Folding commands
let g:Tex_FoldedCommands = ',labday,experiment,subexperiment'
Can someone show me how to customize the folding for the labbook package?
I think you should put
let g:Tex_FoldedSections = 'labday,experiment,subexperiment'`
in your .vimrc itself. If you take a look at ftplugin/latex-suite/folding.vim you'll find:
if g:Tex_FoldedSections != ''
call Tex_FoldSections(g:Tex_FoldedSections,
\ '^\s*\\frontmatter\|^\s*\\mainmatter\|^\s*\\backmatter\|'
\. '^\s*\\begin{thebibliography\|>>>\|^\s*\\endinput\|'
\. '^\s*\\begin{slide\|^\s*\\end{document')
endif
Which means that setting Tex_FoldedSections after the plugin as already loaded will not work. Also make sure that your sections in your latex file itself are nested correctly.

Resources