feat: improve UI visibility and user interaction

Statusline: add buffer count, PASTE/SPELL/MAX flags, LSP server name,
encoding (shown only when non-utf-8/unix).

File tree sidebar: ,e toggles netrw sidebar (cwd), ,E toggles sidebar
(current file dir). Tracks t:netrw_sidebar_buf per-tab for reliable
toggle. browse_split=4 opens files in editor window.

vim . integration: opens tree sidebar (30 cols) + Startify dashboard.
Files opened from tree replace the dashboard.

Toggle feedback: F2/F3/F4/F6/,ss/,z now echo their new state.
This commit is contained in:
m1ngsama 2026-04-22 12:13:37 +08:00
parent 97ca2be139
commit 2e37efe644
4 changed files with 95 additions and 14 deletions

View file

@ -127,16 +127,16 @@ nnoremap <M-k> :m .-2<CR>==
vnoremap <M-j> :m '>+1<CR>gv=gv vnoremap <M-j> :m '>+1<CR>gv=gv
vnoremap <M-k> :m '<-2<CR>gv=gv vnoremap <M-k> :m '<-2<CR>gv=gv
nnoremap <leader>ss :setlocal spell!<cr> nnoremap <silent> <leader>ss :setlocal spell!<CR>:echo 'Spell: ' . (&spell ? 'ON' : 'OFF')<CR>
nnoremap <leader>sn ]s nnoremap <leader>sn ]s
nnoremap <leader>sp [s nnoremap <leader>sp [s
nnoremap <leader>sa zg nnoremap <leader>sa zg
nnoremap <leader>s? z= nnoremap <leader>s? z=
set pastetoggle=<F2> nnoremap <silent> <F2> :set paste!<CR>:echo 'Paste: ' . (&paste ? 'ON' : 'OFF')<CR>
nnoremap <F3> :set invnumber<CR> nnoremap <silent> <F3> :set invnumber<CR>:echo 'Line numbers: ' . (&number ? 'ON' : 'OFF')<CR>
nnoremap <F4> :set invrelativenumber<CR> nnoremap <silent> <F4> :set invrelativenumber<CR>:echo 'Relative numbers: ' . (&relativenumber ? 'ON' : 'OFF')<CR>
nnoremap <F6> :set list!<CR> nnoremap <silent> <F6> :set list!<CR>:echo 'List chars: ' . (&list ? 'ON' : 'OFF')<CR>
nnoremap <space> za nnoremap <space> za

View file

@ -4,13 +4,42 @@
let g:netrw_liststyle = 3 let g:netrw_liststyle = 3
let g:netrw_banner = 0 let g:netrw_banner = 0
let g:netrw_browse_split = 0 let g:netrw_browse_split = 4
let g:netrw_winsize = 25 let g:netrw_winsize = 25
let g:netrw_altv = 1
let g:netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+' let g:netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+'
let g:netrw_list_hide .= ',\.pyc$,node_modules,\.git,__pycache__,\.DS_Store' let g:netrw_list_hide .= ',\.pyc$,node_modules,\.git,__pycache__,\.DS_Store'
nnoremap <leader>e :Explore<CR> function! s:ToggleSidebar(...) abort
nnoremap <leader>E :Vexplore<CR> let l:dir = a:0 ? a:1 : getcwd()
if exists('t:netrw_sidebar_buf')
let l:win = bufwinnr(t:netrw_sidebar_buf)
if l:win != -1
let l:cur = winnr()
execute l:win . 'wincmd w'
close
if l:cur > l:win
execute (l:cur - 1) . 'wincmd w'
endif
unlet t:netrw_sidebar_buf
return
endif
unlet t:netrw_sidebar_buf
endif
execute '1wincmd w'
execute 'Vexplore ' . fnameescape(l:dir)
vertical resize 30
let t:netrw_sidebar_buf = bufnr('%')
wincmd l
endfunction
nnoremap <silent> <leader>e :call <SID>ToggleSidebar()<CR>
nnoremap <silent> <leader>E :call <SID>ToggleSidebar(expand('%:p:h'))<CR>
augroup ChopstickNetrw
autocmd!
autocmd FileType netrw setlocal bufhidden=wipe
augroup END
" ── FZF ───────────────────────────────────────────────────────────────────── " ── FZF ─────────────────────────────────────────────────────────────────────
@ -78,9 +107,11 @@ function! s:ToggleMaximize() abort
if exists('t:maximize_session') if exists('t:maximize_session')
execute t:maximize_session execute t:maximize_session
unlet t:maximize_session unlet t:maximize_session
echo 'Window: restored'
else else
let t:maximize_session = winrestcmd() let t:maximize_session = winrestcmd()
resize | vertical resize resize | vertical resize
echo 'Window: MAXIMIZED'
endif endif
endfunction endfunction
nnoremap <silent> <leader>z :call <SID>ToggleMaximize()<CR> nnoremap <silent> <leader>z :call <SID>ToggleMaximize()<CR>

View file

@ -178,7 +178,7 @@ function! s:CheatSheet() abort
\ '', \ '',
\ 'FILES & SEARCH', \ 'FILES & SEARCH',
\ ' Ctrl+p Fuzzy find file (git-aware)', \ ' Ctrl+p Fuzzy find file (git-aware)',
\ ' ,e / ,E File browser / vertical split', \ ' ,e / ,E Toggle tree sidebar (cwd / file dir)',
\ ' ,b Search open buffers', \ ' ,b Search open buffers',
\ ' ,rg Search project contents (ripgrep)', \ ' ,rg Search project contents (ripgrep)',
\ ' ,rG Ripgrep word under cursor', \ ' ,rG Ripgrep word under cursor',

View file

@ -79,15 +79,28 @@ if exists('g:plugs["vim-startify"]')
let g:startify_files_number = 8 let g:startify_files_number = 8
let g:startify_padding_left = 4 let g:startify_padding_left = 4
function! s:SetupDirView() abort
if argc() != 1 || !isdirectory(argv()[0]) || exists('s:std_in')
return
endif
let l:dir = fnameescape(argv()[0])
execute 'cd ' . l:dir
execute 'Vexplore ' . l:dir
vertical resize 30
let t:netrw_sidebar_buf = bufnr('%')
wincmd l
if exists(':Startify') == 2
Startify
else
enew
endif
endfunction
if !g:is_tty if !g:is_tty
augroup ChopstickStartup augroup ChopstickStartup
autocmd! autocmd!
autocmd StdinReadPre * let s:std_in = 1 autocmd StdinReadPre * let s:std_in = 1
autocmd VimEnter * autocmd VimEnter * nested call <SID>SetupDirView()
\ if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') |
\ exe 'cd ' . fnameescape(argv()[0]) |
\ if exists(':Startify') == 2 | Startify | else | enew | endif |
\ endif
augroup END augroup END
endif endif
@ -144,14 +157,51 @@ function! SLAle() abort
return printf(' E:%d W:%d ', l:e, l:w) return printf(' E:%d W:%d ', l:e, l:w)
endfunction endfunction
function! SLBufCount() abort
let l:n = len(filter(range(1, bufnr('$')), 'buflisted(v:val)'))
return l:n > 1 ? ' ' . l:n . ' bufs ' : ''
endfunction
function! SLFlags() abort
let l:f = ''
if &paste | let l:f .= ' PASTE' | endif
if &spell | let l:f .= ' SPELL' | endif
if exists('t:maximize_session') | let l:f .= ' MAX' | endif
return empty(l:f) ? '' : l:f . ' '
endfunction
function! SLLsp() abort
if !exists('*lsp#get_server_names') | return '' | endif
let l:servers = lsp#get_server_names()
if empty(l:servers) | return '' | endif
let l:status = lsp#get_server_status(l:servers[0])
if l:status ==# 'running'
return ' ' . l:servers[0] . ' '
elseif l:status ==# 'starting' || l:status ==# 'not running'
return ' ' . l:servers[0] . '… '
endif
return ''
endfunction
function! SLEncoding() abort
let l:enc = &fileencoding !=# '' ? &fileencoding : &encoding
let l:fmt = &fileformat
if l:enc ==? 'utf-8' && l:fmt ==# 'unix' | return '' | endif
return ' ' . l:enc . '[' . l:fmt . '] '
endfunction
function! SLBuild() abort function! SLBuild() abort
let [l:label, l:hl] = SLMode() let [l:label, l:hl] = SLMode()
let l:s = '%#' . l:hl . '#' . l:label let l:s = '%#' . l:hl . '#' . l:label
let l:s .= '%#SLBody# %f ' let l:s .= '%#SLBody# %f '
let l:s .= '%#SLFlag#%m%r' let l:s .= '%#SLFlag#%m%r'
let l:s .= '%#SLFlag#' . SLFlags()
let l:s .= '%#SLBody#%=' let l:s .= '%#SLBody#%='
let l:s .= '%#SLBody#' . SLBufCount()
let l:s .= '%#SLFlag#' . SLAle() let l:s .= '%#SLFlag#' . SLAle()
let l:s .= '%#SLRight#' . SLLsp()
let l:s .= '%#SLGit#' . SLGit() let l:s .= '%#SLGit#' . SLGit()
let l:s .= '%#SLRight#' . SLEncoding()
let l:s .= '%#SLFtype# %y ' let l:s .= '%#SLFtype# %y '
let l:s .= '%#SLRight# %l:%c %P ' let l:s .= '%#SLRight# %l:%c %P '
return l:s return l:s