Skip to content

Instantly share code, notes, and snippets.

@mmmattos
Last active December 21, 2015 06:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mmmattos/6265691 to your computer and use it in GitHub Desktop.
Save mmmattos/6265691 to your computer and use it in GitHub Desktop.
My Vim configuration for OSX.
syntax on 'this is needed to see syntax
set background=dark "makes it easier to read with black background
set lines=33
set columns=127
set nocompatible " be iMproved
filetype on " required!
filetype off " required!
" Usual quickstart instructions
set rtp+=~/.vim/bundle/Vundle.vim/
call vundle#begin()
" let Vundle manage Vundle
" required!
Plugin 'VundleVim/Vundle.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'airblade/vim-rooter'
Plugin 'kien/ctrlp.vim'
Plugin 'terryma/vim-multiple-cursors'
Plugin 'rking/ag.vim'
Plugin 'tpope/vim-surround'
Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'xolox/vim-misc'
Plugin 'xolox/vim-session'
Plugin 'airblade/vim-gitgutter'
Plugin 'tpope/vim-bundler'
Plugin 'tpope/vim-rails'
Plugin 'tpope/vim-cucumber'
""Plugin 'kshenoy/vim-signature'
Plugin 'motemen/git-vim'
Plugin 'mattn/webapi-vim'
Plugin 'mattn/gist-vim'
Plugin 'godlygeek/tabular'
Plugin 'rodjek/vim-puppet'
Plugin 'tpope/vim-commentary'
Plugin 'markcornick/vim-vagrant'
Plugin 'b4winckler/vim-objc'
" Plugin 'scrooloose/syntastic'
" Plugin 'klen/python-mode'
Plugin 'tpope/vim-vividchalk'
Plugin 'p0deje/sexy-railscasts-theme'
Plugin 'GertjanReynaert/cobalt2-vim-theme'
call vundle#end()
filetype plugin indent on " required!
" Custom settings
set backupdir=$HOME/.vimbackups
set directory=$HOME/.vimbackups
if has('gui_running')
set guifont=Monaco:h15
" more readable line numbers
highlight LineNr guifg=#666666 guibg=#222222
" remove MacVim scrollbars
set guioptions-=R
set guioptions-=r
set guioptions-=L
" awlays show tab bar in MacVim
set showtabline=2
" autosave file on focus lost
au FocusLost * silent! wa
let g:NERDTreeWinPos = "left"
let g:NERDTreeWinSize = 30
let NERDTreeShowHidden = 1
autocmd vimenter * NERDTree
let g:session_autosave = 'yes'
let g:session_autoload = 'yes'
"Colorschemes
colorscheme vividchalk
""colorscheme sexy-railscasts
endif
set linespace=1
set number
set cursorline
set ls=2 " allways show status line
set hlsearch " highlight searches
set incsearch " do incremental searching
set ruler " show the cursor position all the time
set visualbell " no beeps
set wildignore+=node_modules " ignores node_modules
set showmode " show what mode we're currently editing in
set showmatch " show matching brackets
set list " show hidden chars
set listchars=tab:▸\ ,eol:¬ " chars to be shown
set clipboard+=unnamed " yanks to clipboard
set noswapfile " no sw?s
set nospell " no spell checking
set wrap! " no word wrapping
set virtualedit=all " allow the cursor to go in to 'invalid' places
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set iskeyword+=_,$,@,%,# " none of these are word dividers
set ttimeoutlen=50 " make Esc key faster
set scrolloff=3 " number of lines to keep off the edges of the screen when scrolling
set textwidth=0 " no limit for text column width
set autoindent " always set autoindenting on
set copyindent " copy indentation on new lines
set smartindent " indent on new blocks
set nogdefault " do not search/replace 'globally' (on a line) by default
set smartcase " ignore case if search pattern is all lowercase, case-sensitive otherwise
set hlsearch " highlight search terms
set incsearch " show search matches as you type
set wildmenu " show list instead of just completing
set wildmode=list:longest,full " command <Tab> completion, list matches, then longest common part, then all
set showtabline=2
set scrolloff=5 " Keep at least 5 lines visible when scrolling
set smartindent
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set shiftround " use multiple of shiftwidth when indenting with '<' and '>'
set smarttab
set ignorecase
set nowrap
syntax on
" " Relative number
" autocmd FocusLost * :set number
" autocmd FocusGained * :set relativenumber
" autocmd InsertEnter * :set number
" autocmd InsertLeave * :set relativenumber
" Filetypes
autocmd bufnewfile,bufread *.json set ft=javascript
autocmd filetype ruby set ft=ruby.ruby-rails.ruby-rspec.ruby-rails-rjs.ruby-shoulda
" remove trailing spaces
autocmd FileType c,cpp,python,ruby,java,cucumber,gherkin autocmd BufWritePre <buffer> :%s/\s\+$//e
" change tabs to 2 space on ruby files
autocmd filetype ruby set tabstop=2
autocmd filetype ruby set shiftwidth=2
autocmd filetype ruby set softtabstop=2
" change tabs to 4 space on ruby files
autocmd filetype python set tabstop=4
autocmd filetype python set shiftwidth=4
autocmd filetype python set softtabstop=4
"set noexpandtab to makefiles, to use <tab> char instead of spaces
autocmd filetype make setlocal noexpandtab
"set smartindent for python files
autocmd filetype python set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
"map to execute python files
autocmd filetype python map <leader>p :!python % <cr>
"settings for mark badwhitespaces in python files
autocmd filetype python highlight badwhitespace ctermbg=red guibg=red
autocmd filetype python match badwhitespace /^\t\+/
autocmd filetype python match badwhitespace /\s\+$/
" GitGutter
let g:gitgutter_sign_column_always = 1
let g:gitgutter_sign_added = '+'
let g:gitgutter_sign_modified = '~'
let g:gitgutter_sign_removed = '-'
let g:gitgutter_sign_modified_removed = '-~'
" Gist
let g:gist_clip_command = 'pbcopy'
let g:gist_detect_filetype = 1
let g:gist_show_privates = 1
let g:gist_post_private = 1
" " Syntastic
" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
" set statusline+=%*
" let g:syntastic_auto_loc_list=1
" let g:syntastic_loc_list_height=5
" automatic alignment of | symbol (used in Gherkin) by tabularize plugin
" taken from https://gist.github.com/tpope/287147
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
endif
endfunction
" autocomplete parenthesis
" When you type an open brace, this will automatically
" insert a closing brace on the same line, after the cursor.
" If you quickly hit Enter after the open brace, (to begin
" a code block), the closing brace will be inserted on the
" line below the cursor. If you quickly press the open brace
" key again after the open brace, Vim won't insert anything extra,
" you'll just get a single open brace. Finally, if you quickly
" type an open and close brace, Vim will not do anything special.
inoremap { {}<Left>
inoremap {<CR> {<CR>}<Esc>O
inoremap {{ {
inoremap {} {}
inoremap ( ()<Left>
inoremap (<CR> (<CR>)<Esc>O
inoremap (( (
inoremap () ()
inoremap [ []<Left>
inoremap [<CR> [<CR>]<Esc>O
inoremap [[ [
inoremap [] []
inoremap " ""<Left>
inoremap "<CR> "<CR>"<Esc>O
inoremap "" "
inoremap ' ''<Left>
inoremap '<CR> '<CR>'<Esc>O
inoremap '' '
" Shortcuts
" NERDTree
map <leader>on :NERDTreeToggle<cr>
map <leader>of :NERDTreeFind<cr>
" Quickly edit vimrc
map <leader>rc :e ~/.vimrc<cr>
" CtrlP
map <leader>pp :CtrlPMixed<cr>
map <leader>pf :CtrlP features<cr>
map <leader>pa :CtrlP app<cr>
" Session
map <leader>os :OpenSession!<cr>
map <leader>ss :SaveSession!<Space>
" Window navigation
map <M-h> :wincmd h<cr>
map <M-j> :wincmd j<cr>
map <M-k> :wincmd k<cr>
map <M-l> :wincmd l<cr>
" Format JSON
nmap <silent> <Leader>j :%!python -m json.tool<CR>
" Quicker access to input commands
nnoremap ; :
" Escape key cleans search highlights
nmap <Esc> :nohlsearch<CR>:<CR>
" Quick access to ctrl-p (aka \])
nmap <silent> <Leader>] :CtrlP<CR>
" Quick access to clear ctrl-p cache (aka \[)
nmap <silent> <Leader>[ :CtrlPClearCache<CR>
" Tabs navigation (cmd + shift + arrows)
nmap <D-S-Left> :tabprevious<CR>
nmap <D-S-Right> :tabnext<CR>
" Splits navigation (cmd + alt + arrows)
nmap <silent> <D-A-Up> :wincmd k<CR>
nmap <silent> <D-A-Down> :wincmd j<CR>
nmap <silent> <D-A-Left> :wincmd h<CR>
nmap <silent> <D-A-Right> :wincmd l<CR>
" Create empty split related to the current one (leader + arrows)
nmap <Leader><left> :leftabove vnew<CR>
nmap <Leader><right> :rightbelow vnew<CR>
nmap <Leader><up> :leftabove new<CR>
nmap <Leader><down> :rightbelow new<CR>
" Center search results
nmap n nzz
nmap N Nzz
nmap * *zz
nmap # #zz
nmap g* g*zz
nmap g# g#zz
" Move visual block (ctrl + alt + up/down)
vmap <C-A-up> xkP'[V']
vmap <C-A-down> xp'[V']
" Move line up/down (ctrl + alt + up/down)
nmap <C-A-up> :call g:MoveLineUp()<CR>
nmap <C-A-down> :call g:MoveLineDown()<CR>
function! g:MoveLineUp()
if &modifiable
normal ddkP
endif
endfunction
function! g:MoveLineDown()
if &modifiable
normal ddp
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment