Skip to content

Instantly share code, notes, and snippets.

@internetimagery
Last active April 28, 2025 08:03
Show Gist options
  • Save internetimagery/c7515c497e5f37e0d5f09f2394c492f7 to your computer and use it in GitHub Desktop.
Save internetimagery/c7515c497e5f37e0d5f09f2394c492f7 to your computer and use it in GitHub Desktop.
Current vimrc base
" Install vim-plug with following command
" curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" Then ':PlugInstall' to install them
" Declare plugins
call plug#begin()
" Sensible Defaults
Plug 'tpope/vim-sensible' " Sensible defaults for various things
Plug 'roman/golden-ratio' " Resize split screen to fit active panel
Plug 'tpope/vim-commentary' " 'gc' to comment code 'gcc' comment line
Plug 'tpope/vim-unimpaired' " '[e' ']e' move lines up and down
Plug 'tpope/vim-repeat' " Allow custom tools to use '.' repeat function
Plug 'easymotion/vim-easymotion' " Jump to location '\\f' or '\\w'
Plug 'bronson/vim-visual-star-search' " Select text then can search with *
" Linting + Autocomplete
Plug 'prabirshrestha/vim-lsp' " Run language servers
Plug 'mattn/vim-lsp-settings' " Install language servers easily. Do so via ':LspInstallServer <name>' for instance ':LspInstallServer ruff'
" Light Theme
Plug 'woodyZootopia/flatwhite-vim'
" Dark Theme
Plug 'sonph/onehalf', { 'rtp': 'vim' }
" Bottom Bar
Plug 'vim-airline/vim-airline'
" Git integration
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
call plug#end()
" Theme
"colorscheme flatwhite
set cursorline
colorscheme onehalfdark
let g:airline_theme='onehalfdark'
if exists('+termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
" Keymaps
" Make Y consistent with C and D
map Y y$
" Reselect visual block after indent/outdent.
vnoremap < <gv
vnoremap > >gv
" Keep search pattern at the center of the screen.
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
nnoremap <silent> g* g*zz
" FileTypes
autocmd BufRead,BufNewFile wscript setfiletype python
" GUI
set cursorline " Faint line showing cursor (y axis)
set cursorcolumn " Faint line showing cursor (x axis)
set number relativenumber " Show line numbers and set relative to cursor when in normal mode
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
set scrolloff=7 " keep 3 lines when scrolling
set showcmd " display incomplete commands
set showmode " display current modes
set showmatch " jump to matches when entering parentheses
set matchtime=2 " tenths of a second to show the matching parenthesis
set hlsearch " highlight searches
let g:netrw_banner = 0 " Remove top banner on directory views
let g:netrw_liststyle = 3 " Display folders in a tree view
let ghregex='\(^\|\s\s\)\zs\.\S\+' " Hide dotfiles by default, see...
let g:netrw_list_hide=ghregex " ...https://vi.stackexchange.com/a/18678
" System
set hidden " Allow swapping of buffers with changes, without nagging.
set mouse=a " Enable mouse support
set nocompatible " Don't bother with vi compatibility
autocmd BufEnter * :checktime " Check if files need reloading when swapping buffer
set magic " For regular expressions turn magic on
set title " change the terminal's title
set nobackup " do not keep a backup file
set novisualbell noerrorbells " turn off visual bell
set visualbell t_vb= " turn off error beep/flash
set tm=500
set ignorecase " ignore case when searching
set smartcase " Case sensitive is search includes uppercase letter
set path+=** " Include all files in search path (fuzzy search lite)
autocmd CursorHoldI * stopinsert " Drop out of insert mode after 4 seconds idle
:command W w " Remap W to w, so accidental capitals writes too
" Enable smart switching between constructs (eg html tags etc) (built in plugin)
runtime macros/matchit.vim
" Strip extra whitespace
autocmd FileType c,cpp,java,go,php,javascript,puppet,python,rust,twig,xml,yml,perl autocmd BufWritePre <buffer> :call <SID>StripTrailingWhitespaces()
fun! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfun
" Use ripgrep if it is available when running :grep
if executable("rg")
set grepprg=rg\ --vimgrep\ --smart-case\ --hidden
set grepformat=%f:%l:%c:%m
endif
" Improve :grep experience. https://gist.github.com/romainl/56f0c28ef953ffc157f36cc495947ab3#enlightenment
" Run grep command in background without poluting terminal with output under 'Grep' function
function! Grep(...)
return system(join([&grepprg] + [expandcmd(join(a:000, ' '))], ' '))
endfunction
" Ensure autocomplete works
command! -nargs=+ -complete=file_in_path -bar Grep cgetexpr Grep(<f-args>)
command! -nargs=+ -complete=file_in_path -bar LGrep lgetexpr Grep(<f-args>)
" Open results window on search completion
augroup quickfix
autocmd!
autocmd QuickFixCmdPost cgetexpr cwindow
autocmd QuickFixCmdPost lgetexpr lwindow
augroup END
" Replace grep command with Grep function
cnoreabbrev <expr> grep (getcmdtype() ==# ':' && getcmdline() ==# 'grep') ? 'Grep' : 'grep'
cnoreabbrev <expr> gr (getcmdtype() ==# ':' && getcmdline() ==# 'gr') ? 'Grep' : 'grep'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment