Skip to content

Instantly share code, notes, and snippets.

@maclunar
Created May 7, 2018 05:58
Show Gist options
  • Save maclunar/b40dab09f9669e8d3dc842fe63e952c0 to your computer and use it in GitHub Desktop.
Save maclunar/b40dab09f9669e8d3dc842fe63e952c0 to your computer and use it in GitHub Desktop.
" maclunar's .vimrc file
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set shell=/bin/sh
" use vim-plug
call plug#begin()
Plug 'ctrlpvim/ctrlp.vim' " fuzzy file search
Plug 'rking/ag.vim' " silver searcher search
Plug 'tpope/vim-fugitive' " git stuff
Plug 'tpope/vim-rails' " rails helpers
Plug 'mustache/vim-mustache-handlebars' " hbs syntax highliting
Plug 'kchmck/vim-coffee-script' " coffeescript syntax highlighting
Plug 'scrooloose/nerdcommenter' " commenting multiple lines
Plug 'airblade/vim-gitgutter' " mark git diff lines on the left
Plug 'slim-template/vim-slim' " slim syntax highlighting
Plug 'altercation/vim-colors-solarized' " solarized colorscheme
Plug 'junegunn/goyo.vim' " centers the text for writing
Plug 'reedes/vim-pencil' " better writing in vim
Plug 'tpope/vim-endwise' " automatically add 'end' in Ruby
Plug 'leafgarland/typescript-vim' " typescript syntax highlighting
Plug 'alvan/vim-closetag' " autoclose html tags
Plug 'mattn/emmet-vim' " emmet for working with html/css
Plug 'posva/vim-vue' " vue.js syntax highlighting
call plug#end()
set nocompatible
set encoding=utf-8
" if the file is changed outside vim - reload automatically
set autoread
set ttyfast " faster redrawing
" Don't make backups at all
set nobackup
set nowritebackup
set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" Fix slow O inserts
:set timeout timeoutlen=1000 ttimeoutlen=100
"" Colors
let base16colorspace=256 " access colors present in 256 colorspace
set t_Co=256 " tell vim that terminal supports 256 colors
"highlight ColorColumn ctermbg=235 guibg=#2c2d27
"let &colorcolumn=join(range(101,999),",") "color past 80th line"
highlight LineNr ctermfg=grey
" highlight current line in active window only
augroup CursorLine
au!
au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
au WinLeave * setlocal nocursorline
augroup END
syntax on " older syntax highlighting engine, might be faster
set re=1 " might speed up vim in ruby filed
if has('gui_running')
colorscheme evening
highlight Normal guibg=DarkBlue
set background=dark
set guifont=Inconsolata:h14
set guioptions=
else
syntax enable
set background=light
colorscheme solarized
end
" increase CtrlP window height
let g:ctrlp_match_window = 'max:20'
" disable bell
set noerrorbells
set novisualbell
set t_vb=
autocmd! GUIEnter * set vb t_vb=
" basic visual config
set number " show current line number
set wrap linebreak nolist " line wrapping options
set showbreak=--> " display at the begining of wrapped lines
set showcmd " show partial commands below the status line
set scrolloff=3 " have some context
set hlsearch " highlight matches
set incsearch " incremental searching
set ignorecase " searches are case insensitive...
set smartcase " ... unless they contain at least one capital letter
nnoremap <CR> :nohlsearch<cr>
" clear the search buffer when hitting return
"" Tabs and Indents
set expandtab " insert spacer rather than tabs
set smarttab " tab respects shiftwidth, tabstop and softtabstop
set shiftwidth=2 " number of spaces to use for (un)indent
set tabstop=2 " visible width of tabs
set softtabstop=2 " edit as if tabs are 2 chars wide
"set shiftround " round indent to a multiple of 'shiftwidth'
set autoindent
set smartindent
"" Control and Splits
if has('mouse')
set mouse=a
"set ttymouse=xterm2
endif
" remap <leader> key to ,
let mapleader = ','
let g:mapleader = ','
" easier buffer switching
" gb to see buffer list, then just type buffer number
nnoremap gb :ls<CR>:b<Space>
" easier split navigation
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
" put cursor in the new spli
nnoremap <leader>w <C-w>v<C-w>l
" more natural split opening
set splitbelow
set splitright
" disable Ex mode
noremap Q <NOP>
" double ,, for previous buffer
nnoremap <leader><leader> <c-^>
" yank to system clipboard
set clipboard=unnamed
"set clipboard=unnamedplus,unnamed,autoselect
"set clipboard=unnamedplus
nmap <leader>y "+y
"paste lines from unnamed register and fix indentation
nmap <leader>p pV`]=
nmap <leader>P PV`]=
" scroll the viewport faster
nnoremap <C-e> 3<C-e>
nnoremap <C-y> 3<C-y>
" MULTIPURPOSE TAB KEY
" Indent if at the beginning of a lien. Else, do completion.
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <s-tab> <c-n>
" DEALING WITH TRAILING WHITESPACES
" highlight them
match ErrorMsg '\s\+$'
" remove them ...
function! TrimWhiteSpace()
%s/\s\+$//e
endfunction
" ... manually ...
nnoremap <silent> <Leader>rts :call TrimWhiteSpace()<CR>
" ... and automatically
autocmd FileWritePre * :call TrimWhiteSpace()
autocmd FileAppendPre * :call TrimWhiteSpace()
autocmd FilterWritePre * :call TrimWhiteSpace()
autocmd BufWritePre * :call TrimWhiteSpace()
"" Status line
if has("statusline") && !&cp
set laststatus=2 " always show the status bar
set statusline=%<%1*\ %f\ %* " filename
set statusline+=%2*%m%r%* " modified, readonly
set statusline+=\ %3*%y%* " filetype
set statusline+=%= " left-right separation point
set statusline+=%c, " cursos column
set statusline+=\ %4*%l%*/%L[%p%%] " current line/total lines
endif
" Remove fancy characters COMMAND
function! RemoveFancyCharacters()
let typo = {}
let typo[""] = '"'
let typo[""] = '"'
let typo[""] = "'"
let typo[""] = "'"
let typo[""] = '--'
let typo[""] = '---'
let typo[""] = '...'
:exe ":%s/".join(keys(typo), '\|').'/\=typo[submatch(0)]/ge'
endfunction
command! RemoveFancyCharacters :call RemoveFancyCharacters()
nmap <silent> <leader>r :CtrlPBuffer<cr>
" Speed up Ctrl-P by using Silver Searcher
if executable('ag')
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
endif
" Ignore files from gitignore
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard']
" Replace Ag with Ack
let g:acjprg = 'ag --vimgrep --nogroup --column --smart-case'
" Show current window big, but leave context for other splits
set winwidth=100
" We have to have a winheight bigger than we want to set winminheight. But if
" we set winheight to be huge before winminheight, the winminheight set will
" fail.
set winheight=7
set winminheight=7
set winheight=999
" *** Rails specific mappings ***
"
" Open routes and Gemfile in top left, full height
map <leader>gr :topleft :split config/routes.rb<cr>
map <leader>gg :topleft 100 :split Gemfile<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment