Skip to content

Instantly share code, notes, and snippets.

@grippado
Last active January 3, 2018 13:03
Show Gist options
  • Save grippado/9ab8deae04ae5c0aedbce65ad2c0bbce to your computer and use it in GitHub Desktop.
Save grippado/9ab8deae04ae5c0aedbce65ad2c0bbce to your computer and use it in GitHub Desktop.
" vim: ft=vim
" Use 256 colors in vim
" some plugins not work without it
set t_Co=256
" Set up leader key <leader>, i use default \
let mapleader = "\<Space>"
" Turn off filetype plugins before bundles init
filetype off
" Vim Plug Auto Install ---------------------------------------- {{{
" Automatic installation
" https://github.com/junegunn/vim-plug/wiki/faq#automatic-installation
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
function! PlugCond(cond, ...)
let l:opts = get(a:000, 0, {})
return a:cond ? l:opts : extend(l:opts, { 'on': [], 'for': [] })
endfunction
" }}} ---------------------------------------- Vim Plug Auto Install
" Plugins to Install ---------------------------------------- {{{
call plug#begin('~/.vim/bundle')
"--------------------------------------------------
" Bundles
" Instlall vimrpoc. is uses by unite and neocomplcache
" for async searches and calls
Plug 'Shougo/vimproc.vim', {'do' : 'make'}
" Some support functions used by delimitmate, and snipmate
Plug 'vim-scripts/tlib'
" Improve bookmarks in vim
" Allow word for bookmark marks, and nice quickfix window with bookmark list
" Plug 'AndrewRadev/simple_bookmarks.vim'
" plugin for fuzzy file search, most recent files list
" and much more
Plug 'Shougo/unite.vim'
" Snippets engine with good integration with neocomplcache
Plug 'Shougo/neosnippet'
" Default snippets for neosnippet, i prefer vim-snippets
"Plug 'Shougo/neosnippet-snippets'
" Default snippets
Plug 'honza/vim-snippets'
" Dirr diff
Plug 'vim-scripts/DirDiff.vim'
" Colorscheme solarazied for vim
Plug 'altercation/vim-colors-solarized'
" Allow autoclose paired characters like [,] or (,),
" and add smart cursor positioning inside it,
Plug 'Raimondi/delimitMate'
" Add code static check on write
" need to be properly configured.
" I just enable it, with default config,
" many false positive but still usefull
Plug 'scrooloose/syntastic'
" Great file system explorer, it appears when you open dir in vim
" Allow modification of dir, and may other things
" Must have
Plug 'scrooloose/nerdtree'
" Provide smart autocomplete results for javascript, and some usefull commands
Plug 'marijnh/tern_for_vim', {'do': 'yarn install'}
" Add smart commands for comments like:
" gcc - Toggle comment for the current line
" gc - Toggle comments for selected region or number of strings
" Very usefull
Plug 'tomtom/tcomment_vim'
" Best git wrapper for vim
" But with my workflow, i really rarely use it
" just Gdiff and Gblame sometimes
Plug 'tpope/vim-fugitive'
" Fix-up dot command behavior
" it's kind of service plugin
Plug 'tpope/vim-repeat'
" Add usefull hotkey for operation with surroundings
" cs{what}{towhat} - inside '' or [] or something like this allow
" change surroundings symbols to another
" and ds{what} - remove them
Plug 'tpope/vim-surround'
" Add aditional hotkeys
" Looks like i'm not using it at all
"Plug 'tpope/vim-unimpaired'
" HTML5 + inline SVG omnicomplete funtion, indent and syntax for Vim.
Plug 'othree/html5.vim'
" Improve javascritp syntax higlighting, needed for good folding,
" and good-looking javascritp code
Plug 'jelera/vim-javascript-syntax'
" Improved json syntax highlighting
Plug 'elzr/vim-json'
" Syntax highlighting for .jsx (js files for react js)
Plug 'mxw/vim-jsx'
" Add Support css3 property
Plug 'hail2u/vim-css3-syntax'
" Syntax highlighting for Stylus
Plug 'wavded/vim-stylus'
" Add support for taltoad/vim-jadeumarkdown
Plug 'tpope/vim-markdown'
" Highlights the matching HTML tag when the cursor
" is positioned on a tag.
Plug 'gregsexton/MatchTag'
" Automatically add closing tags in html-like formats
Plug 'alvan/vim-closetag'
" Smart indent for javascript
" http://www.vim.org/scripts/script.php?script_id=3081
Plug 'lukaszb/vim-web-indent'
" Plugin for changing cursor when entering in insert mode
" looks like it works fine with iTerm Konsole adn xerm
" Applies only on next vim launch after PlugInstall
Plug 'jszakmeister/vim-togglecursor'
" Nice statusline/ruler for vim
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
"code-completion for jquery, lodash e.t.c
Plug 'othree/javascript-libraries-syntax.vim'
" Code complete
Plug 'Shougo/neocomplcache.vim'
" Most recent files source for unite
Plug 'Shougo/neomru.vim'
" Yank history for unite
Plug 'Shougo/neoyank.vim'
" Plugin for chord mappings
Plug 'kana/vim-arpeggio'
" JShint :)
" But not necessary with syntastics
" Plug 'walm/jshint.vim'
" Insert vim-polyglot
Plug 'sheerun/vim-polyglot'
" Insert Wakatime
Plug 'wakatime/vim-wakatime'
" Insert FZF
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': 'yes \| ./install --all' } | Plug 'junegunn/fzf.vim'
Plug 'mhinz/vim-startify'
Plug 'lumiliet/vim-twig'
Plug 'junegunn/vim-easy-align'
Plug 'dracula/vim'
call plug#end()
" Enable Indent in plugins
filetype plugin indent on
" Enable syntax highlighting
syntax on
"--------------------------------------------------
" Bundles settings
"-------------------------
" Unite
" Set unite window height
let g:unite_winheight = 10
" Start unite in insert mode by default
let g:unite_enable_start_insert = 1
" Display unite on the bottom (or bottom right) part of the screen
let g:unite_split_rule = 'botright'
" Set short limit for max most recent files count.
" It less unrelative recent files this way
let g:unite_source_file_mru_limit = 100
" Enable history for yanks
let g:unite_source_history_yank_enable = 1
" Make samll limit for yank history,
let g:unite_source_history_yank_limit = 40
" Grep options Default for unite + supress error messages
let g:unite_source_grep_default_opts = '-iRHns'
let g:unite_source_rec_max_cache_files = 99999
" If ack exists use it instead of grep
if executable('ack-grep')
" Use ack-grep
let g:unite_source_grep_command = 'ack-grep'
" Set up ack options
let g:unite_source_grep_default_opts = '--no-heading --no-color -a -H'
let g:unite_source_grep_recursive_opt = ''
endif
" Hotkey for open window with most recent files
nnoremap <silent><leader>m :<C-u>Unite file_mru <CR>
" Hotkey for open history window
nnoremap <silent><leader>h :Unite -quick-match -max-multi-lines=2 -start-insert -auto-quit history/yank<CR>
" Quick tab navigation
nnoremap <silent><leader>' :Unite -quick-match -auto-quit tab<CR>
" Fuzzy find files
nnoremap <silent><leader>; :Unite file_rec/async:! -buffer-name=files -start-insert<CR>
" Unite-grep
nnoremap <silent><leader>/ :Unite grep:. -no-start-insert -no-quit -keep-focus -wrap<CR>
nnoremap <silent> <leader><leader> :Files<cr>
nnoremap <silent> <Leader>c :Colors<cr>
nnoremap <silent> <Leader>b :Buffers<cr>
nnoremap <silent> <Leader>h :Helptags<cr>
nnoremap <silent> <Leader>t :Tags<cr>
nmap <c-s> :w<CR>
imap <c-s> <Esc>:w<CR>a
"-------------------------
" NERDTree
" Tell NERDTree to display hidden files on startup
let NERDTreeShowHidden=1
" Disable bookmarks label, and hint about '?'
let NERDTreeMinimalUI=1
" Display current file in the NERDTree ont the left
nmap <silent> <leader>f :NERDTreeFind<CR>
" Enable autochecks
let g:syntastic_check_on_open=1
let g:syntastic_enable_signs=1
" For correct works of next/previous error navigation
let g:syntastic_always_populate_loc_list = 1
" check json files with jshint
let g:syntastic_filetype_map = { "json": "javascript", }
let g:syntastic_javascript_checkers = ["jshint", "jscs"]
" open quicfix window with all error found
nmap <silent> <leader>ll :Errors<cr>
" previous syntastic error
nmap <silent> [ :lprev<cr>
" next syntastic error
nmap <silent> ] :lnext<cr>
"-------------------------
" Fugitive
" Blame on current line
" nmap <silent> <leader>b :.Gblame<cr>
" Blame on all selected lines in visual mode
" vmap <silent> <leader>b :Gblame<cr>
" Git status
nmap <silent> <leader>gst :Gstatus<cr>
" like git add
nmap <silent> <leader>gw :Gwrite<cr>
" git diff
nmap <silent> <leader>gd :Gdiff<cr>
" git commit
nmap <silent> <leader>gc :Gcommit<cr>
" git commit all
nmap <silent> <leader>gca :Gcommit -a<cr>
" git fixup previous commit
nmap <silent> <leader>gcf :Gcommit -a --amend<cr>
"-------------------------
" DelimitMate
" Delimitmate place cursor correctly n multiline objects e.g.
" if you press enter in {} cursor still be
" in the middle line instead of the last
let delimitMate_expand_cr = 1
" Delimitmate place cursor correctly in singleline pairs e.g.
" if x - cursor if you press space in {x} result will be { x } instead of { x}
let delimitMate_expand_space = 1
" Without this we can't disable delimitMate for specific file types
let loaded_delimitMate = 1
"-------------------------
" vim-mustache-handlebars
" Enable shortcuts for things like {{{ an {{
let g:mustache_abbreviations = 1
"-------------------------
" vim-closetag
" Enable for files with this extensions
let g:closetag_filenames = "*.handlebars,*.html,*.xhtml,*.phtml"
"-------------------------
" Tern_for_vim
let tern_show_signature_in_pum = 1
" Find all refs for variable under cursor
nmap <silent> <leader>tr :TernRefs<CR>
" Smart variable rename
nmap <silent> <leader>tn :TernRename<CR>
"-------------------------
" Solarized
" if You have problem with background, uncomment this line
" let g:solarized_termtrans=1
"-------------------------
" neosnippets
"
" Enable snipMate compatibility
let g:neosnippet#enable_snipmate_compatibility = 1
" Tell Neosnippet about the other snippets
let g:neosnippet#snippets_directory='~/.vim/bundle/vim-snippets/snippets'
" Disables standart snippets. We use vim-snippets bundle instead
let g:neosnippet#disable_runtime_snippets = { '_' : 1 }
" Expand snippet and jimp to next snippet field on Enter key.
imap <expr><CR> neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)" : "\<CR>"
"-------------------------
" vim-airline
" Colorscheme for airline
let g:airline_theme='deus'
" Set custom left separator
let g:airline_left_sep = '▶'
" Set custom right separator
let g:airline_right_sep = '◀'
" Enable airline for tab-bar
let g:airline#extensions#tabline#enabled = 1
" Don't display buffers in tab-bar with single tab
let g:airline#extensions#tabline#show_buffers = 0
" Display only filename in tab
let g:airline#extensions#tabline#fnamemod = ':t'
"-------------------------
" neocomplcache
" Enable NeocomplCache at startup
let g:neocomplcache_enable_at_startup = 1
" Max items in code-complete
let g:neocomplcache_max_list = 10
" Max width of code-complete window
let g:neocomplcache_max_keyword_width = 80
" Code complete is ignoring case until no Uppercase letter is in input
let g:neocomplcache_enable_smart_case = 1
" Auto select first item in code-complete
let g:neocomplcache_enable_auto_select = 1
" Disable auto popup
let g:neocomplcache_disable_auto_complete = 1
" Smart tab Behavior
function! CleverTab()
" If autocomplete window visible then select next item in there
if pumvisible()
return "\<C-n>"
endif
" If it's begining of the string then return just tab pressed
let substr = strpart(getline('.'), 0, col('.') - 1)
let substr = matchstr(substr, '[^ \t]*$')
if strlen(substr) == 0
" nothing to match on empty string
return "\<Tab>"
else
" If not begining of the string, and autocomplete popup is not visible
" Open this popup
return "\<C-x>\<C-u>"
endif
endfunction
inoremap <expr><TAB> CleverTab()
" Undo autocomplete
inoremap <expr><C-e> neocomplcache#undo_completion()
" Enable omni completion.
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
" For cursor moving in insert mode
inoremap <expr><Left> neocomplcache#close_popup() . "\<Left>"
inoremap <expr><Right> neocomplcache#close_popup() . "\<Right>"
inoremap <expr><Up> neocomplcache#close_popup() . "\<Up>"
inoremap <expr><Down> neocomplcache#close_popup() . "\<Down>"
inoremap jj j
inoremap kk k
" disable preview in code complete
set completeopt-=preview
"-------------------------
" Arpeggio
" map jk to escape
call arpeggio#map('i', '', 0, 'jk', '<ESC>')
"--------------------------------------------------
" Colorscheme
" Use solarized colorscheme
colorscheme dracula
" Setting up light color scheme
set background=dark
" set highlighting for colorcolumn
highlight ColorColumn ctermbg=darkGrey
"--------------------------------------------------
" General options
" Enable per-directory .vimrc files and disable unsafe commands in them
"set exrc secure
" Buffer will be hidden instead of closed when no one display it
set hidden
" Auto reload changed files
set autoread
" Always change current dirrectory to current-editing-file dir
"set autochdir
" Indicates fast terminal connection
set ttyfast
" Set character encoding to use in vim
set encoding=utf-8
" Let vim know what encoding we use in our terminal
set termencoding=utf-8
" Which EOl used. For us it's unix
" Not works with modifiable=no
if &modifiable
set fileformat=unix
endif
" Enable Tcl interface. Not shure what is exactly mean.
" set infercase
" Interprete all files like binary and disable many features.
" set binary
"--------------------------------------------------
" Display options
" Hide showmode
" Showmode is useless with airline
set noshowmode
" Show file name in window title
set title
" Mute error bell
set novisualbell
" Remove all useless messages like intro screen and use abbreviation like RO
" instead readonly and + instead modified
set shortmess=atI
" Enable display whitespace characters
set list
" Setting up how to display whitespace characters
set listchars=tab:⇥\ ,trail:·,extends:⋯,precedes:⋯,nbsp:~
" Wrap line only on characters in breakat list like ^I!@*-+;:,./?
" Useless with nowrap
" set linebreak
" Numbers of line to scroll when the cursor get off the screen
" Useless with scrolloff
" set scrolljump=5
" Numbers of columns to scroll when the cursor get off the screen
" Useless with sidescrollof
" set sidescroll=4
" Numbers of rows to keep to the left and to the right off the screen
set scrolloff=10
" Numbers of columns to keep to the left and to the right off the screen
set sidescrolloff=10
" Vim will move to the previous/next line after reaching first/last char in
" the line with this commnad (you can add 'h' or 'l' here as well)
" <,> stand for arrows in command mode and [,] arrows in visual mode
set whichwrap=b,s,<,>,[,],
" Display command which you typing and other command related stuff
set showcmd
" Indicate that last window have a statusline too
set laststatus=2
" Add a line / column display in the bottom right-hand section of the screen.
" Not needed with airline plugin
"set ruler
" Setting up right-hand section(ruller) format
" Not needed with airline plugin
"set rulerformat=%30(%=\:%y%m%r%w\ %l,%c%V\ %P%)
" The cursor should stay where you leave it, instead of moving to the first non
" blank of the line
set nostartofline
" Disable wrapping long string
set nowrap
" Display Line numbers
set number
" Highlight line with cursor
set cursorline
" maximum text length at 80 symbols, vim automatically breaks longer lines
" set textwidth=80
" higlight column right after max textwidth
set colorcolumn=+1
"--------------------------------------------------
" Tab options
" Copy indent from previous line
set autoindent
" Enable smart indent. it add additional indents whe necessary
set smartindent
" Replace tabs with spaces
set expandtab
" Whe you hit tab at start of line, indent added according to shiftwidth value
set smarttab
" number of spaces to use for each step of indent
set shiftwidth=4
" Number of spaces that a Tab in the file counts for
set tabstop=4
" Same but for editing operation (not shure what exactly does it means)
" but in most cases tabstop and softtabstop better be the same
set softtabstop=4
" Round indent to multiple of 'shiftwidth'.
" Indentation always be multiple of shiftwidth
" Applies to < and > command
set shiftround
"--------------------------------------------------
" Search options
" Add the g flag to search/replace by default
set gdefault
" Highlight search results
set hlsearch
" Ignore case in search patterns
set ignorecase
" Override the 'ignorecase' option if the search patter ncontains upper case characters
set smartcase
" Live search. While typing a search command, show where the pattern
set incsearch
" Disable higlighting search result on Enter key
nnoremap <silent> <cr> :nohlsearch<cr><cr>
" Show matching brackets
set showmatch
" Make < and > match as well
set matchpairs+=<:>
"--------------------------------------------------
" Wildmenu
" Extended autocmpletion for commands
set wildmenu
" Autocmpletion hotkey
set wildcharm=<TAB>
"--------------------------------------------------
" Folding
" Enable syntax folding in javascript
let javaScript_fold=1
" No fold closed at open file
set foldlevelstart=99
set nofoldenable
" Keymap to toggle folds with space
nmap <space> za
"--------------------------------------------------
" Edit
" Allow backspace to remove indents, newlines and old text
set backspace=indent,eol,start
" toggle paste mode on \p
" set pastetoggle=<leader>p
" Add '-' as recognized word symbol. e.g dw delete all 'foo-bar' instead just 'foo'
set iskeyword+=-
" Disable backups file
set nobackup
" Disable vim common sequense for saving.
" By defalut vim write buffer to a new file, then delete original file
" then rename the new file.
set nowritebackup
" Disable swp files
set noswapfile
" Do not add eol at the end of file.
set noeol
"--------------------------------------------------
" Diff Options
" Display filler
set diffopt=filler
" Open diff in horizontal buffer
set diffopt+=horizontal
" Ignore changes in whitespaces characters
set diffopt+=iwhite
"--------------------------------------------------
" Hotkeys
" Open new tab
nmap <silent><leader>to :tabnew .<CR>
" Replace
nmap <leader>s :%s//<left>
vmap <leader>s :s//<left>
" Moving between splits
nmap <leader>w <C-w>w
"--------------------------------------------------
" Aautocmd
" It executes specific command when specific events occured
" like reading or writing file, or open or close buffer
if has("autocmd")
" Define group of commands,
" Commands defined in .vimrc don't bind twice if .vimrc will reload
augroup vimrc
" Delete any previosly defined autocommands
au!
" Auto reload vim after your cahange it
au BufWritePost *.vim source $MYVIMRC | AirlineRefresh
au BufWritePost .vimrc source $MYVIMRC | AirlineRefresh
" Restore cursor position :help last-position-jump
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal g'\"" | endif
" Set filetypes aliases
au FileType htmldjango set ft=html.htmldjango
au FileType scss set ft=scss.css
au FileType less set ft=less.css
au BufWinEnter * if line2byte(line("$") + 1) > 100000 | syntax clear | endif
au BufRead,BufNewFile *.js set ft=javascript.javascript-jquery
au BufRead,BufNewFile *.json set ft=json
" Execute python \ -mjson.tool for autoformatting *.json
au BufRead,BufNewFile *.bemhtml set ft=javascript
au BufRead,BufNewFile *.bemtree set ft=javascript
au BufRead,BufNewFile *.xjst set ft=javascript
au BufRead,BufNewFile *.tt2 set ft=tt2
au BufRead,BufNewFile *.plaintex set ft=plaintex.tex
" Auto close preview window, it uses with tags,
" I don't use it
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
" Disable vertical line at max string length in NERDTree
autocmd FileType * setlocal colorcolumn=+1
autocmd FileType nerdtree setlocal colorcolumn=""
" Not enable Folding - it really slow on large files, uses plugin vim-javascript-syntax
" au FileType javascript* call JavaScriptFold()
au FileType html let b:loaded_delimitMate = 1
au FileType handlebars let b:loaded_delimitMate = 1
" Group end
augroup END
endif
" ADD RIPGREP TO FZF
command! -bang -nargs=* Find call fzf#vim#grep('rg --column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --glob "!.git/*" --color "always" '.shellescape(<q-args>).'| tr -d "\017"', 1, <bang>0)
let g:fzf_layout = { 'window': 'enew' }
let g:fzf_files_options = "--min-height 30 --bind esc:cancel --height 100% --border --reverse --tabstop 2 --multi --margin 0,3,3,3 --preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -200'"
" use relative numbers in normal mode, absolute numbers in insert mode
autocmd InsertLeave,WinEnter * set relativenumber
autocmd InsertEnter,WinLeave * set norelativenumber
" Use :C to clear hlsearch
" ------------------------
command! C nohlsearch
set clipboard=unnamedplus
"Copy to the end of the line (to mimic D and C)
nnoremap Y y$
" Add current folder to path (and subfolders also)
set path+=**
set path+=.**
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
nmap \ :Find
let g:startify_change_to_vcs_root = 1
" Project specific override
let s:vimrc_project = $PWD . '/.local.vim'
if filereadable(s:vimrc_project)
execute 'source ' . s:vimrc_project
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment