init.vim 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. " Inspired from https://github.com/kristijanhusak/neovim-config/blob/master/init.vim
  2. " ================ dein config ===================
  3. if &compatible
  4. set nocompatible
  5. endif
  6. " Required:
  7. set runtimepath+=~/.local/share/dein/repos/github.com/Shougo/dein.vim
  8. " Required:
  9. if dein#load_state('~/.local/share/dein/')
  10. call dein#begin('~/.local/share/dein/')
  11. " Let dein manage dein
  12. " Required:
  13. call dein#add('~/.local/share/dein/repos/github.com/Shougo/dein.vim')
  14. " >>> Add or remove your plugins here <<<:
  15. ""
  16. call dein#add('Shougo/deoplete.nvim') " auto-complete
  17. call dein#add('Shougo/denite.nvim') " fuzzy-searching across files using :Denite grep
  18. call dein#add('Shougo/neosnippet.vim') " Include code snippets
  19. call dein#add('Shougo/neosnippet-snippets')
  20. call dein#add('honza/vim-snippets')
  21. call dein#add('freeo/vim-kalisi') "colorscheme
  22. call dein#add('ryanoasis/vim-devicons') " icons everywhere!
  23. call dein#add('Raimondi/delimitMate') " Automatic closing of quotes, brackets, etc.
  24. call dein#add('vim-airline/vim-airline') " action bar
  25. call dein#add('vim-airline/vim-airline-themes')
  26. call dein#add('tpope/vim-commentary') " Comment code easily
  27. call dein#add('tpope/vim-surround') " Surround with quotes, brackets
  28. call dein#add('tpope/vim-repeat') " Enable plugins to use repeat '.'
  29. call dein#add('scrooloose/nerdtree') " File browser
  30. call dein#add('Xuyuanp/nerdtree-git-plugin') " Git for nerdtree
  31. call dein#add('airblade/vim-gitgutter') " Git diff viewer
  32. call dein#add('duff/vim-bufonly') " Delete all buffers except current
  33. call dein#add('gregsexton/MatchTag') " Match HTML tags
  34. call dein#add('sheerun/vim-polyglot') " Language syntax,detect,indent,etc pack
  35. call dein#add('mhinz/vim-startify') " A nice start screen
  36. call dein#add('lambdalisue/gina.vim') " Git stuff
  37. call dein#add('eugen0329/vim-esearch') " Search in files easily
  38. call dein#add('posva/vim-vue') " Search in files easily
  39. " You can specify revision/branch/tag.
  40. " call dein#add('Shougo/vimshell', { 'rev': '3787e5' })
  41. " Required:
  42. call dein#end()
  43. call dein#save_state()
  44. endif
  45. " Required:
  46. filetype plugin indent on
  47. syntax enable
  48. " If you want to install not installed plugins on startup.
  49. if dein#check_install()
  50. call dein#install()
  51. endif
  52. if (has("termguicolors"))
  53. set termguicolors
  54. endif
  55. " ================ Plugin config =====================
  56. "
  57. let g:deoplete#enable_at_startup = 1
  58. let g:airline_powerline_fonts = 1 "Enable powerline fonts
  59. let g:airline_theme = "kalisi" "Set theme to powerline default theme
  60. let g:airline_section_y = '%{substitute(getcwd(), expand("$HOME"), "~", "g")}' "Set relative path
  61. let g:airline#extensions#whitespace#enabled = 0 "Disable whitespace extension
  62. let g:airline#extensions#tabline#enabled = 1 "Enable tabline extension
  63. let g:airline#extensions#tabline#left_sep = ' ' "Left separator for tabline
  64. let g:airline#extensions#tabline#left_alt_sep = '│' "Right separator for tabline
  65. let g:delimitMate_expand_cr = 1 "auto indent on enter
  66. let g:WebDevIconsNerdTreeAfterGlyphPadding = ' ' "Set up spacing for sidebar icons
  67. let g:neosnippet#disable_runtime_snippets = {'_' : 1} "Snippets setup
  68. let g:gitgutter_realtime = 0 "Disable gitgutter in realtime
  69. let g:gitgutter_eager = 0 "Disable gitgutter to eager load on tab or buffer switch
  70. let g:NERDTreeChDirMode = 2 "Always change the root directory
  71. let g:NERDTreeMinimalUI = 1 "Disable help text and bookmark title
  72. let g:NERDTreeShowHidden = 1 "Show hidden files in NERDTree
  73. let g:NERDTreeIgnore=['\.git$', '\.sass-cache$', '\.vagrant', '\.idea']
  74. let g:Tlist_Use_Right_Window = 1
  75. let g:neosnippet#snippets_directory = [
  76. \ '~/.local/share/dein//repos/github.com//honza/vim-snippets/snippets',
  77. \ '~/.local/share/dein/repos/github.com/Shougo/neosnippet-snippets/neosnippets',
  78. \ '~/.local/my-snippets']
  79. " Use silver searcher for recursive file search
  80. call denite#custom#var('file_rec', 'command',
  81. \ ['ag', '--follow', '--nocolor', '--nogroup', '-g', ''])
  82. " ================ General Config ====================
  83. let g:mapleader = "," "Change leader to a comma
  84. let g:enable_bold_font = 1 "Enable bold font in colorscheme
  85. colorscheme kalisi
  86. set t_Co=256 "Set 256 colors
  87. set title "change the terminal's title
  88. set relativenumber "relative numbers are good
  89. set history=500 "Store lots of :cmdline history
  90. set showcmd "Show incomplete cmds down the bottom
  91. set noshowmode "Hide showmode because of the powerline plugin
  92. set gdefault "Set global flag for search and replace
  93. set gcr=a:blinkon500-blinkwait500-blinkoff500 "Set cursor blinking rate
  94. set cursorline "Highlight current line
  95. set smartcase "Smart case search if there is uppercase
  96. set ignorecase "case insensitive search
  97. set mouse=a "Enable mouse usage
  98. set showmatch "Highlight matching bracket
  99. set nostartofline "Jump to first non-blank character
  100. set timeoutlen=1000 ttimeoutlen=200 "Reduce Command timeout for faster escape and O
  101. set fileencoding=utf-8 "Set utf-8 encoding on write
  102. set wrap "Enable word wrap
  103. set linebreak "Wrap lines at convenient points
  104. set listchars=tab:\ \ ,trail:· "Set trails for tabs and spaces
  105. set list "Enable listchars
  106. set lazyredraw "Do not redraw on registers and macros
  107. set completeopt-=preview "Disable preview for autocomplete
  108. set background=dark "Set background to dark
  109. set conceallevel=2 concealcursor=i "neosnippets conceal marker
  110. set splitright "Set up new splits positions
  111. syntax on "turn on syntax highlighting
  112. " ================ Persistent Undo ==================
  113. " Keep undo history across sessions, by storing in file.
  114. silent !mkdir ~/.config/nvim/backups > /dev/null 2>&1
  115. set undodir=~/.config/nvim/backups
  116. set undofile
  117. " ================ Indentation ======================
  118. set shiftwidth=4
  119. set softtabstop=4
  120. set tabstop=4
  121. set expandtab
  122. set smartindent
  123. set nofoldenable
  124. " ================ Completion =======================
  125. set wildmode=list:full
  126. set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
  127. set wildignore+=*vim/backups*
  128. set wildignore+=*sass-cache*
  129. set wildignore+=*cache*
  130. set wildignore+=*logs*
  131. set wildignore+=*node_modules/**
  132. set wildignore+=*DS_Store*
  133. set wildignore+=*.gem
  134. set wildignore+=log/**
  135. set wildignore+=tmp/**
  136. set wildignore+=*.png,*.jpg,*.gif
  137. " ================ Scrolling ========================
  138. set scrolloff=100 "Start scrolling when we're 100 lines away from margins
  139. set sidescrolloff=30
  140. set sidescroll=5
  141. " ================ Custom mappings ========================
  142. " Comment map
  143. nmap <Leader>c gcc
  144. " Line comment command
  145. xmap <Leader>c gc
  146. " Map save to Ctrl + S
  147. map <c-s> :w<CR>
  148. imap <c-s> <C-o>:w<CR>
  149. " Also save with ,w
  150. nnoremap <Leader>w :w<CR>
  151. " Easier window navigation
  152. nmap <C-h> <C-w>h
  153. nmap <C-j> <C-w>j
  154. nmap <C-k> <C-w>k
  155. nmap <C-l> <C-w>l
  156. " Down is really the next line
  157. nnoremap j gj
  158. nnoremap k gk
  159. " Expand snippets on tab if snippets exists, otherwise do autocompletion
  160. imap <expr><TAB> neosnippet#expandable_or_jumpable() ?
  161. \ "\<Plug>(neosnippet_expand_or_jump)"
  162. \ : pumvisible() ? "\<C-n>" : "\<TAB>"
  163. " If popup window is visible do autocompletion from back
  164. imap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<S-Tab>"
  165. " Fix for jumping over placeholders for neosnippet
  166. smap <expr><TAB> neosnippet#jumpable() ?
  167. \ "\<Plug>(neosnippet_jump)"
  168. \: "\<TAB>"
  169. " Yank to the end of the line
  170. nnoremap Y y$
  171. " Copy to system clipboard
  172. vnoremap <C-c> "+y
  173. " Paste from system clipboard with Ctrl + v
  174. inoremap <C-v> <Esc>"+p
  175. nnoremap <Leader>p "0p
  176. vnoremap <Leader>p "0p
  177. " Move to the end of yanked text after yank and paste
  178. nnoremap p p`]
  179. vnoremap y y`]
  180. vnoremap p p`]
  181. " Move selected lines up and down
  182. vnoremap J :m '>+1<CR>gv=gv
  183. vnoremap K :m '<-2<CR>gv=gv
  184. " Clear search highlight
  185. nnoremap <Leader><space> :noh<CR>
  186. " Handle syntastic error window
  187. nnoremap <Leader>e :lopen<CR>
  188. nnoremap <Leader>q :lclose<CR>
  189. " Find current file in NERDTree
  190. nnoremap <Leader>hf :NERDTreeFind<CR>
  191. " Open NERDTree
  192. nnoremap <Leader>n :NERDTreeToggle<CR>
  193. " Toggle between last 2 buffers
  194. nnoremap <leader><tab> <c-^>
  195. " Auto change directory to match current file
  196. nnoremap <Leader>dc :cd %:p:h<CR>:pwd<CR>
  197. " Maps for indentation in normal mode
  198. nnoremap <tab> >>
  199. nnoremap <s-tab> <<
  200. " Indenting in visual mode
  201. xnoremap <s-tab> <gv
  202. xnoremap <tab> >gv
  203. " Resize window with shift + and shift -
  204. nnoremap + <c-w>5>
  205. nnoremap _ <c-w>5<
  206. " Center highlighted search
  207. nnoremap n nzz
  208. nnoremap N Nzz
  209. nnoremap <c-p> :Denite file_rec<CR>
  210. nnoremap <Leader>t :TlistToggle<CR>
  211. " Go to normal mode in terminal by pressing esc
  212. tnoremap <Esc> <C-\><C-n>
  213. " Always go at beginning of first word in line
  214. nnoremap 0 ^
  215. " ================ Abbreviations ====================
  216. cnoreabbrev Wq wq
  217. cnoreabbrev WQ wq
  218. cnoreabbrev W w
  219. cnoreabbrev Q q
  220. cnoreabbrev Qa qa
  221. cnoreabbrev Bd bd
  222. cnoreabbrev bD bd
  223. cnoreabbrev wrap set wrap
  224. cnoreabbrev nowrap set nowrap
  225. cnoreabbrev bda BufOnly
  226. cnoreabbrev t tabe
  227. cnoreabbrev T tabe
  228. cnoreabbrev den Denite
  229. " ================ Functions ========================
  230. function! s:StripTrailingWhitespaces()
  231. let l:l = line(".")
  232. let l:c = col(".")
  233. %s/\s\+$//e
  234. call cursor(l:l, l:c)
  235. endfunction
  236. function! s:LoadLocalVimrc()
  237. if filereadable(glob(getcwd() . '/.vimrc.local'))
  238. :execute 'source '.fnameescape(glob(getcwd(). '/.vimrc.local'))
  239. endif
  240. endfunction
  241. " ================ Auto commands ======================
  242. augroup vimrc
  243. autocmd!
  244. augroup END
  245. autocmd vimrc BufWritePre * :call s:StripTrailingWhitespaces() "Auto-remove trailing spaces
  246. autocmd vimrc InsertLeave * NeoSnippetClearMarkers "Remove unused markers for snippets
  247. autocmd vimrc InsertEnter * :set nocul "Remove cursorline highlight
  248. autocmd vimrc InsertLeave * :set cul "Add cursorline highlight in normal mode
  249. " autocmd vimrc FileType html,javascript,coffee,cucumber setlocal sw=2 sts=2 ts=2 "Set 2 indent for html
  250. " autocmd vimrc FileType php,javascript setlocal cc=80 "Set right margin only for php and js
  251. autocmd vimrc VimEnter,BufNewFile,BufReadPost * call s:LoadLocalVimrc() "Load per project vimrc (Used for custom test mappings, etc.)
  252. autocmd vimrc VimEnter * set vb t_vb=
  253. autocmd vimrc FileType nerdtree syntax match hideBracketsInNerdTree
  254. \ "\]" contained conceal containedin=ALL