diff options
| author | Justine Smithies <justine@smithies.me.uk> | 2026-01-25 16:20:11 +0000 |
|---|---|---|
| committer | Justine Smithies <justine@smithies.me.uk> | 2026-01-25 16:20:11 +0000 |
| commit | f8a17e307498cb3dc7f2352bdd3ab6f940a07e0f (patch) | |
| tree | f9b75058ab7ed88146f3bae10d6cb842530f6322 /.vimrc | |
| parent | 4bc27096b1959f2831d7848a1c4f82d56928add0 (diff) | |
Initial Commit
Diffstat (limited to '.vimrc')
| -rw-r--r-- | .vimrc | 257 |
1 files changed, 257 insertions, 0 deletions
@@ -0,0 +1,257 @@ +set nocompatible " This fixes the problem where arrow keys do not function properly on some systems. +let mapleader=' ' " Use space for leader key + +" General visual look of Vim +set number +set ruler +set noerrorbells +set laststatus=2 +set noshowmode " Don't show mode in bottom status line +let &fillchars ..= ',eob: ' " Hide tildes at EOF +set splitbelow splitright +set cursorline " Highlight the active cursor line +set termguicolors +colorscheme gruvbox + +" Clipboard +set clipboard=unnamedplus + +" Text searching options +set incsearch +set ignorecase +set smartcase +set showmatch + +" Syntax and formatting +syntax on +set encoding=utf-8 +set hidden + +" Tabs and indenting +set smartindent +set tabstop=4 +set shiftwidth=4 +set softtabstop=4 +set expandtab +set noshiftround +set scrolloff=3 + +" Command line completion options +set showcmd +set wildmenu +filetype plugin on +set omnifunc=syntaxcomplete#Complete +set completeopt=menuone,noselect " Don't autoselect the completion + +" Setup undo history +if !isdirectory($HOME."/.vim") + call mkdir($HOME."/.vim", "", 0770) +endif +if !isdirectory($HOME."/.vim/undo-dir") + call mkdir($HOME."/.vim/undo-dir", "", 0700) +endif +set undodir=~/.vim/undo-dir +set undofile + +" Colors +set background=dark +hi Normal guibg=NONE ctermbg=NONE " Set background transparent +" Setup terminal with gruvbox dark +let g:terminal_ansi_colors = [ + \ '#282828', '#cc241d', + \ '#98971a', '#d79921', + \ '#458588', '#b16286', + \ '#689d6a', '#a89984', + \ '#928374', '#fb4934', + \ '#b8bb26', '#fabd2f', + \ '#83a598', '#d3869b', + \ '#8ec07c', '#ebdbb2', + \] + +" Setup netrw +let g:netrw_banner = 0 +let g:netrw_liststyle = 3 +let g:netrw_browse_split = 3 +let g:netrw_altv = 1 +let g:netrw_winsize = 25 + +" Setup custom statusline +function! GitBranch() + return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'") +endfunction + +function! StatuslineGit() + let l:branchname = GitBranch() + return strlen(l:branchname) > 0?' '.l:branchname.' ':'' +endfunction + +function! StatuslineMode() + let l:mode=mode() + if l:mode==#"n" + return "Normal" + elseif l:mode==#"v" + return "Visual" + elseif l:mode==#"V" + return "Visual line" + elseif l:mode==#"\<C-V>" + return "Visual block" + elseif l:mode==#"i" + return "Insert" + elseif l:mode==#"R" + return "Replace" + elseif l:mode==#"s" + return "Select" + elseif l:mode==#"t" + return "Terminal" + elseif l:mode==#"c" + return "Enter command" + elseif l:mode==#"!" + return "Shell" + endif +endfunction + +let g:mode_colors = { + \ 'n': 'StatusLineSection', + \ 'v': 'StatusLineSectionV', + \ "\<C-V>": 'StatusLineSectionV', + \ 'i': 'StatusLineSectionI', + \ 'c': 'StatusLineSectionC', + \ 'r': 'StatusLineSectionR', + \ 's': 'StatusLine', + \ 't': 'StatusLineNC' + \ } + +fun! StatusLineRenderer() + let hl = '%#' . get(g:mode_colors, tolower(mode()), g:mode_colors.n) . '#' + + return hl + \ . ' %{StatuslineMode()} ' + \ . '%#DiffAdd#' + "\ . '%{StatuslineGit()}' + \ . '%#DiffAdd#' + \ . ' %F ' + \ . (&readonly ? ' r ' : '') + \ . (&modified ? ' + ' : '') + \ . '%#CursorColumn#%=' + \ . ' %Y ' + \ . '%#DiffAdd#' + \ . ' %{&fileencoding?&fileencoding:&encoding}' + \ . ' [%{&fileformat}]' + \ . ' %p%%' + \ . ' %l:%c ' +endfun + +fun! <SID>StatusLineHighlights() + hi StatusLine ctermbg=8 guibg=#313131 ctermfg=15 guifg=#cccccc + hi StatusLineNC ctermbg=0 guibg=#313131 ctermfg=8 guifg=#999999 + hi StatusLineSection ctermbg=11 guibg=#928374 ctermfg=0 guifg=#000000 + hi StatusLineSectionC ctermbg=8 guibg=#b8bb26 ctermfg=0 guifg=#333333 + hi StatusLineSectionI ctermbg=10 guibg=#83a598 ctermfg=0 guifg=#000000 + hi StatusLineSectionV ctermbg=12 guibg=#fabd2f ctermfg=0 guifg=#000000 + hi StatusLineSectionR ctermbg=12 guibg=#fb4934 ctermfg=0 guifg=#000000 +endfun + +call <SID>StatusLineHighlights() + +" only set default statusline once on initial startup. +" ignored on subsequent 'so $MYVIMRC' calls to prevent +" active buffer statusline from being 'blurred'. +if has('vim_starting') + let &statusline = ' %F%= %l:%c ' +endif + +augroup vimrc + au! + " show focussed buffer statusline + au FocusGained,VimEnter,WinEnter,BufWinEnter * + \ setlocal statusline=%!StatusLineRenderer() + + " show blurred buffer statusline + au FocusLost,VimLeave,WinLeave,BufWinLeave * + \ setlocal statusline& + + " restore statusline highlights on colorscheme update + au Colorscheme * call <SID>StatusLineHighlights() +augroup END + +" Setup BufferLine with Tabs +set showtabline=2 + +function! SpawnBufferLine() + let s = '' + + " Get the list of buffers. Use bufexists() to include hidden buffers + let bufferNums = filter(range(1, bufnr('$')), 'buflisted(v:val)') + " Making a buffer list on the left side + for i in bufferNums + " Highlight with yellow if it's the current buffer + let s .= (i == bufnr()) ? ('%#TabLineSel#') : ('%#TabLine#') + let s .= i . ' ' " Append the buffer number + if bufname(i) == '' + let s .= '[No Name]' " Give a name to a new buffer + endif + if getbufvar(i, "&modifiable") + let s .= fnamemodify(bufname(i), ':t') " Append the file name + " let s .= pathshorten(bufname(i)) " Use this if you want a trimmed path + " If the buffer is modified, add + and separator. Else, add separator + let s .= (getbufvar(i, "&modified")) ? (' [+] | ') : (' | ') + else + let s .= fnamemodify(bufname(i), ':t') . ' [RO] | ' " Add read only flag + endif + endfor + let s .= '%#TabLineFill#%T' " Reset highlight + + let s .= '%=' " Spacer + + " Making a tab list on the right side + for i in range(1, tabpagenr('$')) " Loop through the number of tabs + " Highlight with yellow if it's the current tab + let s .= (i == tabpagenr()) ? ('%#TabLineSel#') : ('%#TabLine#') + let s .= '%' . i . 'T ' " set the tab page number + let s .= i . '' " set page number string + endfor + let s .= '%#TabLineFill#%T' " Reset highlight + return s +endfunction + +set tabline=%!SpawnBufferLine() " Assign the tabline + +" Add UpdateVimPackages command using the internal package system of vim +function! UpdatePackages() + " Gather all top-level package directories from both start and opt + let l:packages = globpath('~/.vim/pack/*/start/*', '', 0, 1) + globpath('~/.vim/pack/*/opt/*', '', 0, 1) + + " Open a new tab for output + tabnew | setlocal buftype=nofile | setlocal bufhidden=delete | setlocal noswapfile + setlocal nonumber " Disable line numbers + setlocal norelativenumber " Disable relative line numbers + call setline(1, ['Updating Vim Packages...'] + repeat([''], 9)) + + let l:output = [] + for package in l:packages + let l:cmd = 'cd ' . package . ' && git pull' + let l:result = system(l:cmd) + + " Remove trailing newlines from the command output + let l:result = substitute(l:result, '\n\+$', '', '') + + " Extract text between slashes from package directory + let l:package_name = matchstr(package, '/\zs[^/]\+/$') + let l:package_name = substitute(l:package_name, '/\zs$\S\+$\ze/', '\1', '') + " Remove the last slash if it exists + let l:package_name = substitute(l:package_name, '/\s*$', '', '') + +" Append the full command output to the list + call add(l:output, package_name . ': ' . l:result) + endfor + + " Show the collected output starting from line 3 + call setline(3, l:output) +endfunction + +command! UpdateVimPackages call UpdatePackages() + +" To add plugins see examples below +" git clone https://github.com/BourgeoisBear/clrzr ~/.vim/pack/plugins/start/clrzr +" +" git clone https://github.com/morhetz/gruvbox ~/.vim/pack/colorschemes/opt/gruvbox |
