Vim ctrlp only works with a git repo - vim

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

Related

Cannot write to backup file

Since I have upgraded to Catalina, I cannot edit my dotfiles but get a message saying "Cannot write to backup file...".
I have checked the permissions on the file and my user account is the owner and has read and write permissions. If I edit the files with BBedit, I can save the files so the issue just seems to be editing within neovim.
I can also edit files using neovim in other directories but not within my dotfile directory.
Additional information added:
I have noticed that the files that I can't edit have the following permission structure:
.rwxrwxrwx# 1.4k pdd 30 Aug 2017 plugin_manager.vim
I have now removed the # attribute using xattr but that has not made any difference.
Additional Information Update
I have narrowed it down to something in my vimrc file. If I start neovim without my vimrc, I can save files in my vimrc directory.
I have the following code in my vimrc relating to backup files:
if exists('$SUDO_USER')
set nobackup " don't create root-owned files
set nowritebackup " don't create root-owned files
else
set backupdir=~/local/.config/nvim/tmp/backup
set backupdir+=~/.config/nvim/tmp/backup " keep backup files out of the way
set backupdir+=.
endif
If I comment these lines out, I can then save files in my vimrc directory. I am a little confused as I have had these in my vimrc for some time and have not had a problem.
I am probably missing something simple. Does anyone have any suggestions?
The original backup I used for vim was found here: https://vim.fandom.com/wiki/Incremental_backup_in_central_backup_directory created July 22, 2005 author Sylvain Lafleur
It doesn't work in neovim, but I was able to get it working:
I'm using KDE Neon. The original looks like it might work on windows, but I have not tested it.
A few things to note:
You will need to manually edit the g:backupdir and
g:this_root_backkup_dir (This may be reduced, but I didn't mess with it.)
I was unable to make $HOME work, so use /home/username on linux.
This is not my actual directory structure, but should suffice as an
example, in that /home/neon/vim existed before I used this code.
This is very redundant backup. Every time the file is saved it will
create a backup of the filename with date/time stamp.
In the .vimrc put your vim specific code in if !has('nvim')
and endif blocks. I put the following code in my init.vim file.
set backup
set backupcopy=yes
function Write_backup()
let g:backupdir='/home/neon/vim/vim_backups'
let &backupdir=g:backupdir
let g:backupext = strftime("_%Y-%m-%d_%H-%M-%S")
let &backupext=g:backupext
let g:this_root_backup_dir = '/home/neon/vim/vim_backups'
let g:this_dir = substitute(expand("%:p:h")," ","_","g")
let g:this_filename = substitute(expand("%")," ","_","g")
let g:this_drive = strpart(g:this_dir, 0, 1)
let g:this_backup_dir_drive = g:this_root_backup_dir . g:this_drive
let g:this_backup_dir = g:this_backup_dir_drive . strpart(g:this_dir, 1)
"--make DRIVE directory if it doesn't exist
if !filewritable(g:this_backup_dir_drive)
silent! execute expand('!mkdir -p ' . g:this_backup_dir_drive)
endif
"--make directory under DRIVE if it doesn't exist
if !filewritable(g:this_backup_dir)
silent! execute expand('!mkdir -p ' . g:this_backup_dir)
endif
"--set new backup dir
let g:backupdir = g:this_backup_dir
let &backupdir=g:backupdir
endfunction
call Write_backup()
inoremap <ESC> <ESC>:call Write_backup()<CR><C-l>
" note the <C-l> clears the output so remove if testing with echo

How to get the tail of a path (or string) in vim

I'm tuning my vimrc and I'd like to show in my airline bar the folder where I started vim (usually my project folder).
As the vim airline help says, I use let g:airline_section_b = '%{getcwd()}'
but then I get a complete path while I'd like to get the last folder.
I've tried with :t but doesn't work:
let g:airline_section_b = '%{getcwd()}:t. It just shows /home/vivo/myproject:t (while I want just myproject)
You're looking for fnamemodify() -> fnamemodify(getcwd(), ':t')

Vim Ctrl+P file search is Ignoring Directories With Dashes

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.

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.

Ctrl-p can't find my file?

The following is my ctr-p config:
let g:ctrlp_map = '<Leader>t'
let g:ctrlp_match_window_bottom = 0
let g:ctrlp_match_window_reversed = 0
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_root_markers = ['.ctrlp']
let g:ctrlp_dotfiles = 0
let g:ctrlp_switch_buffer = 0
I put one file .ctrlp in my project root directory.
I typed ,t and ,d to find my full filename "PhotoArtHacker" which's full path is
12083_cmcc_svn4456/mediatek/platform/mt6589/hardware/camera/hal/adapter/oppo/PhotoArtHacker.cpp.
while, I don't know why the file didn't appeared in the search result?
Is my file depth too deep?
By the way, the android project contains thousands of files.
I found a solution on the project's GitHub issues.
It looks that if you set the property:
let g:ctrlp_max_files=0
The problem will be solved.
I had the same problem: ctrlp+F5 wasn't finding all my source files, because it was searching through too many files in too many subdirectories. I found the following command in the ctrlp help:
let g:ctrlp_user_command =
\ ['.git', 'cd %s && git ls-files -co --exclude-standard']
This solved the problem without reading a vast number of files (so no slowdown and no need to set g:ctrlp_max_files to 0).
The ctrlp help provides other commands for searching other types of repositories.

Resources