Closed kristijanhusak closed 6 years ago
Hi,
I'm not sure if that should be an option on its own, because there are so many similar but different approaches on when Startify could be shown.. creating an option for each of those would only bloat everything.
But maybe I can interest you in some custom code? If it works for you, we can add it to :h startify-faq
.
autocmd BufDelete * if empty(filter(tabpagebuflist(), '!buflisted(v:val)')) | Startify | endif
Looks simple and easy to put in an option, but a few persons might want to take unlisted buffers into account as well. Or maybe they prefer BufWipeout
over BufDelete
and so on. It's more useful to document it accordingly and let the users choose.
Yeah that works, thanks!
One more unrelated question: Can Startify somehow know to open up the root of my project?
For example, i have project in ~/code/my-project
, and MRU list offers to open ~/code/my-project/components/list/list-item.js
. When i open it, it sets my working directory to the one where list-item.js
is, where i would like to set it to open ~/code/my-project
.
Yeah, I know that issue. Here's what I use: https://github.com/mhinz/dotfiles/blob/master/.vim/autoload/mhi.vim#L127-L156
So, you could put this in your vimrc:
function! s:cd() abort
if &buftype =~# '\v(nofile|terminal)' || expand('%') =~# '^fugitive'
return
endif
if !exists('s:cache')
let s:cache = {}
endif
let dirs = [ '.git', '.hg', '.svn' ]
let curdir = resolve(expand('%:p:h'))
if !isdirectory(curdir)
echohl WarningMsg | echo 'No such directory: '. curdir | echohl NONE
return
endif
if has_key(s:cache, curdir)
execute 'lcd' fnameescape(s:cache[curdir])
return
endif
for dir in dirs
let founddir = finddir(dir, curdir .';')
if !empty(founddir)
break
endif
endfor
let dir = empty(founddir) ? curdir : resolve(fnamemodify(founddir, ':p:h:h'))
let s:cache[curdir] = dir
execute 'lcd' fnameescape(dir)
endfunction
command! Cd call s:cd()
autocmd BufEnter * call s:cd()
So, it automatically sets the current directory to the folder containing the .git
/.hg
/.svn
directory (beginning with the directory of the opened file and going upwards) and does nothing otherwise. It also does some caching (which is really unimportant in most cases) and handles a few corner cases.
If it hits an unhandled corner case, you'll get a warning message and the current directory won't change.
Thanks!
Just came to say thanks for all your amazing work, and that I was looking for just this!
+1 to adding it to the :help example configs!
Thx
autocmd BufDelete * if empty(filter(tabpagebuflist(), '!buflisted(v:val)')) | Startify | endif
For some reason when I use this to open a session, it opens the session, but doesn't exit the startify page.
Hi there, VIM noobie here trying to switch from VSC to VIM as my IDE.
I implemented
autocmd BufDelete * if empty(filter(tabpagebuflist(), '!buflisted(v:val)')) | Startify | endif
which worked beautifully, until I started using vim-fugitive. It works, but every time I close a fugitive buffer it gives me the warning:
E937: Attempt to delete a buffer that is in use
Is there way to check if the current buffer is a fugitive screen and adding that to the if statement?
P.s. I'm pretty sure this is a noobie question, so apologies in advance. Just trying to learn here.
Hi, is there a way to show startify automatically once all buffers are closed?
So open up for example 2 buffers, do
:bd
on both, and once it should go toNo Name
buffer, to show Startify. I wasn't able to find that in the docs.