Skip to content

Instantly share code, notes, and snippets.

@mmmattos
Last active December 21, 2015 06:39
Show Gist options
  • Save mmmattos/6265741 to your computer and use it in GitHub Desktop.
Save mmmattos/6265741 to your computer and use it in GitHub Desktop.
My Vim configuration for Windows
set lines=32
set columns=96
set visualbell
set vb t_vb=
set nocompatible " be iMproved
filetype on " required!
filetype off " required!
" Properly setup vundle dirs on Windows
if has('win32') || has('win64')
set rtp+=~/vimfiles/bundle/vundle/
call vundle#rc('$HOME/vimfiles/bundle/')
else
" Usual quickstart instructions
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
endif
" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
Bundle 'scrooloose/nerdtree'
Bundle 'airblade/vim-rooter'
Bundle 'kien/ctrlp.vim'
Bundle 'terryma/vim-multiple-cursors'
Bundle 'rking/ag.vim'
Bundle 'tpope/vim-surround'
Bundle 'jistr/vim-nerdtree-tabs'
Bundle 'xolox/vim-session'
Bundle 'xolox/vim-misc'
Bundle 'airblade/vim-gitgutter'
Bundle 'tpope/vim-bundler'
Bundle 'tpope/vim-rails'
Bundle 'tpope/vim-cucumber'
Bundle 'kshenoy/vim-signature'
Bundle 'motemen/git-vim'
Bundle 'mattn/webapi-vim'
Bundle 'mattn/gist-vim'
Bundle 'godlygeek/tabular'
Bundle 'rodjek/vim-puppet'
Bundle 'tpope/vim-commentary'
Bundle 'markcornick/vim-vagrant'
Bundle 'scrooloose/syntastic'
" Bundle 'klen/python-mode'
Bundle 'tpope/vim-vividchalk'
Bundle 'p0deje/sexy-railscasts-theme'
filetype plugin indent on " required!
" Custom settings
" Patch Windows specific stuff...
if ! has('win16') || has('win32') || has('win64') || has('win95')
set backupdir=$HOME\\_vimbackups
set directory=$HOME\\_vimbackups
let &runtimepath.=',~/vimfiles'
source $VIMRUNTIME/mswin.vim
behave mswin
else
set backupdir=$HOME/_vimbackups
set directory=$HOME/_vimbackups
endif
if has('gui_running')
set guifont=Consolas:h11:b
" 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
" NERDTree"
let g:NERDTreeWinPos = "left"
let g:NERDTreeWinSize = 30
let NERDTreeShowHidden = 1
au VimEnter * NERDTree
" Session"
let g:session_autosave = 'yes'
let g:session_autoload = 'yes'
" Colorschemes
colorscheme vividchalk
colorscheme sexy-railscasts
endif
" Global Settings
set autoindent " always set autoindenting on
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set clipboard+=unnamed " yanks to clipboard
set copyindent " copy indentation on new lines
set cursorline
set expandtab
set hlsearch " highlight search terms
set ignorecase
set incsearch " show search matches as you type
set iskeyword+=_,$,@,%,# " none of these are word dividers
set linespace=1
set list " show hidden chars
set listchars=tab:>-,trail:.,extends:> " chars to be shown
set ls=2 " allways show status line
set nogdefault " do not search/replace 'globally' (on a line) by default
set nospell " no spell checking
set noswapfile " no sw?s
set nowrap
set number
set ruler " show the cursor position all the time
set scrolloff=5 " Keep at least 5 lines visible when scrolling
set shiftround " use multiple of shiftwidth when indenting with '<' and '>'
set shiftwidth=4
set showmatch " show matching brackets
set showmode " show what mode we're currently editing in
set showtabline=2
set smartcase " ignore case if search pattern is all lowercase, case-sensitive otherwise
set smartindent " indent on new blocks
set smarttab
set softtabstop=4
set tabstop=4
set textwidth=0 " no limit for text column width
set ttimeoutlen=50 " make Esc key faster
set virtualedit=onemore " allow the cursor to go in to 'invalid' places
set visualbell " no beeps
set wildignore+=node_modules " ignores node_modules
set wildmenu " show list instead of just completing
set wildmode=list:longest,full " command <Tab> completion, list matches, then longest common part, then all
syntax on
" " Relative number
" autocmd FocusLost * :set number
" autocmd FocusGaned * :set relativenumber
" autocmd InsertEnter * :set number
" autocmd InsertLeave * :set relativenumber
" Disable completly the bell and the visual flash.
autocmd GUIEnter * set vb t_vb= " for your GUI
autocmd VimEnter * set vb t_vb=
" 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 viml files
autocmd filetype vim set tabstop=2
autocmd filetype vim set shiftwidth=2
autocmd filetype vim set softtabstop=2
" 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 [] []
" 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>
nmap <silent> <Leader>] :CtrlP<CR>
nmap <silent> <Leader>[ :CtrlPClearCache<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
map <Leader>j :%!python -m json.tool<CR>
" Quicker access to input commands
nnoremap ; :
" Escape key cleans search highlights
nmap <Esc> :nohlsearch<CR>:<CR>
" Tabs navigation (cmd + shift + arrows)
nmap <C-A-S-Left> :tabprevious<CR>
nmap <C-A-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-S-up> xkP'[V']
vmap <C-A-S-down> xp'[V']
" Move line up/down (ctrl + alt + up/down)
nmap <C-A-S-up> :call g:MoveLineUp()<CR>
nmap <C-A-S-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