diff --git a/README.md b/README.md index 3fafdcf..24be6be 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ chopsticks gives you a production-ready Vim config in one command. Pure VimScrip ## What's in the box -| | | -|-|-| +| Feature | Description | +|---------|-------------| | **LSP** | completion, go-to-def, hover, rename, code actions — pure VimScript ([vim-lsp](https://github.com/prabirshrestha/vim-lsp)) | | **Lint + format** | [ALE](https://github.com/dense-analysis/ale) runs black, prettier, gofmt, rustfmt on save | | **Fuzzy find** | files, buffers, grep, tags, marks, commands — [FZF](https://github.com/junegunn/fzf.vim) | diff --git a/modules/core.vim b/modules/core.vim index 37191cd..55848c1 100644 --- a/modules/core.vim +++ b/modules/core.vim @@ -127,16 +127,16 @@ nnoremap :m .-2== vnoremap :m '>+1gv=gv vnoremap :m '<-2gv=gv -nnoremap ss :setlocal spell! +nnoremap ss :setlocal spell!:echo 'Spell: ' . (&spell ? 'ON' : 'OFF') nnoremap sn ]s nnoremap sp [s nnoremap sa zg nnoremap s? z= -set pastetoggle= -nnoremap :set invnumber -nnoremap :set invrelativenumber -nnoremap :set list! +nnoremap :set paste!:echo 'Paste: ' . (&paste ? 'ON' : 'OFF') +nnoremap :set invnumber:echo 'Line numbers: ' . (&number ? 'ON' : 'OFF') +nnoremap :set invrelativenumber:echo 'Relative numbers: ' . (&relativenumber ? 'ON' : 'OFF') +nnoremap :set list!:echo 'List chars: ' . (&list ? 'ON' : 'OFF') nnoremap za diff --git a/modules/navigation.vim b/modules/navigation.vim index 9fc8d7d..caa710f 100644 --- a/modules/navigation.vim +++ b/modules/navigation.vim @@ -4,13 +4,37 @@ let g:netrw_liststyle = 3 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_altv = 1 let g:netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+' let g:netrw_list_hide .= ',\.pyc$,node_modules,\.git,__pycache__,\.DS_Store' -nnoremap e :Explore -nnoremap E :Vexplore +function! s:ToggleSidebar(...) abort + let l:dir = a:0 ? a:1 : getcwd() + if getbufvar(winbufnr(1), '&filetype') ==# 'netrw' && getwinvar(1, '&winfixwidth') + let l:cur = winnr() + 1wincmd w + close + if l:cur > 1 + execute (l:cur - 1) . 'wincmd w' + endif + return + endif + execute 'topleft vertical 30new' + execute 'Explore ' . fnameescape(l:dir) + setlocal winfixwidth + setlocal bufhidden=wipe + wincmd p +endfunction + +nnoremap e :call ToggleSidebar() +nnoremap E :call ToggleSidebar(expand('%:p:h')) + +augroup ChopstickNetrw + autocmd! + autocmd FileType netrw setlocal bufhidden=wipe +augroup END " ── FZF ───────────────────────────────────────────────────────────────────── @@ -78,9 +102,11 @@ function! s:ToggleMaximize() abort if exists('t:maximize_session') execute t:maximize_session unlet t:maximize_session + echo 'Window: restored' else let t:maximize_session = winrestcmd() resize | vertical resize + echo 'Window: MAXIMIZED' endif endfunction nnoremap z :call ToggleMaximize() diff --git a/modules/tools.vim b/modules/tools.vim index 07c56a5..235744b 100644 --- a/modules/tools.vim +++ b/modules/tools.vim @@ -178,7 +178,7 @@ function! s:CheatSheet() abort \ '', \ 'FILES & SEARCH', \ ' 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', \ ' ,rg Search project contents (ripgrep)', \ ' ,rG Ripgrep word under cursor', diff --git a/modules/ui.vim b/modules/ui.vim index 2540323..a313d1f 100644 --- a/modules/ui.vim +++ b/modules/ui.vim @@ -79,15 +79,29 @@ if exists('g:plugs["vim-startify"]') let g:startify_files_number = 8 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 + vertical rightbelow vnew + if exists(':Startify') == 2 + Startify + else + enew + endif + wincmd h + vertical resize 30 + setlocal winfixwidth + wincmd l + endfunction + if !g:is_tty augroup ChopstickStartup autocmd! autocmd StdinReadPre * let s:std_in = 1 - autocmd VimEnter * - \ if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') | - \ exe 'cd ' . fnameescape(argv()[0]) | - \ if exists(':Startify') == 2 | Startify | else | enew | endif | - \ endif + autocmd VimEnter * nested call SetupDirView() augroup END endif @@ -144,14 +158,51 @@ function! SLAle() abort return printf(' E:%d W:%d ', l:e, l:w) 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 let [l:label, l:hl] = SLMode() let l:s = '%#' . l:hl . '#' . l:label let l:s .= '%#SLBody# %f ' let l:s .= '%#SLFlag#%m%r' + let l:s .= '%#SLFlag#' . SLFlags() let l:s .= '%#SLBody#%=' + let l:s .= '%#SLBody#' . SLBufCount() let l:s .= '%#SLFlag#' . SLAle() + let l:s .= '%#SLRight#' . SLLsp() let l:s .= '%#SLGit#' . SLGit() + let l:s .= '%#SLRight#' . SLEncoding() let l:s .= '%#SLFtype# %y ' let l:s .= '%#SLRight# %l:%c %P ' return l:s