Skip to content

Instantly share code, notes, and snippets.

@Zerophase
Created March 6, 2018 22:20
Show Gist options
  • Save Zerophase/7ccd1abafe5a80cc860d65adb6c4db94 to your computer and use it in GitHub Desktop.
Save Zerophase/7ccd1abafe5a80cc860d65adb6c4db94 to your computer and use it in GitHub Desktop.
Vim config
" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <[email protected]>" Last change: 2016 Apr 05
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for Amiga: s:.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
" for OpenVMS: sys$login:.vimrc
" When started as "evim", evim.vim will already have done these settings.
runtime! archlinux.vim
if v:progname =~? "evim"
finish
endif
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'christoomey/vim-tmux-navigator'
Plugin 'christoomey/vim-tmux-runner'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'rking/ag.vim'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-repeat'
Plugin 'tpope/vim-rails'
Plugin 'tpope/vim-commentary'
Plugin 'thoughtbot/vim-rspec'
Plugin 'tpope/vim-dispatch'
Plugin 'scrooloose/nerdtree'
Plugin 'Matt-Deacalion/vim-systemd-syntax'
Plugin 'ervandew/supertab'
Plugin 'trusktr/seti.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'roman/golden-ratio'
Plugin 'romainl/flattened'
Plugin 'morhetz/gruvbox'
call vundle#end()
filetype plugin indent on
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
let g:ctrlp_user_command = 'ag %s -l --hidden --nocolor -g ""'
let g:ctrlp_usr_caching = 0
if has("vms")
set nobackup " do not keep a backup file, use versions instead
else
set backup " keep a backup file (restore to previous version)
set undofile " keep an undo file (undo changes after closing)
endif
set history=1000 " keep 1000 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")
" Don't use Ex mode, use Q for formatting
map Q gq
" tmux interferes with this command figure out
" how to get around and use ctrl s
" interferes with navigating to help tags
nmap <C-j>:w <cr>
nmap 0 ^
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" makes it easier to move through wrapped lines
nmap k gk
nmap j gj
" Switch syntax highlighting on when the terminal has colors or when using the
" GUI (which always has colors).
if &t_Co > 2 || has("gui_running")
syntax on
" I like highlighting strings inside C comments.
let c_comment_strings=1
endif
let mapleader="\<Space>"
nmap <leader>vr :sp $MYVIMRC<cr>
nmap<leader>so :source $MYVIMRC<cr>
map <leader>v :vnew <C-R>=escape(expand("%:p:h"), ' ') . '/'<CR>
map <leader>vi :tabe ~/.vimrc<CR>
" copies entire file into system registry
map<leader>co ggVG"*y
" splits on rails database schema
map <leader>sc :sp db/schema.rb<cr>
map <leader>i mmgg=G`m<cr>
map <leader>p :set paste<CR>o<esc>"*]p:set nopaste<cr>
" saves when exiting insert mode figure out how to make C-s work with tmux
" interferes with navigating to help tags
imap <C-j> <esc>:w <CR>
imap jk <esc>
imap kj <esc>
" wrap the below line with a check for the vim tmux runner.
nnoremap<leader>irb :VtrOpenRunner{'orientation':'h', 'percentage': 50, 'cmd': 'irb'}<cr>
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin on
autocmd filetype help nmap <buffer> q :q<cr>
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
autocmd VimResized * :wincmd =
" zoom a vim pane, <C-w>= to rebalance
nnoremap <leader>- :wincmd _<cr>:wincmd \|<cr>
nnoremap <leader>= :wincmd =<cr>
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
autocmd FileType python set breakindentopt=shift:4
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") >= 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
if has('langmap') && exists('+langnoremap')
" Prevent that the langmap option applies to characters that result from a
" mapping. If unset (default), this may break plugins (but it's backward
" compatible).
set langnoremap
endif
" move these to general setting
set linebreak
set whichwrap=b,s,<,>,[,]
set number
set relativenumber
set spell
set nocompatible "don't maintain compatibility with vi
set hidden " Allow buffer changes w/o saving
set autoread " load file from disk, ie for git reset
set nocompatible
set lazyredraw " Don't update while executing macros
set backspace=indent,eol,start " change backspace behavior
set scrolloff=4 " keep 4 lines below the cursor
" tab behavior TODO look up how to customize tab behavior depending on lang
set tabstop=2
set softtabstop=2
set shiftwidth=2
set noexpandtab " use autocmd for owriting settings on different
" filetypes
set autowrite
setlocal spell spelllang=en_us
" Allow saving of files as sudo when I forget to start vim using sudo.
cmap w!! w !sudo tee > /dev/null %
set guiheadroom=0
" Add optional packages.
"
" The matchit plugin makes the % command work better, but it is not backwards
" compatible.
packadd matchit
set secure " hopefully he talks about this
set modelines=1
set nobackup
" settings for correcting common command typos
command! Q q
command! Qall qall
command! QA qall
command! E e
set t_8f=[38;2;%lu;%lu;%lum
set t_8b=[48;2;%lu;%lu;%lum
colorscheme gruvbox
set background=dark
let g:gruvbox_contrast_dark = 'hard'
highlight Normal ctermbg=NONE guibg=NONE
highlight NonText ctermbg=NONE guibg=NONE
set termguicolors
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_setp = '|'
let g:airline_theme = 'raven'
set ttyfast
set mouse=a
set ttymouse=xterm2
" search settings
set incsearch
set hlsearch
nmap <leader>h :nohlsearch<cr>
set ignorecase
set smartcase " search pattern has a capital letter than case sensitive used
" g + / or if search already started ctrl + f allows editing of search
" vimscript behavior
" strings starting with a number have truth value of true.
" strings without numbers are false
set clipboard=unnamedplus
function MergeTabs()
if tabpagenr() == 1
return
endif
let bufferName = bufname("%")
if tabpagenr("$") == tabpagenr()
close!
else
close!
tabprev
endif
vsplit
" Arguments to internal commands don't get commas.
" execute adds spaces for you, unless you use '.'
buffer bufferName
endfunction
function ExtractUrlFromCurrentLine()
return matchstr(getline(","), "http[^ ]*")
endfunction
" blah blah blah http://google.com blarg barg
function! OpenUrlOnCurrentLineInBrowser() " doesn't really work
let url = ExtractUrlFromCurrentLine()
exec 'silent !google-chrome-stable' url '&'
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment