Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StartifyDirChanging autocmd for customizing appearance in different directories #505

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion autoload/startify.vim
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function! startify#insane_in_the_membrane(on_vimenter) abort

if exists('##DirChanged')
let b:startify.cwd = getcwd()
autocmd startify DirChanged <buffer> if getcwd() !=# get(get(b:, 'startify', {}), 'cwd') | Startify | endif
autocmd startify DirChanged <buffer> call startify#handle_directory_change()
endif
if exists('#User#Startified')
doautocmd <nomodeline> User Startified
Expand All @@ -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 <nomodeline> User StartifyDirChanging
endif

Startify
endif
endfunction

" Function: #session_load {{{1
function! startify#session_load(source_last_session, ...) abort
if !isdirectory(s:session_dir)
Expand Down
43 changes: 43 additions & 0 deletions doc/startify.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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*
Expand Down Expand Up @@ -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*
>
Expand Down