Skip to content

Instantly share code, notes, and snippets.

@yankcrime
Last active July 2, 2024 10:45
Show Gist options
  • Save yankcrime/3d5c73908ae697cc9e6f6082df3316a0 to your computer and use it in GitHub Desktop.
Save yankcrime/3d5c73908ae697cc9e6f6082df3316a0 to your computer and use it in GitHub Desktop.
MVP .vimrc, pilfered from @romainl
" filetype support
filetype plugin indent on
syntax on
" because it's there
runtime macros/matchit.vim
" various settings
set autoindent
set backspace=indent,eol,start
set complete+=d
set foldlevelstart=999
set foldmethod=indent
set grepprg=LC_ALL=C\ grep\ -nrsH
set hidden
set incsearch
" set mouse=a
set noswapfile
set path& | let &path .= "**"
set ruler
set shiftround
set shiftwidth=0
let &softtabstop = &tabstop
set tags=./tags;,tags;
set wildcharm=<C-z>
set wildmenu
set wildmode=full
" various autocommands
augroup minivimrc
autocmd!
" automatic location/quickfix window
autocmd QuickFixCmdPost [^l]* cwindow
autocmd QuickFixCmdPost l* lwindow
autocmd VimEnter * cwindow
" various adjustments of the default colorscheme
autocmd ColorScheme * hi ModeMsg cterm=NONE ctermbg=green ctermfg=black
\ hi Search cterm=NONE ctermbg=yellow ctermfg=black
\ hi StatusLineNC cterm=bold ctermbg=darkgrey
\ hi Visual cterm=NONE ctermbg=white ctermfg=darkblue
" Git-specific settings
autocmd FileType gitcommit nnoremap <buffer> { ?^@@<CR>|nnoremap <buffer> } /^@@<CR>|setlocal iskeyword+=-
augroup END
" commands for adjusting indentation rules manually
command! -nargs=1 Spaces execute "setlocal tabstop=" . <args> . " shiftwidth=" . <args> . " softtabstop=" . <args> . " expandtab" | setlocal ts? sw? sts? et?
command! -nargs=1 Tabs execute "setlocal tabstop=" . <args> . " shiftwidth=" . <args> . " softtabstop=" . <args> . " noexpandtab" | setlocal ts? sw? sts? et?
" juggling with jumps
nnoremap ' `
" juggling with files
nnoremap ,f :find *
nnoremap ,s :sfind *
nnoremap ,v :vert sfind *
nnoremap ,t :tabfind *
" juggling with buffers
nnoremap ,b :buffer *
nnoremap ,B :sbuffer *
nnoremap <PageUp> :bprevious<CR>
nnoremap <PageDown> :bnext<CR>
nnoremap <BS> :buffer#<CR>
" juggling with tags
nnoremap ,j :tjump /
nnoremap ,p :ptjump /
" juggling with definitions
nnoremap ,d :dlist /
nnoremap [D [D:djump<Space><Space><Space><C-r><C-w><S-Left><Left>
nnoremap ]D ]D:djump<Space><Space><Space><C-r><C-w><S-Left><Left>
" juggling with matches
nnoremap ,i :ilist /
nnoremap [I [I:ijump<Space><Space><Space><C-r><C-w><S-Left><Left><Left>
nnoremap ]I ]I:ijump<Space><Space><Space><C-r><C-w><S-Left><Left><Left>
" juggling with changes
nnoremap ,; *``cgn
nnoremap ,, #``cgN
" juggling with quickfix entries
nnoremap <End> :cnext<CR>
nnoremap <Home> :cprevious<CR>
" super quick search and replace
nnoremap <Space><Space> :'{,'}s/\<<C-r>=expand("<cword>")<CR>\>/
nnoremap <Space>% :%s/\<<C-r>=expand("<cword>")<CR>\>/
" better completion menu
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap ,, <C-n><C-r>=pumvisible() ? "\<lt>Down>\<lt>C-p>\<lt>Down>\<lt>C-p>" : ""<CR>
inoremap ,: <C-x><C-f><C-r>=pumvisible() ? "\<lt>Down>\<lt>C-p>\<lt>Down>\<lt>C-p>" : ""<CR>
inoremap ,= <C-x><C-l><C-r>=pumvisible() ? "\<lt>Down>\<lt>C-p>\<lt>Down>\<lt>C-p>" : ""<CR>
" pair expansion on the cheap
inoremap (<CR> (<CR>)<Esc>O
inoremap (; (<CR>);<Esc>O
inoremap (, (<CR>),<Esc>O
inoremap {<CR> {<CR>}<Esc>O
inoremap {; {<CR>};<Esc>O
inoremap {, {<CR>},<Esc>O
inoremap [<CR> [<CR>]<Esc>O
inoremap [; [<CR>];<Esc>O
inoremap [, [<CR>],<Esc>O
" smooth grepping
command! -nargs=+ -complete=file_in_path -bar Grep silent! grep! <args> | redraw!
" smooth searching
cnoremap <expr> <Tab> getcmdtype() == "/" \|\| getcmdtype() == "?" ? "<CR>/<C-r>/" : "<C-z>"
cnoremap <expr> <S-Tab> getcmdtype() == "/" \|\| getcmdtype() == "?" ? "<CR>?<C-r>/" : "<S-Tab>"
" smooth listing
cnoremap <expr> <CR> <SID>CCR()
function! s:CCR()
command! -bar Z silent set more|delcommand Z
if getcmdtype() == ":"
let cmdline = getcmdline()
if cmdline =~ '\v\C^(dli|il)' | return "\<CR>:" . cmdline[0] . "jump " . split(cmdline, " ")[1] . "\<S-Left>\<Left>\<Left>"
elseif cmdline =~ '\v\C^(cli|lli)' | return "\<CR>:silent " . repeat(cmdline[0], 2) . "\<Space>"
elseif cmdline =~ '\C^changes' | set nomore | return "\<CR>:Z|norm! g;\<S-Left>"
elseif cmdline =~ '\C^ju' | set nomore | return "\<CR>:Z|norm! \<C-o>\<S-Left>"
elseif cmdline =~ '\v\C(#|nu|num|numb|numbe|number)$' | return "\<CR>:"
elseif cmdline =~ '\C^ol' | set nomore | return "\<CR>:Z|e #<"
elseif cmdline =~ '\v\C^(ls|files|buffers)' | return "\<CR>:b"
elseif cmdline =~ '\C^marks' | return "\<CR>:norm! `"
elseif cmdline =~ '\C^undol' | return "\<CR>:u "
else | return "\<CR>" | endif
else | return "\<CR>" | endif
endfunction
" statusline
set laststatus=2
set statusline=%t\ %m%r%h%w%=\ %{&ft}\ %{&ff}\ %{&fenc}\ %l,%v\ -\ %L
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment