Skip to content

Instantly share code, notes, and snippets.

@hlegius hlegius/.vimrc
Last active Jan 25, 2018

Embed
What would you like to do?
Personal Vim's dotfile
" Original "Vi behaviour" disabled (I am not that tr00 user [yet])
set nocompatible " better safe than sorry
" Fair Vim
noremap <Left> <NOP>
noremap <Right> <NOP>
noremap <Up> <NOP>
noremap <Down> <NOP>
inoremap <Left> <NOP>
inoremap <Right> <NOP>
inoremap <Up> <NOP>
inoremap <Down> <NOP>
" Let's define The Leader
let mapleader=","
" Looks weird, but it could work
inoremap jj <Esc>
" Most common command I use mapped as <Leader>{letter}
nnoremap <Leader>w :w<cr>
nnoremap <Leader>qq :q<cr>
nnoremap <Leader>foo :split foo.txt<cr>
nnoremap <Leader>ev :split ~/.vimrc<cr>
" Fugitive Git shortcuts
nnoremap <Leader>gs :Gstatus<cr>
nnoremap <Leader>gb :Gblame<cr>
" to open CtrlP Buffer list
nnoremap <Leader>fb :CtrlPBuffer<cr>
nnoremap <Leader>fko <C-w>o
" Zoom in/out current file
nnoremap <Leader>zi <C-W>_<C-W>\|
nnoremap <Leader>zo <C-W>=
" Split movement shortcut
nnoremap <silent> <C-w>l <C-W>l<C-w>=20<C-w>>5<C-w>+<cr>
nnoremap <silent> <C-w>h <C-W>h<C-W>=20<C-w>>5<C-w>+<cr>
nnoremap <silent> <C-w>j <C-W>j<C-W>=5<C-w>+<cr>
nnoremap <silent> <C-w>k <C-W>k<C-W>=5<C-w>+<cr>
" automatically rebalance windows on vim resize
autocmd VimResized * :wincmd =
" Normal configuration
autocmd ColorScheme * highlight! Normal ctermbg=NONE guibg=NONE
autocmd ColorScheme * highlight! nonText ctermbg=NONE guibg=NONE
colorscheme jellybeans
filetype on " Automatically detect file types.
filetype indent on " vim-ruby plugin for indentation
filetype plugin on " vim-ruby plugin
syntax enable
set autoindent
set fileformat=unix " File format UNIX LIKE LF instead of CRLF
set encoding=utf-8 " file encoding
set ruler " Ruler on
set relativenumber " Relative Line numbers on
set nowrap " Line wrapping off
set shell=/bin/zsh
"set clipboard=unnamedplus " Yanks level 99+ (take copy from system's clipboard)
set history=1024 " Number of things to remember in history.
set timeoutlen=250 " Time to wait after ESC (default causes an annoying delay)
set novisualbell " No blinking .
set noerrorbells " No noise.
set laststatus=2 " Always show status line.
set backspace=indent,eol,start " delete key
set lcs=tab:\ \ ,eol:$,trail:~,extends:>,precedes:< " Show $ at end of line and trailing space as ~
" backup files elsewhere
set backupdir=~/.vimbackup,/tmp
set directory=~/.vimbackup,/tmp
" Searching Highlight with * or # (clean with space)
set hlsearch
set incsearch
set ignorecase " searches are case insensitive...
set smartcase " ... unless they contain at least one capital letter
:nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o " Don't add the comment prefix when I hit enter or o/O on a comment line.
au! FileType mkd setlocal syn=off " Don't syntax highlight markdown because it's often wrong.
au! BufRead,BufNewFile *.markdown set filetype=mkd
au! BufRead,BufNewFile *.md set filetype=mkd
" Remove trailing whitespace on save
au BufWritePre *.rb :%s/\s\+$//e
au BufWritePre *.java :%s/\s\+$//e
au BufWritePre *.php :%s/\s\+$//e
au BufWritePre *.css :%s/\s\+$//e
au BufWritePre *.js :%s/\s\+$//e
" Auto completion menu with matches list
set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches
set wildmode=list:longest
set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
set wildignore+=*vim/backups*
set wildignore+=*sass-cache*
set wildignore+=*DS_Store*
set wildignore+=vendor/rails/**
set wildignore+=vendor/cache/**
set wildignore+=*.gem
set wildignore+=log/**
set wildignore+=tmp/**
set wildignore+=*app/cache/**
set wildignore+=*.png,*.jpg,*.gif
set wildignore+=*.so,*.swp,*.zip
set wildignore+=*.git/**,.svn/**,*.git,*.svn
" Scrolling settings
set scrolloff=8 "Start scrolling when we're 8 lines away from margins
set sidescrolloff=15
set sidescroll=1
" Formatting
autocmd Filetype ruby setlocal ts=2 sts=2 sw=2
autocmd Filetype php setlocal ts=4 sts=4 sw=4
autocmd Filetype javascript setlocal ts=4 sts=4 sw=4
set tabstop=2
set shiftwidth=2
set expandtab
set cinoptions=i2,+2,+p2
set cinwords=if,else,while,do,for,switch,case,class,def
set cindent
set autoindent
set smarttab
" Navigation
set showmatch " Show matching brackets. (navigate always with %)
set mat=5 " Bracket blinking.
" ==========================================
" Plugin's Configuration
" Slimux Mapping Configuration
" https://github.com/epeli/slimux
nnoremap <Leader>rl :SlimuxREPLSendLine<CR>
vnoremap <Leader>rs :SlimuxREPLSendSelection<CR>
nnoremap <leader>rb :SlimuxREPLSendBuffer<CR>
" Ag
" -- use Ag over grep
set grepprg=ag\ --nogroup\ --nocolor
" Ag functions -- definitions
function! AgWithinDirectories(pattern)
let thedir = './'
execute ':Ag! ' . a:pattern . ' -R ' . thedir
endfunction
function! AgFileOnly(pattern)
let dir = './'
let current = expand('%:p')
let thedir = substitute(current, '^\(' . dir . '/[^/]\+\).*', '\1', '')
execute ':Ag! ' . a:pattern . ' ' . thedir
endfunction
command! -nargs=+ AgWithinDirectories call AgWithinDirectories(<q-args>)
command! -nargs=+ AgFileOnly call AgFileOnly(<q-args>)
" binding gf/gp for searching using AG within File or entire Project
" finding word under cursor
nmap <Leader>sf :AgFileOnly "\b<C-R><C-W>\b"<cr>
nmap <Leader>sp :AgWithinDirectories "\b<C-R><C-W>\b"<cr>
" ctrlp
let g:ctrlp_map = '<leader>fo'
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_user_command = 'ag %s -i --nocolor --nogroup --hidden
\ --ignore .git
\ --ignore .svn
\ --ignore .hg
\ --ignore .DS_Store
\ --ignore "**/*.pyc"
\ --ignore "target/"
\ -g ""'
let g:ctrlp_match_func = { 'match': 'pymatcher#PyMatch' }
let g:ctrlp_follow_symlinks = 1 " follow symlinks
let g:ctrlp_use_caching = 0 " disable caching
let g:ctrlp_switch_buffer = 0 " don't jump the first result to opened window
let g:ctrlp_lazy_update = 200 " delay to prevent extra search
let g:ctrlp_max_files = 0 " there is no file limit
" Comment configuration (https://github.com/tpope/vim-commentary)
autocmd FileType ruby set commentstring=#\ %s
autocmd FileType scala set commentstring=\/\/\ %s
autocmd FileType java set commentstring=\/\/\ %s
autocmd FileType javascript set commentstring=#\ %s
autocmd FileType php set commentstring=\/\/\ %s
autocmd FileType apache set commentstring=#\ %s
" vim-scala https://github.com/derekwyatt/vim-scala/
" Comments as Scaladoc recommends
let g:scala_scaladoc_indent = 1
" Set import order
let g:scala_sort_across_groups = 1
" terryma/vim-multiple-cursors
" Default mapping
let g:multi_cursor_next_key='<C-n>'
let g:multi_cursor_prev_key='<C-p>'
let g:multi_cursor_skip_key='<C-x>'
let g:multi_cursor_quit_key='<Esc>'
" Map start key separately from next key
let g:multi_cursor_start_key='<C-n>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.