From 4533d7d86b213f0a6104837586b8c306f10e1f03 Mon Sep 17 00:00:00 2001 From: ELLIOTTCABLE Date: Wed, 18 Aug 2021 15:38:08 -0600 Subject: [PATCH] (new aucmd) Adding StartifyDirChanging for hooking into :cd --- autoload/startify.vim | 12 +++++++++++- doc/startify.txt | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/autoload/startify.vim b/autoload/startify.vim index 3b9867a..10fa93b 100644 --- a/autoload/startify.vim +++ b/autoload/startify.vim @@ -164,7 +164,7 @@ function! startify#insane_in_the_membrane(on_vimenter) abort if exists('##DirChanged') let b:startify.cwd = getcwd() - autocmd startify DirChanged if getcwd() !=# get(get(b:, 'startify', {}), 'cwd') | Startify | endif + autocmd startify DirChanged call startify#handle_directory_change() endif if exists('#User#Startified') doautocmd User Startified @@ -174,6 +174,16 @@ function! startify#insane_in_the_membrane(on_vimenter) abort endif endfunction +function! startify#handle_directory_change() abort + if getcwd() !=# get(get(b:, 'startify', {}), 'cwd') + if exists('#User#StartifyDirChanging') + doautocmd User StartifyDirChanging + endif + + Startify + endif +endfunction + " Function: #session_load {{{1 function! startify#session_load(source_last_session, ...) abort if !isdirectory(s:session_dir) diff --git a/doc/startify.txt b/doc/startify.txt index 1581b78..9025c8c 100644 --- a/doc/startify.txt +++ b/doc/startify.txt @@ -742,6 +742,12 @@ StartifyReady~ When the Startify buffer is ready. +StartifyDirChanging~ + + When the current-directory is changed while Startify is open, but not when + Startify itself changes the directory after activation. Executes before + `:Startify` is re-executed, so you're free to change Startify settings here. + StartifyBufferOpened~ For each buffer that got opened by Startify. When you open multiple files at @@ -918,6 +924,7 @@ FAQ *startify-faq* |startify-faq-16| How to disable single mappings? |startify-faq-17| Run Startify for each new tab! |startify-faq-18| Files from remote file system slow down startup! + |startify-faq-19| Use different configs for $HOME / different directories ------------------------------------------------------------------------------ *startify-faq-01* @@ -1161,6 +1168,42 @@ system to |g:startify_skiplist|: > let g:startify_skiplist = ['^/mnt/nfs'] < + +------------------------------------------------------------------------------ + *startify-faq-19* +Use different configs for $HOME / different directories~ + +If you want to use different settings for new Vim windows opened in, say, your +$HOME folder, than you use for new tabs opened in a current project, or opened +in a specific directory from the command-line: + +> + function! s:configure_startify() abort + if getcwd() ==# $HOME + let g:startify_change_cmd = 'cd' + let g:startify_change_to_vcs_root = 1 + + let g:startify_lists = [ + \ { 'type': 'files', 'header': [' MRU'] }, + \ ] + let g:startify_files_number = 20 + else + let g:startify_change_cmd = 'lcd' + let g:startify_change_to_vcs_root = 0 + + let g:startify_lists = [ + \ { 'type': 'dir', 'header': [' MRU '. getcwd()] }, + \ { 'type': 'files', 'header': [' MRU elsewhere'] }, + \ ] + let g:startify_files_number = 10 + endif + endfunction + call s:configure_startify() + + augroup startify | au! + autocmd User StartifyDirChanging call s:configure_startify() + augroup END +< ============================================================================== EXAMPLE *startify-example* >