I have come across the awesome ctrlp.vim plugin. It is a good alternative to the Command-T plugin which I have used before. What I did not like about Command-T is that it would take about 20-30 seconds to rescan files when it is invoked for the first time after starting vim.
CtrlP works a lot faster but it does not seem to automatically rescan for newly created files. How should I trigger a rescan manually?
Thanks!
From the documentation:
<F5>
- Refresh the match window and purge the cache for the current directory.
- Remove deleted files from MRU list.
This assumes you're in ctrl-p mode already. Note that you can hit F5 in the middle of a query, i.e., you can type a few characters, find it's not matching a recently updated file, and hit F5 to refresh right then. It will automatically show you the match if the file was just added to the ctrl-p cache.
As Jeet says you can press F5 but if that doesn't work you can always run :CtrlPClearCache which is what F5 is supposed to run.
From the documentation
:CtrlPClearCache
Flush the cache for the current working directory. The same as pressing <F5>
inside CtrlP.
To enable or disable caching, use the |g:ctrlp_use_caching| option.
I added this to .vimrc which turns off ctrlp caching
g:ctrlp_use_caching = 0
If you want, you can automatically bust the cache when a save happens, so it will be forced to refresh on next use.
Put this in your vimrc (credit docwhat):
" CtrlP auto cache clearing.
" ----------------------------------------------------------------------------
function! SetupCtrlP()
if exists("g:loaded_ctrlp") && g:loaded_ctrlp
augroup CtrlPExtension
autocmd!
autocmd FocusGained * CtrlPClearCache
autocmd BufWritePost * CtrlPClearCache
augroup END
endif
endfunction
if has("autocmd")
autocmd VimEnter * :call SetupCtrlP()
endif
Unfortunately there's no way to automatically keep the cache fresh in the background.
I know this is a old question, but it's so simple that I have to comment.
Put this in your .vimrc
:nnoremap <c-p> :CtrlPClearCache<bar>CtrlP<cr>
This will refresh the cache and then call CtrlP. No more missing files.
Related
I use MacVim and in my .vimrc file I have map ,V :source $MYVIMRC<CR> binding that allows me to apply the newest version of .vimrc in a case it was recently modified.
However I noticed that strange things can happen, relaunch can slow down vim and some plugins can start to conflict after pressing ,V, when everything works fine if I just close and relaunch MacVim from the scratch.
I'd be very thankful if you could give me a hint on the reason of this behavior as I'd like to have a possibility to update .vimrc file that will completely clear internal vim state and grab new configuration file
The only viable way to re-apply your config to a pristine Vim is actually to restart it.
But the most likely cause of slow downs is the overuse/misuse of autocommands.
Autocommands are added without checking for existing ones. One consequence is that they tend to pile-up if you don't manage them properly and every individual autocommand corresponding to a specific event is executed when that event is triggered, leading to dreadful slow downs.
Here are the two ways you are supposed to use autocommands in your vimrc:
Method #1
" anywhere
augroup nameofthegroup
autocmd!
autocmd EventName pattern commandtoexecute
autocmd AnotherEventName anotherpattern anothercommandtoexecute
augroup END
Method #2
" near the top of your vimrc
augroup nameofthegroup
autocmd!
augroup END
" anywhere
autocmd nameofthegroup EventName pattern commandtoexecute
autocmd nameofthegroup AnotherEventName anotherpattern anothercommandtoexecute
The idea is to create a group of autocommands that clears itself whenever it is invoked and thus prevents them from piling-up.
my question is similar to this one https://superuser.com/questions/277051/how-can-i-emulate-key-presses-on-vim-startup
I'm using the plugin netrw in my vim instead of nerdtree in that question. I add the following line to enable netrw automatically.
autocmd BufWinEnter * :Ve
While open vim, I need to press ^W^W each time because the active buffer is the left one, where the netrw is located.
How can I make vim emulate these key presses on startup? In fact, I've got it works before, but I didn't save my .vimrc in a recently re-installation of OS.
The answer of that question doesn't work for me.
My environment:
Mac OS X 10.9.5
MacVim Snapshot 73
Any answers appreciated, thanks a lot :)
Best way is by just appending the command to the existing :autocmd (separated by |):
autocmd BufWinEnter * Vexplore | wincmd w
Notes
By using BufWinEnter, this will open a netrw split on each displaying of a buffer. If you just want to trigger this once at Vim startup, VimEnter is the right event to use.
Don't abbreviate commands inside plugins and configuration; this is just to save keys on interactive use. It's easier to understand this way, and you don't have the risk of having to adapt all instances when you install / define another command with the same initial letters (e.g. :VerticalSplit). Also, you don't need the : in autocmds.
For <C-W> window commands, there's the special :wincmd Ex command to trigger those. For all else, you would use :execute 'normal! \<C-w>\<C-w>'.
A plugin adds to my insert mappings a mapping for <leader>is. I have some ideas which one it can be. But it does not matter I don't want to change anything in foreign plugins. So I want to disable this mapping. I tried this:
imap <leader>is <nop>
I did not help.
What is your suggestions?
BTW, I want to ask how disable in vimrc all insert mapping of plugins?
To remove an insert mode mapping, use the :iunmap command:
:iunmap <Leader>is
I don't know whether it is possible to do "bulk unmapping", but at least you can list all active insert mode mappings with
:imap
or, even better, with
:verbose imap
which will also tell you where the mapping has been defined in the first place.
Edit: To clarify, the unmapping needs to be done after the plugin has been loaded. To do so, create a file with the following contents in ~/.vim/after/plugin/ (see #ZyX's answer):
" myafter.vim: will be executed after plugins have been loaded
iunmap <Leader>is
Your command if inserted in the vimrc is executed before plugin defines the intrusive mapping and this is why it has no effect. To make it have effect you should make it run after that plugin which is normally achieved either by putting it into ~/.vim/after/plugin/disable_mappings.vim (any name instead of disable_mappings works). Second is using VimEnter event:
augroup DisableMappings
autocmd! VimEnter * :inoremap <leader>ic <Nop>
augroup END
. To disable all mappings see :h 'paste' and :h 'pastetoggle', also :h :imapclear (though the latter will remove mappings instead of temporary disabling them).
Of course, you may also use iunmap just where I suggested to use inoremap … <Nop>. How did I came to forget this command?
I've tried the following in my .vimrc:
:au FocusLost * silent! wa
autocmd BufLeave,FocusLost silent! wall
And also tried:
How can I make Vim autosave files when it loses focus?
but can't get it to work, when I do a Ctrl+Z or switch to another tab in Terminal (mac) it still doesn't auto save.
BufLeave is triggered when you go to another buffer. Neither <C-z> nor switching to another Terminal.app tab will trigger this because you are using CLI Vim which doesn't care at all about the terminal emulator's GUI or environment and… you are not leaving your buffer.
The same is true for FocusLost (more or less, the doc says that it's GUI only but can work in some terminals without telling which one).
So, these setting will probably work in MacVim but definetly not in CLI Vim.
Actually, since Vim is not aware of your terminal emulator's tabs or about it being put in the background, I doubt you can achieve your goal in CLI Vim.
I happen to have autocmd FocusLost * :wa in my ~/.vimrc but I've put it in an if has("gui_running") conditional and also inoremap <Esc> <Esc>:w<CR> to save on ESC. Hope it helps.
On OS X and Vim CLI, I use this plugin http://www.vim.org/scripts/script.php?script_id=4521
AutoSave - automatically save changes to disk without having to use :w
(or any binding to it) every time a buffer has been modified.
AutoSave is disabled by default, run :AutoSaveToggle to enable/disable
AutoSave. If you want plugin to be always enabled it can be done with
g:auto_save option (place 'let g:auto_save = 1' in your .vimrc).
I usually edit my files in gVim when developing. Sometimes I need to do a quick tweak in my .vimrc or in some plugins (like snipMate). To do this, I open a terminal, open vim and edit my .vimrc or my plugin.
(Why do I do that, opening .vimrc in a different window? I don't like to mix configuration files with project files when I'm at gvim, it's a matter of preference.)
I would like to have these modifications available at my already opened gVim without restarting it - automatically.
So, my question is: how do I automatically load my .gvimrc/.vimrc after editing it in an already opened gVim session? I use snipmate plugin, is it possible to create a snippet and use it right away as well?
I'm already using this solution
augroup myvimrchooks
au!
autocmd bufwritepost .vimrc source $HOME/.vim/.vimrc
augroup END
It works, but not in the first scenario I described. Any ideas in how can I do it? Thanks!
Here's a suggestion. This may need some tweaking. (Also, I'm asuming your .vimrc is in $HOME/.vim/.vimrc rather than $HOME/.vimrc based on how the question was worded.) The idea is to send the :source $HOME/.vim/.vimrc command to every active vim server when .vimrc is written.
function! UpdateVimRC()
for server in split(serverlist())
call remote_send(server, '<Esc>:source $HOME/.vim/.vimrc<CR>')
endfor
endfunction
augroup myvimrchooks
au!
autocmd bufwritepost .vimrc call UpdateVimRC()
augroup END
Probably only works with GVIM, but I'm not sure.