New lists handling
This commit is contained in:
parent
1675e50fca
commit
44c01cf608
|
@ -9,16 +9,12 @@ endif
|
|||
let g:autoloaded_startify = 1
|
||||
|
||||
" Init: values {{{1
|
||||
let s:session_dir = resolve(expand(get(g:, 'startify_session_dir',
|
||||
let s:cmd = (get(g:, 'startify_change_to_dir', 1) ? ' <bar> lcd %:h' : '') . '<cr>'
|
||||
let s:numfiles = get(g:, 'startify_files_number', 10)
|
||||
let s:show_special = get(g:, 'startify_enable_special', 1)
|
||||
let s:session_dir = resolve(expand(get(g:, 'startify_session_dir',
|
||||
\ has('win32') ? '$HOME\vimfiles\session' : '~/.vim/session')))
|
||||
|
||||
let s:cmd = (get(g:, 'startify_change_to_dir', 1) ? ' <bar> lcd %:h' : '') . '<cr>'
|
||||
let s:numfiles = get(g:, 'startify_show_files_number', 10)
|
||||
let s:show_special = get(g:, 'startify_enable_special', 1)
|
||||
let s:show_dir = get(g:, 'startify_show_dir')
|
||||
let s:show_files = get(g:, 'startify_show_files', 1)
|
||||
let s:show_sessions = get(g:, 'startify_show_sessions', 1)
|
||||
|
||||
" Function: #insane_in_the_membrane {{{1
|
||||
function! startify#insane_in_the_membrane() abort
|
||||
if !empty(v:servername) && exists('g:startify_skiplist_server')
|
||||
|
@ -39,6 +35,7 @@ function! startify#insane_in_the_membrane() abort
|
|||
setlocal norelativenumber
|
||||
endif
|
||||
|
||||
let cnt = 0
|
||||
let s:offset_header = 0
|
||||
|
||||
if exists('g:startify_custom_header')
|
||||
|
@ -47,29 +44,16 @@ function! startify#insane_in_the_membrane() abort
|
|||
endif
|
||||
|
||||
if s:show_special
|
||||
call append('$', ' [e] <empty buffer>')
|
||||
call append('$', [' [e] <empty buffer>', ''])
|
||||
endif
|
||||
|
||||
let cnt = 0
|
||||
if s:show_dir
|
||||
let cnt = s:show_dir(cnt)
|
||||
endif
|
||||
|
||||
if s:show_files && !empty(v:oldfiles)
|
||||
let cnt = s:show_files(cnt)
|
||||
endif
|
||||
|
||||
let sfiles = split(globpath(s:session_dir, '*'), '\n')
|
||||
if s:show_sessions && !empty(sfiles)
|
||||
let cnt = s:show_sessions(sfiles, cnt)
|
||||
endif
|
||||
|
||||
if exists('g:startify_bookmarks')
|
||||
call s:show_bookmarks(cnt)
|
||||
endif
|
||||
for list in get(g:, 'startify_list_order', ['files', 'sessions', 'bookmarks'])
|
||||
let cnt = s:show_{list}(cnt)
|
||||
call append('$', '')
|
||||
endfor
|
||||
|
||||
if s:show_special
|
||||
call append('$', ['', ' [q] <quit>'])
|
||||
call append('$', ' [q] <quit>')
|
||||
endif
|
||||
|
||||
setlocal nomodifiable nomodified
|
||||
|
@ -194,11 +178,9 @@ endfunction
|
|||
|
||||
" Function: s:show_dir {{{1
|
||||
function! s:show_dir(cnt) abort
|
||||
let cnt = a:cnt
|
||||
let cnt = a:cnt
|
||||
let files = []
|
||||
if s:show_special
|
||||
call append('$', '')
|
||||
endif
|
||||
|
||||
for fname in split(glob('.\=*'))
|
||||
if isdirectory(fname)
|
||||
\ || (exists('g:startify_skiplist') && s:is_in_skiplist(resolve(fnamemodify(fname, ':p'))))
|
||||
|
@ -206,80 +188,100 @@ function! s:show_dir(cnt) abort
|
|||
endif
|
||||
call add(files, [getftime(fname), fname])
|
||||
endfor
|
||||
|
||||
function! l:compare(x, y)
|
||||
return a:y[0] - a:x[0]
|
||||
endfunction
|
||||
|
||||
call sort(files, 'l:compare')
|
||||
|
||||
for items in files
|
||||
let index = s:get_index_as_string(cnt)
|
||||
let fname = items[1]
|
||||
|
||||
call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
|
||||
execute 'nnoremap <buffer>' index ':edit' fnameescape(fname) '<cr>'
|
||||
|
||||
let cnt += 1
|
||||
|
||||
if (cnt == s:numfiles)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
|
||||
return cnt
|
||||
endfunction
|
||||
|
||||
" Function: s:show_files {{{1
|
||||
function! s:show_files(cnt) abort
|
||||
let cnt = a:cnt
|
||||
let num = s:numfiles
|
||||
let cnt = a:cnt
|
||||
let num = s:numfiles
|
||||
let entries = {}
|
||||
if s:show_special || s:show_dir
|
||||
call append('$', '')
|
||||
endif
|
||||
|
||||
for fname in v:oldfiles
|
||||
let expfname = resolve(fnamemodify(fname, ':p'))
|
||||
let fullpath = resolve(fnamemodify(fname, ':p'))
|
||||
|
||||
" filter duplicates, bookmarks and entries from the skiplist
|
||||
if has_key(entries, expfname)
|
||||
\ || !filereadable(expfname)
|
||||
\ || (exists('g:startify_skiplist') && s:is_in_skiplist(expfname))
|
||||
\ || (exists('g:startify_bookmarks') && s:is_bookmark(expfname))
|
||||
if has_key(entries, fullpath)
|
||||
\ || !filereadable(fullpath)
|
||||
\ || (exists('g:startify_skiplist') && s:is_in_skiplist(fullpath))
|
||||
\ || (exists('g:startify_bookmarks') && s:is_bookmark(fullpath))
|
||||
continue
|
||||
endif
|
||||
let entries[expfname] = 1
|
||||
|
||||
let entries[fullpath] = 1
|
||||
let index = s:get_index_as_string(cnt)
|
||||
|
||||
call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
|
||||
execute 'nnoremap <buffer>' index ':edit' fnameescape(fname) s:cmd
|
||||
|
||||
let cnt += 1
|
||||
let num -= 1
|
||||
|
||||
if !num
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
|
||||
return cnt
|
||||
endfunction
|
||||
|
||||
" Function: s:show_sessions {{{1
|
||||
function! s:show_sessions(sfiles, cnt) abort
|
||||
let cnt = a:cnt
|
||||
if s:show_special || s:show_dir || s:show_files
|
||||
call append('$', '')
|
||||
function! s:show_sessions(cnt) abort
|
||||
let sfiles = split(globpath(s:session_dir, '*'), '\n')
|
||||
|
||||
if empty(sfiles)
|
||||
return a:cnt
|
||||
endif
|
||||
for i in range(len(a:sfiles))
|
||||
|
||||
let cnt = a:cnt
|
||||
|
||||
for i in range(len(sfiles))
|
||||
let idx = (i + cnt)
|
||||
let index = s:get_index_as_string(idx)
|
||||
call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fnamemodify(a:sfiles[i], ':t:r'))
|
||||
execute 'nnoremap <buffer> '. index .' :source '. fnameescape(a:sfiles[i]) .'<cr>'
|
||||
|
||||
call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fnamemodify(sfiles[i], ':t:r'))
|
||||
execute 'nnoremap <buffer> '. index .' :source '. fnameescape(sfiles[i]) .'<cr>'
|
||||
endfor
|
||||
|
||||
return idx
|
||||
endfunction
|
||||
|
||||
" Function: s:show_bookmarks {{{1
|
||||
function! s:show_bookmarks(cnt) abort
|
||||
let cnt = a:cnt
|
||||
if s:show_special || s:show_dir || s:show_files || s:show_sessions
|
||||
call append('$', '')
|
||||
|
||||
if exists('g:startify_bookmarks')
|
||||
for fname in g:startify_bookmarks
|
||||
let cnt += 1
|
||||
let index = s:get_index_as_string(cnt)
|
||||
|
||||
call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
|
||||
execute 'nnoremap <buffer> '. index .' :edit '. fnameescape(fname) . s:cmd
|
||||
endfor
|
||||
endif
|
||||
for fname in g:startify_bookmarks
|
||||
let cnt += 1
|
||||
let index = s:get_index_as_string(cnt)
|
||||
call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
|
||||
execute 'nnoremap <buffer> '. index .' :edit '. fnameescape(fname) . s:cmd
|
||||
endfor
|
||||
|
||||
return cnt
|
||||
endfunction
|
||||
|
||||
" Function: s:is_in_skiplist {{{1
|
||||
|
|
|
@ -77,15 +77,6 @@ Startify basically provides two things:
|
|||
Put these variables into your vimrc. The shown assignments are also the
|
||||
default values.
|
||||
|
||||
============-
|
||||
|
||||
let g:startify_empty_buffer_key = ''
|
||||
|
||||
This creates an additional, hidden mapping for the empty buffer.
|
||||
|
||||
Example: let g:startify_empty_buffer_key = 'o'
|
||||
|
||||
|
||||
============-
|
||||
|
||||
let g:startify_session_dir = '~/.vim/session'
|
||||
|
@ -97,34 +88,34 @@ The default for Windows systems is '$HOME\vimfiles\session'.
|
|||
|
||||
============-
|
||||
|
||||
let g:startify_show_sessions = 1
|
||||
let g:startify_lists = ['files', 'sessions', 'bookmarks']
|
||||
|
||||
List saved sessions in g:startify_session_dir.
|
||||
At the moment startify can show these kind of lists:
|
||||
|
||||
1) Most recently used files.
|
||||
|
||||
This lists the most recently used files using viminfo. The number of files
|
||||
is limited by g:startify_files_number.
|
||||
|
||||
|
||||
============-
|
||||
2) Most recently changed files in the current directory.
|
||||
|
||||
let g:startify_show_files = 1
|
||||
This lists the files from the current directory sorted by modification
|
||||
time. The number of files is limited by g:startify_files_number.
|
||||
|
||||
List recently used files using viminfo.
|
||||
3) Bookmarks.
|
||||
|
||||
The number is limited by g:startify_show_files_number.
|
||||
This lists bookmarks, thus hardcoded files that will always be shown.
|
||||
Have a look at g:startify_bookmarks.
|
||||
|
||||
4) Sessions.
|
||||
|
||||
============-
|
||||
This lists all the sessions saved in the directory
|
||||
g:startify_session_dir.
|
||||
|
||||
let g:startify_show_files_number = 10
|
||||
Therefore, to show all of them in the above order:
|
||||
|
||||
The number of files to list.
|
||||
|
||||
|
||||
============-
|
||||
|
||||
let g:startify_show_dir = 0
|
||||
|
||||
Show files from the current directory sorted by modification time.
|
||||
|
||||
The number is limited by g:startify_show_files_number.
|
||||
let g:startify_lists = ['files', 'dir', 'bookmarks', 'sessions']
|
||||
|
||||
|
||||
============-
|
||||
|
@ -136,6 +127,21 @@ the start screen.
|
|||
|
||||
Example: let g:startify_bookmarks = [ '~/.vimrc' ]
|
||||
|
||||
|
||||
============-
|
||||
|
||||
let g:startify_files_number = 10
|
||||
|
||||
The number of files to list.
|
||||
|
||||
|
||||
============-
|
||||
|
||||
let g:startify_change_to_dir = 1
|
||||
|
||||
When opening a file or bookmark, change to its directory.
|
||||
|
||||
|
||||
============-
|
||||
|
||||
let g:startify_skiplist = []
|
||||
|
@ -160,6 +166,22 @@ name contained in this list.
|
|||
Example: let g:startify_skiplist_server = [ 'GVIM' ]
|
||||
|
||||
|
||||
============-
|
||||
|
||||
let g:startify_empty_buffer_key = 'o'
|
||||
|
||||
This creates an additional, hidden mapping for the empty buffer.
|
||||
|
||||
Default: does not exist
|
||||
|
||||
|
||||
============-
|
||||
|
||||
let g:startify_enable_special = 1
|
||||
|
||||
Show <empty buffer> and <quit>.
|
||||
|
||||
|
||||
============-
|
||||
|
||||
let g:startify_custom_indices = []
|
||||
|
@ -193,13 +215,6 @@ Best practices:
|
|||
- (you might want to keep 'j' and 'k' for navigation)
|
||||
|
||||
|
||||
============-
|
||||
|
||||
let g:startify_enable_special = 1
|
||||
|
||||
Don't show <empty buffer> and <quit>.
|
||||
|
||||
|
||||
============-
|
||||
|
||||
let g:startify_custom_header = ''
|
||||
|
@ -223,13 +238,6 @@ Example:
|
|||
\ ]
|
||||
|
||||
|
||||
============-
|
||||
|
||||
let g:startify_change_to_dir = 1
|
||||
|
||||
When opening a file or bookmark, change to its directory.
|
||||
|
||||
|
||||
==============================================================================
|
||||
4. Commands *startify-commands*
|
||||
|
||||
|
|
Loading…
Reference in a new issue