Skip to content

Instantly share code, notes, and snippets.

@rands0n
Last active September 9, 2018 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rands0n/718b872d333c9788fce9dfe0878ca50e to your computer and use it in GitHub Desktop.
Save rands0n/718b872d333c9788fce9dfe0878ca50e to your computer and use it in GitHub Desktop.
.vimrc config
" =============================================================================
" Randson Oliveira .vimrc file
" -----------------------------------------------------------------------------
" Heavily inspired by: @millermedeiros, @scrooloose, @nvie, @gf3, @bit-theory.
" -----------------------------------------------------------------------------
" -----------------------------------------------------------------------------
" BEHAVIOR
" -----------------------------------------------------------------------------
nmap <Leader>ev :tabedit $MYVIMRC<cr> " Open .vimrc configuration when type ,ev
set nocompatible " Disable vi compatibility
filetype on " File type must be enabled first
filetype off " Force reloading *after* pathogen loaded
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'vim-scripts/IndentAnything'
Plugin 'editorconfig/editorconfig-vim'
Plugin 'wakatime/vim-wakatime'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'airblade/vim-gitgutter'
Plugin 'bronson/vim-trailing-whitespace'
Plugin 'Yggdroot/indentLine'
Plugin 'tpope/vim-vinegar'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'vim-scripts/bufkill.vim'
Plugin 'elzr/vim-json'
call vundle#end()
syntax enable " Enable syntax highlight
filetype plugin indent on
" Centralize backups, swapfiles and undo history
set backupdir=~/.vim/backups
set directory=~/.vim/swaps
if exists("&undodir")
set undodir=~/.vim/undo
endif
" Change mapleader to comma
let mapleader=','
let maplocalleader=';'
set spelllang=en_us " spell checking
set encoding=utf-8 nobomb " BOM often causes trouble, UTF-8 is awsum.
" --- performance / buffer ---
set hidden " can put buffer to the background without writing to disk, will remember history/marks.
set lazyredraw " don't update the display while executing macros
set ttyfast " Send more characters at a given time.
" --- history / file handling ---
set history=999 " Increase history (default = 20)
set undolevels=999 " Moar undo (default=100)
set autoread " reload files if changed externally
" --- backup and swap files ---
set nobackup
set nowritebackup
set noswapfile
" --- search / regexp ---
set gdefault " RegExp global by default
set magic " Enable extended regexes.
set hlsearch " highlight searches
set incsearch " show the `best match so far' astyped
set ignorecase smartcase " make searches case-insensitive, unless they contain upper-case letters
" --- keys ---
set backspace=indent,eol,start " allow backspacing over everything.
set esckeys " Allow cursor keys in insert mode.
set nostartofline " Make j/k respect the columns
" set virtualedit=all " allow the cursor to go in to 'invalid' places
set timeoutlen=500 " how long it wait for mapped commands
set ttimeoutlen=100 " faster timeout for escape key and others
" -----------------------------------------------------------------------------
" ----- UI
" -----------------------------------------------------------------------------
colorscheme atom-dark-256 " Set coloscheme to atom-dark
set guifont=Fira_Code:h17 " Set the default font family and size.
if has('gui_running')
set transp=0
endif
" Fake left padding for each window
set foldcolumn=0
hi foldcolumn guibg=bg
hi vertisplit guifg=bg guibg=bg " Get rid of ugly split borders
" Make splits default to below...
set splitbelow
set splitright " And the right, to be more natural
set macligatures " Set font ligatures for MacVim --> www
set t_Co=256 " 256 colors terminal
let &t_AB="\e[48;5;%dm"
let &t_AF="\e[38;5;%dm"
set number " Enable line numbers
set backupskip=/tmp/*,/private/tmp/* " Don't create backups when editing files in certain directories
set cursorline " Highlight cursor line
highlight LineNr guibg=bg " Set the background color of line numbers
" Show invisible characters
set lcs=tab:▸\ ,trail:·,nbsp:_
set list
set laststatus=2 " Always show status line
set noerrorbells visualbell t_vb= " Disable errors bells
set scrolloff=5 " Start scrolling five lines before the horizontal window border
set ruler " Show the current cursor position
set showmode " Show the current mode
set title " Show the filename in the window titlebar
set showcmd " Show the (partial) command as it's being typed
set report=0 " Show all changes.
set showmatch " show matching parenthesis
set diffopt+=iwhite " Ignore whitespace changes.
set hlsearch " Highlight search
set incsearch " Highlight dynamically as pattern is typed
set ignorecase " Ignore case of searches
nmap <Leader><space> :nohlsearch<cr> " Mapping for leader+space to clear searches
" add useful stuff to title bar (file name, flags, cwd)
" based on @factorylabs
if has('title') && (has('gui_running') || &title)
set titlestring=
set titlestring+=%f
set titlestring+=%h%m%r%w
set titlestring+=\ -\ %{v:progname}
set titlestring+=\ -\ %{substitute(getcwd(),\ $HOME,\ '~',\ '')}
endif
" use relative line number by default
if exists('+relativenumber')
set relativenumber
endif
" guioptions for scroll bar on MacVim
set guioptions-=l " left scroll bar
set guioptions-=L
set guioptions-=r
set guioptions-=R
set guioptions-=e " We don't want, GUI tabs for Mac-Vim
set linespace=15 " MacVim specific line-height
" Allow use hjkl for split management
nmap <C-J> <C-W><C-J>
nmap <C-H> <C-W><C-H>
nmap <C-L> <C-W><C-L>
nmap <C-K> <C-W><C-K>
hi ColorColumn ctermbg=0 guibg=#000 " Colored column ruler to black
" --- command completion ---
set wildmenu " Hitting TAB in command mode will
set wildchar=<TAB> " show possible completions.
set wildmode=list:longest
set wildignore+=*.DS_STORE,*.db,node_modules/**,*.jpg,*.png,*.gif
" --- folding---
set foldmethod=manual " manual fold
set foldnestmax=3 " deepest fold is 3 levels
set nofoldenable " don't fold by default
" -----------------------------------------------------------------------------
" ----- INDENTATION AND TEXT-WRAP
" -----------------------------------------------------------------------------
set expandtab " Expand tabs to spaces
set autoindent smartindent " auto/smart indent
set copyindent " copy previous indentation on auto indent
set softtabstop=2 " Tab key results in # spaces
set tabstop=2 " Tab is # spaces
set shiftwidth=2 " The # of spaces for indenting.
set wrap " wrap lines
set nomodeline " don't use modeline (security)
set synmaxcol=300 " Faster wehn opening files with large lines
" -----------------------------------------------------------------------------
" ----- PLUGINS
" -----------------------------------------------------------------------------
" --- NERDTree ----
let NERDTreeShowHidden=1 " Show hidden files from NerdTree
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
" Easier mapping for NerdTreeToggle
map <c-n> :NERDTreeToggle<cr>
map <D-Bslash> :NERDTreeToggle<cr> " Active nerdtree by pressing command-backslash
let g:NERDTreeIgnore=['.git', 'node_modules', '.DS_Store', '.sass-cache', '.idea']
let NERDTreeHijackNetrw = 0
nmap <Leader>n <plug>NERDTreeTabsToggle<cr> " Mapping for leader+n to toggle nerdtree
" --- CtrlP ----
nmap <c-R> :CtrlPBufTag<cr> " Search for symbols on a file
nmap <c-E> :CtrlPMRUFiles<cr> " Show recent last edited files on
nmap <D-p> :CtrlP<cr> " Use the CtrlP by command on OSX
nmap <D-R> :CtrlPBufTag<cr> " Search for a symbol by command on OSX
nmap <D-E> :CtrlPPMRUFiles<cr>
" Ignore files and folders for CtrlP
let g:ctrlp_custom_ignore = '\v[\/]\.(hg|svn|DS_Store|bundle|idea)$'
let g:ctrlp_match_window = 'bottom,order:btt,min:1,max:30,results:30'
" --- Ctags ----
nmap <Leader>f :tag<space>
" --- Vim Powerline ----
let g:airline_theme='papercolor'
" --- Strip trailing whitespace ---
function! StripWhitespace ()
let save_cursor = getpos(".")
let old_query = getreg('/')
:%s/\s\+$//e
call setpos('.', save_cursor)
call setreg('/', old_query)
endfunction
" Trailing white space (strip spaces)
noremap <leader>ss :call StripWhitespace()<CR>
" -----------------------------------------------------------------------------
" KEY MAPPINGS
" -----------------------------------------------------------------------------
" movement by screen line instead of file line (for text wrap)
nnoremap j gj
nnoremap <down> gj
nnoremap k gk
nnoremap <up> gk
nnoremap <C-Tab> :tabn<CR> " Next tab
" automatic esc, really uncommon to type jj,jk
inoremap jj <ESC>
inoremap jk <Esc>
" Faster scrolling
nnoremap <C-e> 3<C-e>
nnoremap <C-y> 3<C-y>
" Open current buffer in a new split
noremap <leader>s :vsplit<cr>
noremap <leader>i :split<cr>
" close window
noremap <leader>q :clo<CR>
" smarter next/prev buffer (requires bufkill.vim)
map <leader>bn :BF<CR>
map <leader>bp :BB<CR>
" resize splits (http://vim.wikia.com/wiki/Resize_splits_more_quickly)
nnoremap <silent> <Leader>+ :exe "resize " . (winheight(0) * 3/2)<CR>
nnoremap <silent> <Leader>- :exe "resize " . (winheight(0) * 2/3)<CR>
" -----------------------------------------------------------------------------
" FILE HANDLING
" -----------------------------------------------------------------------------
augroup mm_buf_cmds
" Automatically source the vimrc file on save
autocmd bufwritepost .gvimrc source %
autocmd bufwritepost .vimrc source %
" Only show cursorline in the current window and in normal mode
au WinLeave,InsertEnter * set nocul
au WinEnter,InsertLeave * set cul
" highlight char at column 81 (textwidth + 1)
autocmd BufEnter * match OverLength /\%81v/
" Color Column (only on insert)
if exists("&colorcolumn")
autocmd InsertEnter * set colorcolumn=80
autocmd InsertLeave * set colorcolumn=""
endif
augroup END
" Tricks and Tips
" - Press "zz" to instantly center the line where the cursor is located.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment