Skip to content

Instantly share code, notes, and snippets.

@CreaturePhil
Last active May 9, 2024 22:48
Show Gist options
  • Save CreaturePhil/da1f2eb92e6a4282685ed36f60e77cb9 to your computer and use it in GitHub Desktop.
Save CreaturePhil/da1f2eb92e6a4282685ed36f60e77cb9 to your computer and use it in GitHub Desktop.
vimrc version 10000
""
"" General
""
set nocompatible " No compatibility with vi, use vi iMproved
filetype plugin indent on " Load plugins according to filetype
syntax on " Enable syntax highlighting
set autoindent " Indent according to previous line
set expandtab " Use spaces instead of tabs
set softtabstop=4 " Tab key indents by 4 spaces.
set shiftwidth=4 " >> indents by 4 spaces
set backspace=indent,eol,start " Backspace works in insert mode
set ttyfast " Faster redrawing
set lazyredraw " Redraw when necessary
set clipboard+=unnamed " use the clipboards of vim and win
set paste " Paste from a windows or from vim
set noswapfile
set hidden " Switch between buffers without having to save first
set incsearch " Instant search two-way binding
set ignorecase
set smartcase " Override the ignorecase option if the search pattern caints uppercase chars
set wildmenu " Show tab completions on status line
set autochdir
if has("win32")
au GUIEnter * simalt ~x " Start maximized
endif
if has("gui_running")
" Turn off visual bells
autocmd GUIEnter * set vb t_vb=
endif
set foldmethod=syntax
set foldlevel=99 " Default to unfolded when opening files
""
"" Color scheme
""
set background=dark
syntax reset
" Core
hi Normal guifg=#a08563 guibg=#161616 ctermbg=0 ctermfg=137
hi Comment guifg=#7d7d7d ctermfg=102
hi Constant guifg=#6b8e23 ctermfg=64
hi Statement guifg=#cd950c gui=NONE ctermfg=172
hi Preproc guifg=#dab98f ctermfg=172
hi Special guifg=#6b8e23 ctermfg=64
hi Type guifg=#cd950c ctermfg=172 gui=NONE cterm=NONE
hi Cursor guibg=#40FF40 ctermbg=196
hi CursorLine guibg=#121e12 ctermbg=0
hi StatusLine guifg=#7d7d7d guibg=#161616 ctermbg=102 ctermfg=0 gui=NONE cterm=NONE
hi StatusLineNC guifg=#665c54 guibg=#161616 ctermbg=241 ctermfg=0 gui=NONE cterm=NONE
hi Visual guibg=#3a0000 ctermbg=235
hi Pmenu guifg=#161616 guibg=#7d7d7d ctermbg=102 ctermfg=0
hi PmenuSel guifg=#161616 guibg=#665c54 ctermbg=235 ctermfg=0
hi Todo guibg=#161616 guifg=#ff0000 ctermfg=196 ctermbg=137
autocmd Syntax * syn match Note /NOTE/ containedin=ALL
hi def link Note String
" Hide vertical bars in vertical split
hi LineNr guibg=bg
hi foldcolumn guibg=bg
hi VertSplit guibg=bg guifg=bg
" Extension
hi! link Identifier Statement
hi! link MatchParen Todo
hi! link SpecialKey Statement
hi! link NonText Statement
hi! link Directory Statement
hi! link ErrorMsg WarningMsg
hi! link Question Statement
hi! link WildMenu Visual
hi! link LineNr String
hi! link Search Visual
hi! link Folded Visual
hi! link TabLine PmenuSel
hi! link TabLineSel Visual
hi! link TabLineFill Normal
hi! link Title Statement
""
"" UI
""
set guioptions-=m " Remove menu bar
set guioptions-=T " Remove Toolbar
" Remove Scrollbars
set guioptions-=r
set guioptions-=L
" Better looking tabs
set guiheadroom=0
set guioptions-=e
let g:netrw_banner=0 " Remove `:e .` info header
set laststatus=0 " Hide statusline
set guicursor=a:blinkon0 " Stop blinking cursor
set rulerformat=%l,%v
set cursorline
if has('win32')
set guifont=Droid_Sans_Mono:h10:cANSI:qDRAFT
else
set guifont=monospace
endif
""
"" Key Mappings
""
""function! CleverTab()
"" if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
"" return "\<Tab>"
"" else
"" return "\<C-N>"
"" endif
""endfunction
""inoremap <Tab> <C-R>=CleverTab()<CR>
nnoremap B :b#<CR>
nnoremap <Tab> <C-w>w
function! FindSourceOrHeaderFile()
let l:file_name = expand('%:t')
let l:file_ext = expand('%:e')
let l:file_ext_len = len(file_ext)
let l:full_ext_len = file_ext_len + 2
let l:name = file_name[:-full_ext_len]
if file_ext =~ "c" || file_ext =~ "cpp"
execute 'find ' . name . '.h'
else
execute 'find ' . name . '.cpp'
endif
endfunction
nnoremap H :call FindSourceOrHeaderFile()<CR>
nnoremap J <C-D>
vnoremap J <C-D>
nnoremap K <C-U>
vnoremap K <C-U>
" Make cnext loop back to the beginning
command! Cnext try | cnext | catch | cfirst | catch | endtry
nnoremap <F11> :Cnext<CR>
" Leader shortcuts
let mapleader=" "
nnoremap <leader>a :argadd **/*.cpp<CR>:argadd **/*.h<CR>
nnoremap <leader>l :set nomore <Bar> :ls <Bar> :set more <CR>:b<Space>
nnoremap <leader>e :e <C-d>
if has("win32")
nnoremap <leader>u :e $VIMRUNTIME/../_vimrc<CR>
else
nnoremap <leader>u :e ~/.vimrc<CR>
endif
cnoreabbrev Vsp vsp
function! MoveToBottomWindow()
wincmd J
resize 35
endfunction
nnoremap <leader>q :copen<CR>:call MoveToBottomWindow()<CR>
" ripgrep source code navigation
if executable("rg")
set grepprg=rg\ --vimgrep\ --no-heading
set grepformat=%f:%l:%c:%m,%f:%l:%m
" Automatically open quickfix window after performing grep
command! -nargs=+ F execute 'silent grep!' <q-args> | copen | call MoveToBottomWindow() | redraw!
nnoremap <leader>f "zyiw:exe "silent grep " . @z . " -g \"*.{c,cpp,h}\""<CR>:copen<CR>:call MoveToBottomWindow()<CR>
endif
autocmd FileType qf nnoremap <buffer> <CR> <CR>:cclose<CR>
" Projects
nnoremap <leader>1 :e w:\tp\win32_tp.cpp<CR>
set makeprg=build.bat
nnoremap <leader>c :Make<CR>
" Highlight all instances of word under cursor, when idle.
" Useful when studying strange source code.
" Type z/ to toggle highlighting on/off.
nnoremap z/ :if AutoHighlightToggle()<Bar>set hls<Bar>endif<CR>
function! AutoHighlightToggle()
let @/ = ''
if exists('#auto_highlight')
au! auto_highlight
augroup! auto_highlight
setl updatetime=4000
echo 'Highlight current word: off'
return 0
else
augroup auto_highlight
au!
au CursorHold * let @/ = '\V\<'.escape(expand('<cword>'), '\').'\>'
augroup end
setl updatetime=100
echo 'Highlight current word: ON'
return 1
endif
endfunction
" Automatically append closing characters
""inoremap { {}<Left>
""inoremap {<CR> {<CR>}<Esc>O
""inoremap {{ {
""inoremap {} {}
""
""inoremap ( ()<Left>
""inoremap <expr> ) strpart(getline('.'), col('.')-1, 1) == ")" ? "\<Right>" : ")"
""
""inoremap [ []<Left>
""inoremap <expr> ] strpart(getline('.'), col('.')-1, 1) == "]" ? "\<Right>" : "]"
""
""inoremap <expr> ' strpart(getline('.'), col('.')-1, 1) == "\'" ? "\<Right>" : "\'\'\<Left>"
""inoremap <expr> " strpart(getline('.'), col('.')-1, 1) == "\"" ? "\<Right>" : "\"\"\<Left>"
" Plugins
if !empty(glob("~/.vim/bundle/Vundle.vim"))
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'ervandew/supertab'
Plugin 'terryma/vim-multiple-cursors'
Plugin 'jiangmiao/auto-pairs'
Plugin 'tpope/vim-dispatch'
call vundle#end()
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment