Skip to content

Instantly share code, notes, and snippets.

@rawaludin
Last active March 1, 2016 15:45
Show Gist options
  • Save rawaludin/89521671393a640d187f to your computer and use it in GitHub Desktop.
Save rawaludin/89521671393a640d187f to your computer and use it in GitHub Desktop.
" File: init.vim
" Author: Rahmat Awaludin <rahmat.awaludin@dmail.com>
"
" How I configure neovim :P
call plug#begin('~/.config/nvim/plugged')
" ----- Making Vim look good ------------------------------------------
Plug 'altercation/vim-colors-solarized'
Plug 'vim-airline/vim-airline'
" ----- Vim as a programmer's text editor -----------------------------
Plug 'scrooloose/nerdtree'
" Plug 'jistr/vim-nerdtree-tabs' " make same nerdtree all tabs
" Plug 'scrooloose/syntastic' " use neomake instead
" Plug 'xolox/vim-misc'
" Plug 'xolox/vim-easytags'
" Plug 'majutsushi/tagbar'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': 'yes \| ./install' }
Plug 'ctrlpvim/ctrlp.vim'
Plug 'tacahiroy/ctrlp-funky'
Plug 'terryma/vim-multiple-cursors'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'mattn/emmet-vim'
Plug 'easymotion/vim-easymotion'
Plug 'tomtom/tcomment_vim'
Plug 'terryma/vim-expand-region'
Plug 'tobyS/pdv' " php docblock
Plug 'ryanoasis/vim-devicons' " add icon to nerdtree and airline
" ----- Vim for Designer ----------------------------------
Plug 'KabbAmine/vCoolor.vim'
" ----- Working with Git ----------------------------------------------
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
" ----- Working with Markdown ----------------------------------------------
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
Plug 'junegunn/goyo.vim' " distraction mode
Plug 'junegunn/limelight.vim' " focus on paraghraph while writing
Plug 'reedes/vim-colors-pencil' " ia writer inspired theme
" ----- Other text editing features -----------------------------------
Plug 'Raimondi/delimitMate'
Plug 'ervandew/supertab'
Plug 'SirVer/ultisnips'
Plug 'Valloric/YouCompleteMe'
" ----- man pages, tmux -----------------------------------------------
Plug 'jez/vim-superman'
" Plug 'christoomey/vim-tmux-navigator'
" ---- Extras/Advanced plugins ----------------------------------------
" Highlight and strip trailing whitespace
" Plug 'ntpeters/vim-better-whitespace'
call plug#end()
" --- General seoentttings ---
" allow backspacing over everything in insert mode
set ruler " show the cursor position all the time
set number " line numbers
set showcmd " display incomplete commands
set autowriteall
set clipboard=unnamed " share clipboard with OSX
set wrap linebreak nolist " better word wrap
" Tab settings
set expandtab " Expand tabs into spaces
set tabstop=2 " default to 2 spaces for a hard tab
set softtabstop=2 " default to 2 spaces for the soft tab
set shiftwidth=2 " for when <TAB> is pressed at the beginning of a line
" Fold setings
set foldmethod=indent " Fold based on indent
set foldnestmax=10 " deepest fold is 10 levels
set nofoldenable " dont fold by default
set updatetime=250 " change file update time from 4 s to 0.25s for gitgutter
set colorcolumn=80 " column guide at 80 char
set ignorecase " ignore case on autocomplete command
set hidden " hide error when opening file but current buffer has
" unsaved changes
au FocusLost * silent! wa " autosave when focus is lost, not save unsaved buffer
set shell=zsh " use zsh as shell, don't forget to ln -s ~/.zshrc ~/.zshenv
set encoding=utf8 " set encoding to utf8, so ryanoasis/vim-devicons would work
let $NVIM_TUI_ENABLE_TRUE_COLOR=1 " support true color
" different cursor on insert and normal mode (only work for iTerm2)
let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1
" --- set leader key to space ---
let mapleader = " "
" ----- General Leader key binding ---
" quit by <space>q
nmap <silent> <leader>q :q<CR>
" force quit by <space>qq
nmap <silent> <leader>qq :q!<CR>
" save by <space>w
nmap <silent> <leader>w :w<CR>
" save and quit by <space>wq
nmap <silent> <leader>wq :wq<CR>
" Copy current buffer path relative to root of VIM session to system clipboard
nnoremap <Leader>yp :let @*=expand("%")<cr>:echo "Copied file path to clipboard"<cr>
" Copy current filename to system clipboard
nnoremap <Leader>yf :let @*=expand("%:t")<cr>:echo "Copied file name to clipboard"<cr>
" Copy current buffer path without filename to system clipboard
nnoremap <Leader>yd :let @*=expand("%:h")<cr>:echo "Copied file directory to clipboard"<cr>
" previous buffer by [
map [ :bp<cr>
" next buffer by ]
map ] :bn<cr>
" delete buffer <space>d
map <silent> <leader>d :bd<cr>
" close all buffer <space>bufdo BD
map <silent> <leader>D :bufdo bd<CR>
" switch pane by <space>w arrow
nnoremap <leader>w <C-W>
" select last pasted block by `gp`
nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
" exit insert mode by `nn`
" imap nn <Esc>
" ----- On the fly vimrc file editing -----
" edit vimrc file by <space>v
nmap <leader>v :edit $MYVIMRC<CR>
" ----- Custom command ------------------------------------------------
" delete all trailing whitespace in current buffer by :strip
function! <SID>StripTrailingWhitespaces()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
command! Strip call <SID>StripTrailingWhitespaces()<CR>
" ----- Plugin-Specific Settings --------------------------------------
" ----- terryma/vim-expand-region -----
" expand selection in visual mode by v
vmap v <Plug>(expand_region_expand)
" shrink selection in visual mode by ctrl+v
vmap <C-v> <Plug>(expand_region_shrink)
" ----- tobyS/pdv settings -----
let g:pdv_template_dir = $HOME ."/.vim/plugged/pdv/templates_snip"
" nnoremap <buffer> <C-u> :call pdv#DocumentWithSnip()<CR>
" ----- YouCompleteMe and UltiSnips -----
" make YCM compatible with UltiSnips (using supertab)
let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
let g:SuperTabDefaultCompletionType = '<C-n>'
set completeopt-=preview " disable preview window at all
" let g:ycm_add_preview_to_completeopt = 0 " disable preview window
" better key bindings for UltiSnipsExpandTrigger
let g:UltiSnipsExpandTrigger = "<tab>"
let g:UltiSnipsJumpForwardTrigger = "<tab>"
let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
" -----------------------------------------------------------------------------
" ----- junegunn/limelight settings -----
" Color name (:help cterm-colors) or ANSI code
let g:limelight_conceal_ctermfg = 'gray'
let g:limelight_conceal_ctermfg = 240
" autoactivate / deactivate on enter / leave goyo mode
" autocmd! User GoyoEnter Limelight
" autocmd! User GoyoLeave Limelight!
" -----------------------------------------------------------------------------
" ----- junegunn/goyo.vim settings ----
" activate goyo when opening markdown
au BufNewFile,BufRead *.{md,mdown,mkd,mkdn,markdown,mdwn} Goyo
au BufNewFile,BufFilePre,BufRead *.md set filetype=markdown " set syntax as markdown when opening md
" fix `:q` on goyo
" -----------------------------------------------------------------------------
" ----- easymotion settings ------
let g:EasyMotion_do_mapping = 0 " Disable default mappings
" Jump to anywhere you want with minimal keystrokes, with just one key
" binding.
" " `f{char}{label}`
nmap f <Plug>(easymotion-overwin-f)
" Turn on case insensitive feature
let g:EasyMotion_smartcase = 1"
" -----------------------------------------------------------------------------
" ----- altercation/vim-colors-solarized settings -----
" Toggle this to "light" for light colorscheme
set background=dark
" Uncomment the next line if your terminal is not configured for solarized
"let g:solarized_termcolors=256
" Set the colorscheme
" colorscheme solarized
colorscheme pencil
" -----------------------------------------------------------------------------
" ----- bling/vim-airline settings -----
" Always show statusbar
set laststatus=2
" Fancy arrow symbols, requires a patched font
" To install a patched font, run over to
" https://github.com/abertsch/Menlo-for-Powerline
" download all the .ttf files, double-click on them and click "Install"
" Finally, uncomment the next line
let g:airline_powerline_fonts = 1
" Show PASTE if in paste mode
let g:airline_detect_paste=1
" Show airline for tabs too
let g:airline#extensions#tabline#enabled = 1
" -----------------------------------------------------------------------------
" ----- scrooloose/nerdtree settings -----
" Open/close NERDTree Tabs with <space>t
nmap <silent> <leader>t :NERDTreeTabsToggle<CR>
" Open synced tree with <space>ts
nmap <silent> <leader>ts :NERDTreeFind<CR>
" To have NERDTree always open on startup set this to 1
let g:nerdtree_tabs_open_on_console_startup = 0
" -----------------------------------------------------------------------------
" ----- scrooloose/syntastic settings -----
" let g:syntastic_error_symbol = '✘'
" let g:syntastic_warning_symbol = "▲"
" augroup mySyntastic
" " au!
" au FileType tex let b:syntastic_mode = "passive"
" augroup END
" -----------------------------------------------------------------------------
" ----- xolox/vim-easytags settings -----
" Where to look for tags files
" set tags=./tags;,~/.vimtags
" Sensible defaults
" let g:easytags_events = ['BufReadPost', 'BufWritePost']
" let g:easytags_async = 1
" let g:easytags_dynamic_files = 2
" let g:easytags_resolve_links = 1
" let g:easytags_suppress_ctags_warning = 1
" -----------------------------------------------------------------------------
" ----- majutsushi/tagbar settings -----
" Open/close tagbar with \b
" nmap <silent> <leader>rt :TagbarToggle<CR>
" Uncomment to open tagbar automatically whenever possible
"autocmd BufEnter * nested :call tagbar#autoopen(0)
" -----------------------------------------------------------------------------
" ----- ctrlpvim/ctrlp.vim settings ------
" use ag for faster ctrlp
let g:ctrlp_use_caching = 0
if executable('ag')
set grepprg=ag\ --nogroup\ --nocolor
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
else
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
let g:ctrlp_prompt_mappings = {
\ 'AcceptSelection("e")': ['<space>', '<cr>', '<2-LeftMouse>'],
\ }
endif
" -----------------------------------------------------------------------------
" ---- ctrlp-funky settings ----
" Open/close ctrlp-funky with <space>r (jump to method)
nmap <silent> <leader>r :CtrlPFunky<CR>
" -----------------------------------------------------------------------------
" ----- junegunn/fzf ----
" use ag for searching, search hidden, ignore .gitignore, skip whats in .git
let $FZF_DEFAULT_COMMAND = 'ag --hidden -U --ignore .git -g ""' "
" fuzzy open file in current project with <space>p
nmap <silent> <leader>p :FZF<CR>
" List recent opened file <space>u
command! FZFMru call fzf#run({'source': v:oldfiles,'sink' : 'e ','options' : '-m',})
nmap <silent> <leader>u :FZFMru<CR>
" Jump to opened file (buffer) with <space><Enter>
function! s:buflist()
redir => ls
silent ls
redir END
return split(ls, '\n')
endfunction
function! s:bufopen(e)
execute 'buffer' matchstr(a:e, '^[ 0-9]*')
endfunction
nnoremap <silent> <Leader><Enter> :call fzf#run({
\ 'source': reverse(<sid>buflist()),
\ 'sink': function('<sid>bufopen'),
\ 'options': '+m',
\ 'down': len(<sid>buflist()) + 2
\ })<CR>
" -----------------------------------------------------------------------------
" ----- airblade/vim-gitgutter settings -----
" Required after having changed the colorscheme
hi clear SignColumn
" In vim-airline, only display "hunks" if the diff is non-zero
let g:airline#extensions#hunks#non_zero_only = 1
" -----------------------------------------------------------------------------
" ----- Raimondi/delimitMate settings -----
let delimitMate_expand_cr = 1
augroup mydelimitMate
au!
au FileType markdown let b:delimitMate_nesting_quotes = ["`"]
au FileType tex let b:delimitMate_quotes = "
au FileType tex let b:delimitMate_matchpairs = "(:),[:],{:},`:'"
au FileType python let b:delimitMate_nesting_quotes = ['"', "'"]
augroup END"'"'"]"']"
" -----------------------------------------------------------------------------
" ----- plasticboy/vim-markdown -----
let g:vim_markdown_folding_disabled=1 " disable folding because performance,
" see https://github.com/plasticboy/vim-markdown/issues/162
" disable indent when new paragraph with `o` from list
au BufNewFile,BufRead *.{md,mdown,mkd,mkdn,markdown,mdwn} setlocal indentexpr=''
" Close TOC after click enter on heading link
nnoremap <expr><enter> &ft=="qf" ? "<cr>:lcl<cr>" : (getpos(".")[2]==1 ? "i<cr><esc>": "i<cr><esc>l")
" -----------------------------------------------------------------------------
" ----- jez/vim-superman settings -----
" better man page support
noremap K :SuperMan <cword><CR>
" -----------------------------------------------------------------------------
" ----- tacahiroy/ctrlp-funky -----
" syntax highlighting
let g:ctrlp_funky_syntax_highlight = 1
" matched chars highlighting
let g:ctrlp_funky_matchtype = 'path'
" -----------------------------------------------------------------------------
" ----- mattn/emmet-vim settigs -----
let g:user_emmet_install_global = 0
autocmd FileType html,css,php EmmetInstall
let g:user_emmet_leader_key='<Tab>' " autocomplete emmet by <Tab><comma>
" -----------------------------------------------------------------------------
" ----- text bubling -----
" Bubble single lines
nmap <C-Up> [e
nmap <C-Down> ]e
" Bubble multiple lines
vmap <C-Up> [egv
vmap <C-Down> ]egv
" -----------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment