Skip to content

Instantly share code, notes, and snippets.

@serge-rgb
Created May 19, 2018 21:34
Show Gist options
  • Save serge-rgb/cc2266d1e1e13412782493835e065f1b to your computer and use it in GitHub Desktop.
Save serge-rgb/cc2266d1e1e13412782493835e065f1b to your computer and use it in GitHub Desktop.
filetype on
filetype plugin on
set nocompatible
" Setup notes:
" (git should be installed)
" git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
" or (windows): (needs curl script. see vundle site.)
" git clone https://github.com/gmarik/Vundle.vim.git %userprofile%/vimfiles/bundle/Vundle.vim
if has("win32")
set rtp+=~/vimfiles/bundle/Vundle.vim
elseif has("unix")
set rtp+=~/.vim/bundle/Vundle.vim/
endif
if has('win32')
" Win64:
" veegee vim.
" LuaBinaries.sf.net, download x64 dll into vim74 dir.
let path='~/vimfiles/bundle'
call vundle#begin(path)
else
call vundle#begin()
endif
Plugin 'gmarik/Vundle.vim'
"==== Vim editing steroids
Plugin 'auto-pairs'
Plugin 'godlygeek/tabular'
Plugin 'junegunn/goyo.vim'
Plugin 'justinmk/vim-gtfo'
Plugin 'lokaltog/vim-easymotion'
Plugin 'surround.vim'
Plugin 'tpope/vim-capslock'
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-dispatch'
Plugin 'tpope/vim-repeat'
Plugin 'tpope/vim-sleuth'
Plugin 'tpope/vim-speeddating'
Plugin 'tpope/vim-unimpaired'
" Plugin 'vim-airline/vim-airline'
" Plugin 'vim-airline/vim-airline-themes'
" Plugin 'powerline/powerline', {'rtp': 'powerline/bindings/vim/'}
Plugin 'yankring.vim'
"==== IDE stuff
" Plugin 'Shougo/neocomplete.vim'
Plugin 'ervandew/supertab'
" Plugin 'jeaye/color_coded'
Plugin 'scrooloose/nerdtree'
" Plugin 'scrooloose/syntastic'
Plugin 'a.vim'
" Plugin 'abudden/taghighlight-automirror'
" Plugin 'ludovicchabant/vim-gutentags'
Plugin 'majutsushi/tagbar'
" Plugin 'mileszs/ack.vim'
Plugin 'tpope/vim-fugitive'
" Plugin 'valloric/YouCompleteMe'
Plugin 'maralla/completor.vim'
Plugin 'wincent/Command-T' " using it for its great fuzzy tag search
" Plugin 'ctrlpvim/ctrlp.vim' " ctrlp for all other fuzzy searches because it doesn't have a huge list of deps.
"==== Random lang support
"Plugin 'beyondmarc/glsl.vim'
Plugin 'tpope/vim-markdown'
"Plugin 'petRUShka/vim-opencl'
" Plugin 'PProvost/vim-ps1'
"Plugin 'rust-lang/rust.vim'
" Plugin 'raichoo/haskell-vim'
"==== Rainbows
" Plugin 'notpratheek/vim-luna'
" Plugin 'rhysd/vim-color-spring-night'
" Plugin 'vim-scripts/louver.vim'
Plugin 'albertorestifo/github.vim'
Plugin 'altercation/vim-colors-solarized'
Plugin 'arcticicestudio/nord-vim'
Plugin 'hzchirs/vim-material'
Plugin 'jnurmine/Zenburn.git'
Plugin 'mhinz/vim-startify'
Plugin 'nightsense/seabird'
Plugin 'reedes/vim-colors-pencil'
Plugin 'romainl/Apprentice'
Plugin 'roosta/vim-srcery'
Plugin 'tomasr/molokai'
Plugin 'NLKNguyen/papercolor-theme'
" Plugin 'itchyny/lightline.vim'
Plugin 'nightsense/simplifysimplify'
call vundle#end()
let g:sergeAtWork = 0
source ~/local.vim
" ============================================================
" ==== Sane vim defaults ====
" ============================================================
let mapleader=','
" Remap \ as , for an extra leader
nmap \ ,
" au BufNewFile,BufRead *.c,*.cpp,*.h :sp tags<CR>:%s/^\([^ :]*:\)\=\([^ ]*\).*/syntax keyword Tag \2/<CR>:wq! tags.vim<CR>/^<CR>
" syntax off
" au BufNewFile,BufRead * syntax off
set backspace=2
set history=1024 " Lines of history
filetype plugin on
filetype indent on
set shellslash " Always forward slashes.
set autoread " Reload when I modify the file elsewhere.
set cursorline " Highlight current line.
" set relativenumber " Easier to move around
" search ---
set hlsearch
" clear highlight
" nnoremap <CR> :noh<cr><cr>
nnoremap <leader>j :noh<cr>
set incsearch
set ignorecase
set smartcase
" Hide buffers, don't close them
set hidden
set nobackup
set nowritebackup
set noswapfile
set wildmenu " command line completion
set laststatus=2 "Always display status line
set encoding=utf-8
set cmdheight=2 " avoid hit-enter promts
" Don't mess with my window. Use buffer in already open tab. Otherwise, split
set switchbuf+=usetab
" Do not redraw when executing macros.
set lazyredraw
" Don't beep
set visualbell
set virtualedit+=all
" Statusline with fugitive info
" set statusline=%<%f\ %h%m%r%{fugitive#statusline()}%=%-14.(%l,%c%V%)\ %P
set statusline=%h%w\ %f%<\ %m%r%=%-50.(%{fugitive#statusline()}%)%=%-20.(%l,%c%V\ \\\ %L%)\ %P
" Mostly using the preview window for Fugitive Git status
set previewheight=20
" Wrap enable/disable
set nowrap
" Wrap at word boundaries.
set sidescroll=5
set listchars+=precedes:<,extends:>
set linebreak
" Very special regex by default
noremap / /\v
" First column
nnoremap <leader>q <home>
" Window
" Ctrl-w is cumbersome
noremap <leader>w <C-w>
noremap <leader>w. <C-w>c
" Switch betweeen windows
noremap <C-h> <C-w>h
noremap <C-l> <C-w>l
noremap <C-k> <C-w>k
noremap <C-j> <C-w>j
" Splits
noremap <C-s> <C-w>s
noremap <C-v> <C-w>v
" incsearch - next match while searching
cnoremap <C-n> <cr>n
noremap <C-n> n
" ============================================================
" ==== Text edit remaps ====
" ============================================================
" F4 to repeat macro
noremap <F4> @@
" Saving
noremap <leader>s :w<cr>
" Swap Header/Impl
noremap <C-Tab> :A<cr>
noremap <leader>v :A<cr>
inoremap <C-Tab> <esc>:A<cr>
" make word Capitalized
noremap <leader>u ebgUl
" make word UPPERCASE
noremap <leader>U gUiw
" I can never find $ and ^
noremap <leader>e $
noremap <leader>a ^
" better tag jump
noremap <leader>g g<C-]>
inoremap <leader>g g<C-]>
" Tabular plugin common case
noremap <leader>t :Tabularize /=<cr>
" Nice to have when wrapping. Might possibly mess with other plugins and features.
noremap j gj
noremap k gk
" Insert mode ---
" ... Emacs style
inoremap <C-e> <esc>A
inoremap <C-a> <esc>I
inoremap <C-k> <esc>d$A
" Ctrl-Backspace should kill a word..
inoremap <C-BS> <C-W>
cnoremap <C-BS> <C-W>
" ============================================================
" ==== Functions ====
" ============================================================
" Global function to make LongLines do nothing
let g:no_longlines=0 ""
" For writing prose
function! LongLines()
if !g:no_longlines
set wrap
set linebreak
set nolist
set textwidth=0
set wrapmargin=0
set colorcolumn=0
set columns=90
set lines=60
set nocursorline
set spell
"Remap j and k to be visual
noremap j gj
noremap k gk
noremap <leader>e g$
noremap <leader>a g^
if has('win32')
"set guifont=DejaVu_Sans_Mono:h11
endif
if has('unix')
if has("macunix")
" set guifont=DejaVu\ Sans\ Mono\ for\ Powerline:h12
set guifont=DejaVu\ Sans\ Mono\ 12
else
set guifont=DejaVu\ Sans\ Mono\ 12
endif
endif
endif
endfunction
" Ctags + update tag highlighting
function! Index()
" silent ! ctags -R .
silent ! cscope -Rb
" :UpdateTypesFile
:cs reset
endfunction
" noremap <C-F12> :cal Index()<cr>
" set cscopetag " Use cscope instead of ctags when possible
" Commented out because cscope doesn't tend to work well with C++
" Map C-[ to find the caller of the function at point.
" noremap <C-[> :cs find c <C-r>=expand("<cword>")<CR><CR>
" Set the background based on the time.
function! SetDayColor()
python << EOF
import vim, time
hour = time.localtime().tm_hour
if hour <= 7 or hour >= 20:
vim.command("set background=dark\n")
else:
vim.command("set background=light\n")
EOF
endfunction
function! CopyPath()
let @*=@%
let @*.=":".line('.')
echo "Copyied path to clipboard."
endfunction
noremap <leader>l :call CopyPath()<cr>
function! SergeCStyle()
" C++ style
" set colorcolumn=81,101
" set colorcolumn=101
" No namespace indent, indent for case, unindent label block, no indent for
" public, private in classes
set cino=N-s,:s,l1,g0,(0,+8
set smarttab
set expandtab
set shiftwidth=3
set softtabstop=3
set tabstop=8
" set colorcolumn=110
"
" " Common types
" syn keyword sergeType u8 i8 u16 i16 u32 i32 u64 i64
" syn keyword sergeType f32 f64
" syn keyword sergeType b32
" hi def link sergeType Type
" Ctags Highlight plugin confuses colorschemes
hi link Member Identifier
" C++ remappings
" Auto-indent when pasting
"nnoremap p p=`]`]
endfunction
function! IugoCStyle()
" C++ style
" set colorcolumn=81,101
" set colorcolumn=101
" No namespace indent, indent for case, unindent label block, no indent for
" public, private in classes, C++ lambdas, case indent?
set cino=N-s,:s,l1,g0,(0,+8,j1
set smarttab
set expandtab
set shiftwidth=2
set softtabstop=2
set tabstop=8
" set colorcolumn=110
"
" " Common types
" syn keyword sergeType u8 i8 u16 i16 u32 i32 u64 i64
" syn keyword sergeType f32 f64
" syn keyword sergeType b32
" hi def link sergeType Type
" Ctags Highlight plugin confuses colorschemes
hi link Member Identifier
" C++ remappings
" Auto-indent when pasting
"nnoremap p p=`]`]
endfunction
let g:loop_win_size=0
function! LoopSize()
if g:loop_win_size == 0
cal Big()
elseif g:loop_win_size == 1
cal Bigger()
elseif g:loop_win_size == 2
cal Huge()
endif
let g:loop_win_size = (g:loop_win_size+1)%3
endfunction
noremap <F5> :cal LoopSize()<cr>
function! Vcope()
wincmd o
" vert topleft cope
vert rightb cope
wincmd =
endfunction
function! CloseHelpers()
" close preview
pclose
" close quickfix
cclose
NERDTreeClose
TagbarClose
wincmd =
endfunction
" ============================================================
" ==== Plugin Configuration ====
" ============================================================
" Auto-Pairs ---
let g:AutoPairsFlyMode=0
" NERDTree ---
noremap <F2> :NERDTreeToggle<cr>:wincmd =<cr>
" YankRing --- Remapping
let g:yankring_replace_n_pkey = "<leader>p"
let g:yankring_replace_n_nkey = "<leader>n"
" Autopairs --- Jump outside of scope mapping
noremap <C-space> <esc>:call AutoPairsJump()<cr>
inoremap <C-space> <esc>:call AutoPairsJump()<cr>a
" Supertab --- Go from top to bottom
let g:SuperTabDefaultCompletionType = '<c-n>'
" Tagbar --- mappings
map <f3> :TagbarOpenAutoClose<CR>
"CommandT
let g:CommandTMaxHeight = 30
" let g:CommandTFileScanner = 'find'
" noremap <leader>r :CommandTTag<CR>
noremap <leader>b :CommandTMRU<cr>
" noremap <C-f> :CommandT<cr>
noremap <C-p> :CommandT<cr>
" noremap <C-p> :CtrlPMixed<cr>
" noremap <leader>b :CtrlPBuffer<cr>
" noremap <leader>r :CtrlPTag<CR>
noremap <leader>r :CommandTTag<CR>
let g:tagbar_sort = 0
" Neocomplete
let g:neocomplete#enable_at_startup = 1
let g:neocomplete#enable_smart_case = 1
let g:neocomplete#sources#syntax#min_keyword_length = 2
" YouCompleteMe
let g:ycm_key_invoke_completion = '<C-n>'
let g:ycm_auto_trigger = 1
let g:ycm_filetype_specific_completion_to_disable = { 'c': 0, 'cpp': 0, 'python': 0 }
" Sleuth
let g:sleuth_automatic = 1
" Fugitive. Easy Git status
noremap <leader>d :Gstatus<cr>
" Easymotion mapping
map <space> <Plug>(easymotion-prefix)
nmap <Leader>f <Plug>(easymotion-overwin-f)
" Startify
let g:startify_bookmarks = [ '~/.vimrc', '/Volumes/job/todo', '/Volumes/job/log.txt' ]
" Commentary
autocmd FileType cpp setlocal commentstring=//\ %s
autocmd FileType c,cpp Sleuth
" Startify startup quotes.
let g:startify_custom_header_quotes = [
\ [' "The more pleasures a man captures,', ' the more masters he will have to serve.”', ' - Lucius Annaeus'],
\ [ ' In walking, just walk.', ' In sitting, just sit.', " Above all, don't wobble", ' -Yün-men' ]
\ ]
" ============================================================
" ==== Quickfix window ====
" ============================================================
imap <F1> <esc>
nmap <F1> <esc>
" if g:sergeAtWork:
" " Vim original errorformat:
" endif
set autowrite
" noremap <C-b> :wa<esc>:make<cr><cr>:cal Index()<cr>
" noremap <C-b> :wa<esc>:make<cr><cr>:silent! cal Index()<cr>
" noremap <C-b> :wa<esc>:make<cr>cal Vcope()<cr>
" inoremap <C-b> <esc>:wa<esc>:make<cr>cal Vcope()<cr>
noremap <C-b> :wa<esc>:Make<cr>
inoremap <C-b> <esc>:wa<esc>:Make<cr>
" Silver Searcher
noremap <F7> :grep "\b<C-r><C-w>\b"<cr>
inoremap <F7> :grep "\b<C-r><C-w>\b"<cr>
if g:sergeAtWork
set errorformat=%f:%l:%c:\ %m
noremap <F6> :grep ((struct\\|class).*\\b=expand(<C-r><C-w>)"\|(using\s+"<C-r><C-w>"))"<cr>
endif
" Go through errors in cwind
noremap <F8> :cnext<cr>
noremap <S-F8> :cprev<cr>
" noremap <F9> :crewind<cr>
noremap <F9> :cprev<cr>
inoremap <F8> <cr>:cnext<cr>
inoremap <S-F8> <cr>:cprev<cr>
" inoremap <F9> <cr>:crewind<cr>
" Open/close quickfix window
noremap <F10> :cal Vcope()<cr>
" noremap <S-F10> :cal Vcope()<cr>/error:<cr>
noremap <S-F10> :copen<cr>/error:<cr>
noremap <F11> :cal CloseHelpers()<cr>:wincmd =<cr>
noremap <esc> :cal CloseHelpers()<cr>:wincmd =<cr><esc>
noremap <S-F11> 40<C-W>>
noremap <C-F12> :Startify<cr>
" noremap <S-C-F8> :cclose<cr>
if g:sergeAtWork
if has("macunix")
noremap <F12> :cf ~/iugo/client/buildout<cr>
else
noremap <F12> :cf R:/buildout<cr>
endif
endif
set tags=./tags;
" ============================================================
" ==== File defaults (BufRead BufWrite etc) ====
" ============================================================
" Remove any trailing whitespace that is in the file
if !g:sergeAtWork
autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif
endif
" filetypes ---
"au BufNewFile,BufRead *.glsl set filetype=glsl430
au BufNewFile,BufRead *.glsl set filetype=cpp
au BufNewFile,BufRead *.cl set filetype=opencl
if g:sergeAtWork
au BufNewFile,BufRead *.cpp,*.cc,*.c,*.h,*.cl,*.glsl call IugoCStyle()
if has("win32")
" set makeprg=W:\build.bat
set makeprg=W:\send.bat
else
set makeprg=make
endif
else
au BufNewFile,BufRead *.cpp,*.cc,*.c,*.h,*.cl,*.glsl call MakeOrSingle()
au BufNewFile,BufRead *.py set makeprg=python\ %
au BufNewFile,BufRead *.rs set makeprg=cargo\ check
au BufNewFile,BufRead *.hs set makeprg=cabal\ build
endif
au FileType c,cpp,objc,objcpp map <buffer> K <C-w>g}
func! MakeOrSingle()
if filereadable("build.bat") && has("win32")
set makeprg=build
elseif filereadable("Makefile")
set makeprg=make
elseif filereadable("build/Makefile")
set makeprg=pushd\ build;\ make\ -j;\ popd
else
set makeprg=./%
endif
endfunc
" prose
let g:no_open_files=1
" au BufNewFile,BufRead *.txt,*.md,*.html if g:no_open_files | cal LongLines() | endif
au BufNewFile,BufRead * let g:no_open_files=0
" Use semantic highlighting for code
"au BufNewFile,BufRead,BufEnter *.cpp,*.cc,*.c,*.h,*.cl,*.glsl,*.py,*.lua SemanticHighlight
"au BufNewFile,BufRead,BufEnter *.cpp,*.cc,*.c,*.h,*.cl,*.glsl,*.py,*.lua noremap <leader>s :w<cr>:SemanticHighlight<cr>
" au BufNewFile * set ff=unix
" ============================================================
" ==== GUI and Init ====
" ============================================================
let g:loop_function_int=1 " 0 - Dark and high contrast
" 1 - Dark low contrast
" 2 - Light
function! LoopColorSchemes()
" let g:lightline = {}
if g:loop_function_int == 0 " Dark and high contrast
" let g:lightline.colorscheme = 'Tomorrow_Night'
" colorscheme apprentice
colorscheme srcery
" AirlineTheme base16_mocha
" colorscheme molokai
" AirlineTheme molokai
elseif g:loop_function_int == 1 " Dark low contrast
" colorscheme zenburn
" highlight CursorLine guibg=#2b2b2b
"
let g:nord_italic = 1
let g:nord_italic_comments = 1
let g:nord_comment_brightness = 16
" colorscheme nord
colorscheme simplifysimplify-dark
"colorscheme solarized
" AirlineTheme solarized
" colorscheme vim-material
" AirlineTheme material
elseif g:loop_function_int == 2 " Light
" let g:lightline.colorscheme = 'PaperColor'
" colorscheme seagull
set background=light
" colorscheme PaperColor
colorscheme solarized
" colorscheme github
endif
" if g:loop_function_int == 0 || g:loop_function_int == 1
" set nocursorline
" else
" set cursorline
" endif
let g:loop_function_int=g:loop_function_int + 1
let g:loop_function_int=g:loop_function_int % 3
" call lightline#init()
" call lightline#colorscheme()
" call lightline#update()
endfunction
noremap <leader>c :call LoopColorSchemes()<cr>
function! InitVim()
if has('win32')
" set shell=powershell
" set shellcmdflag=-c
" set shellpipe=>
" set shellredir=>
elseif has('unix')
" set makeprg=make
endif
"Look for the default cscope out file
cs add cscope.out
if executable('ag')
set grepprg=ag\ --nogroup\ --nocolor
endif
" Don't complete from tags. Too slow on my work laptop.
set cpt-=t
endfunction
function! Big()
" set columns=238
set columns=119
set lines=77
endfunction
function! Bigger()
set columns=238
set lines=104
endfunction
function! Huge()
set columns=359
set lines=104
endfunction
if g:sergeAtWork
call IugoCStyle()
else
call SergeCStyle()
endif
function! InitVimGui()
set lines=60 columns=100
"set lines=80 columns=211
set guioptions-=T "No toolbar
" Remove scrobars:
set guioptions-=r
set guioptions-=L
" No menu
" if has("unix")
" " Presumably on ubuntu, where the menu doesn't get in the way.
" else
set guioptions-=m
" endif
set t_vb=
autocmd! GUIEnter * set vb t_vb=
" Tagbar signature highlighting sucks
hi link TagbarSignature Statement
let g:molokai_original=1
"colorscheme molokai
"colorscheme zenburn
"colorscheme solarized
"colorscheme pencil
"colorscheme base16-monokai
"colorscheme default
"set background=dark
"colorscheme louver
if has("win32")
set guifont=DejaVu_Sans_Mono:h08
set enc=utf-8
else
if has("unix")
if has("macunix")
if g:sergeAtWork
set guifont=DejaVu\ Sans\ Mono:h12
else
set guifont=DejaVu\ Sans\ Mono:h13
endif
else
set guifont=DejaVu\ Sans\ Mono:h10
endif
endif
endif
if has("gui_macvim")
macm File.Open\.\.\. key=<nop>
macmenu &File.New\ Tab key=<nop>
endif
"call SetDayColor()
call LoopColorSchemes()
endfunction
autocmd VimEnter * :call InitVim()
autocmd GuiEnter * :call InitVimGui()
" Add errorformat for clang-cl on windows.
" set errorformat+=%f(%l\\,%c)%m
" Catch linker errors
" set errorformat+=%slinker%m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment