Advertisement
Guest User

.vimrc

a guest
Dec 11th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 13.47 KB | None | 0 0
  1. set nocompatible              " be iMproved, required
  2. filetype off                  " required
  3.  
  4. " set the runtime path to include Vundle and initialize
  5. set rtp+=~/.vim/bundle/Vundle.vim
  6. call vundle#begin()
  7. " alternatively, pass a path where Vundle should install plugins
  8. "call vundle#begin('~/some/path/here')
  9.  
  10. " let Vundle manage Vundle, required
  11. Plugin 'VundleVim/Vundle.vim'
  12.  
  13. " The following are examples of different formats supported.
  14. " Keep Plugin commands between vundle#begin/end.
  15. " plugin on GitHub repo
  16. Plugin 'tpope/vim-fugitive'
  17. " plugin from http://vim-scripts.org/vim/scripts.html
  18. " Plugin 'L9'
  19. " Git plugin not hosted on GitHub
  20. Plugin 'git://git.wincent.com/command-t.git'
  21. " git repos on your local machine (i.e. when working on your own plugin)
  22. " The sparkup vim script is in a subdirectory of this repo called vim.
  23. " Pass the path to set the runtimepath properly.
  24. Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
  25. " Install L9 and avoid a Naming conflict if you've already installed a
  26. " different version somewhere else.
  27. " Plugin 'ascenator/L9', {'name': 'newL9'}"
  28. " Plugin 'valloric/youcompleteme'
  29. Plugin 'scrooloose/nerdtree'
  30. Plugin 'terryma/vim-multiple-cursors'
  31.  
  32. Plugin 'tpope/vim-sensible'
  33. Plugin 'tpope/vim-surround'
  34. Plugin 'scrooloose/syntastic'
  35. Plugin 'ctrlpvim/ctrlp.vim'
  36. Plugin 'pangloss/vim-javascript'
  37. Plugin 'airblade/vim-gitgutter'
  38. Plugin 'altercation/vim-colors-solarized'
  39. Plugin 'nathanaelkane/vim-indent-guides'
  40. Plugin 'bronson/vim-trailing-whitespace'
  41. Plugin 'mtscout6/syntastic-local-eslint.vim'
  42. Plugin 'hail2u/vim-css3-syntax'
  43. Plugin 'styled-components/vim-styled-components'
  44. Plugin 'Valloric/YouCompleteMe'
  45. Plugin 'flowtype/vim-flow'
  46. " All of your Plugins must be added before the following line
  47. call vundle#end()            " required
  48. filetype plugin indent on    " required
  49. " To ignore plugin indent changes, instead use:
  50. "filetype plugin on
  51. "
  52. " Brief help
  53. " :PluginList       - lists configured plugins
  54. " :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
  55. " :PluginSearch foo - searches for foo; append `!` to refresh local cache
  56. " :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
  57. "
  58. " see :h vundle for more details or wiki for FAQ
  59. " Put your non-Plugin stuff after this line
  60. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  61. " Maintainer:
  62. "       Amir Salihefendic
  63. "       http://amix.dk - amix@amix.dk
  64. "
  65. " Version:
  66. "       6.0 - 01/04/17 14:24:34
  67. "
  68. " Blog_post:
  69. "       http://amix.dk/blog/post/19691#The-ultimate-Vim-configuration-on-Github
  70. "
  71. " Awesome_version:
  72. "       Get this config, nice color schemes and lots of plugins!
  73. "
  74. "       Install the awesome version from:
  75. "
  76. "           https://github.com/amix/vimrc
  77. "
  78. " Syntax_highlighted:
  79. "       http://amix.dk/vim/vimrc.html
  80. "
  81. " Raw_version:
  82. "       http://amix.dk/vim/vimrc.txt
  83. "
  84. " Sections:
  85. "    -> General
  86. "    -> VIM user interface
  87. "    -> Colors and Fonts
  88. "    -> Files and backups
  89. "    -> Text, tab and indent related
  90. "    -> Visual mode related
  91. "    -> Moving around, tabs and buffers
  92. "    -> Status line
  93. "    -> Editing mappings
  94. "    -> vimgrep searching and cope displaying
  95. "    -> Spell checking
  96. "    -> Misc
  97. "    -> Helper functions
  98. "
  99. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  100.  
  101.  
  102. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  103. " => General
  104. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  105. " Sets how many lines of history VIM has to remember
  106. set history=500
  107.  
  108. " Enable filetype plugins
  109. filetype plugin on
  110. filetype indent on
  111.  
  112. " Set to auto read when a file is changed from the outside
  113. set autoread
  114.  
  115. " With a map leader it's possible to do extra key combinations
  116. " like <leader>w saves the current file
  117. let mapleader = ","
  118. let g:mapleader = ","
  119.  
  120. " Fast saving
  121. nmap <leader>w :w!<cr>
  122.  
  123. " :W sudo saves the file
  124. " (useful for handling the permission-denied error)
  125. command W w !sudo tee % > /dev/null
  126.  
  127.  
  128. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  129. " => VIM user interface
  130. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  131. " Set 7 lines to the cursor - when moving vertically using j/k
  132. set so=7
  133.  
  134. " Avoid garbled characters in Chinese language windows OS
  135. let $LANG='en'
  136. set langmenu=en
  137. source $VIMRUNTIME/delmenu.vim
  138. source $VIMRUNTIME/menu.vim
  139.  
  140. " Turn on the WiLd menu
  141. set wildmenu
  142.  
  143. " Ignore compiled files
  144. set wildignore=*.o,*~,*.pyc
  145. if has("win16") || has("win32")
  146.     set wildignore+=.git\*,.hg\*,.svn\*
  147. else
  148.     set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
  149. endif
  150.  
  151. "Always show current position
  152. set ruler
  153.  
  154. " Height of the command bar
  155. set cmdheight=2
  156.  
  157. " A buffer becomes hidden when it is abandoned
  158. set hid
  159.  
  160. " Configure backspace so it acts as it should act
  161. set backspace=eol,start,indent
  162. set whichwrap+=<,>,h,l
  163.  
  164. " Ignore case when searching
  165. set ignorecase
  166.  
  167. " When searching try to be smart about cases
  168. set smartcase
  169.  
  170. " Highlight search results
  171. set hlsearch
  172.  
  173. " Makes search act like search in modern browsers
  174. set incsearch
  175.  
  176. " Don't redraw while executing macros (good performance config)
  177. set lazyredraw
  178.  
  179. " For regular expressions turn magic on
  180. set magic
  181.  
  182. " Show matching brackets when text indicator is over them
  183. set showmatch
  184. " How many tenths of a second to blink when matching brackets
  185. set mat=2
  186.  
  187. " No annoying sound on errors
  188. set noerrorbells
  189. set novisualbell
  190. set t_vb=
  191. set tm=500
  192.  
  193. " Properly disable sound on errors on MacVim
  194. if has("gui_macvim")
  195.     autocmd GUIEnter * set vb t_vb=
  196. endif
  197.  
  198.  
  199. " Add a bit extra margin to the left
  200. set foldcolumn=1
  201.  
  202.  
  203. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  204. " => Colors and Fonts
  205. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  206. " Enable syntax highlighting
  207. syntax enable
  208.  
  209. " Enable 256 colors palette in Gnome Terminal
  210. if $COLORTERM == 'gnome-terminal'
  211.     set t_Co=256
  212. endif
  213.  
  214. try
  215.     colorscheme desert
  216. catch
  217. endtry
  218.  
  219. set background=dark
  220.  
  221. " colorscheme solarized
  222.  
  223. " Set extra options when running in GUI mode
  224. if has("gui_running")
  225.     set guioptions-=T
  226.     set guioptions-=e
  227.     set t_Co=256
  228.     set guitablabel=%M\ %t
  229. endif
  230.  
  231. " Set utf8 as standard encoding and en_US as the standard language
  232. set encoding=utf8
  233.  
  234. " Use Unix as the standard file type
  235. set ffs=unix,dos,mac
  236.  
  237.  
  238. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  239. " => Files, backups and undo
  240. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  241. " Turn backup off, since most stuff is in SVN, git et.c anyway...
  242. set nobackup
  243. set nowb
  244. set noswapfile
  245.  
  246.  
  247. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  248. " => Text, tab and indent related
  249. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  250. " Use spaces instead of tabs
  251. set expandtab
  252.  
  253. " Be smart when using tabs ;)
  254. set nosmarttab
  255.  
  256. " 1 tab == 2 spaces
  257. set shiftwidth=2
  258. set tabstop=2
  259. set et
  260. let g:indent_guides_start_level=2
  261. let g:indent_guides_enable_on_vim_startup=1
  262.  
  263. " let g:indent_guides_auto_colors = 0
  264. " autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd  guibg=red   ctermbg=3
  265. " autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=green ctermbg=4
  266.  
  267. " Linebreak on 500 characters
  268. set lbr
  269. set tw=500
  270.  
  271. set ai "Auto indent
  272. set si "Smart indent
  273. set wrap "Wrap lines
  274.  
  275.  
  276. """"""""""""""""""""""""""""""
  277. " => Visual mode related
  278. """"""""""""""""""""""""""""""
  279. " Visual mode pressing * or # searches for the current selection
  280. " Super useful! From an idea by Michael Naumann
  281. vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
  282. vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
  283.  
  284.  
  285. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  286. " => Moving around, tabs, windows and buffers
  287. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  288. " Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search)
  289. map <space> /
  290. map <c-space> ?
  291.  
  292. " Disable highlight when <leader><cr> is pressed
  293. map <silent> <leader><cr> :noh<cr>
  294.  
  295. " Smart way to move between windows
  296. map <C-j> <C-W>j
  297. map <C-k> <C-W>k
  298. map <C-h> <C-W>h
  299. map <C-l> <C-W>l
  300.  
  301. " Close the current buffer
  302. map <leader>bd :Bclose<cr>:tabclose<cr>gT
  303.  
  304. " Close all the buffers
  305. map <leader>ba :bufdo bd<cr>
  306.  
  307. map <leader>l :bnext<cr>
  308. map <leader>h :bprevious<cr>
  309.  
  310. " Useful mappings for managing tabs
  311. map <leader>tn :tabnew<cr>
  312. map <leader>to :tabonly<cr>
  313. map <leader>tc :tabclose<cr>
  314. map <leader>tm :tabmove
  315. map <leader>t<leader> :tabnext
  316.  
  317. " Let 'tl' toggle between this and the last accessed tab
  318. let g:lasttab = 1
  319. nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
  320. au TabLeave * let g:lasttab = tabpagenr()
  321.  
  322.  
  323. " Opens a new tab with the current buffer's path
  324. " Super useful when editing files in the same directory
  325. map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
  326.  
  327. " Switch CWD to the directory of the open buffer
  328. map <leader>cd :cd %:p:h<cr>:pwd<cr>
  329.  
  330. " Specify the behavior when switching between buffers
  331. try
  332.   set switchbuf=useopen,usetab,newtab
  333.   set stal=2
  334. catch
  335. endtry
  336.  
  337. " Return to last edit position when opening files (You want this!)
  338. au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
  339.  
  340.  
  341. """"""""""""""""""""""""""""""
  342. " => Status line
  343. """"""""""""""""""""""""""""""
  344. " Always show the status line
  345. set laststatus=2
  346.  
  347. " Format the status line
  348. set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
  349. set statusline+=%#warningmsg#
  350. set statusline+=%{SyntasticStatuslineFlag()}
  351. set statusline+=%*
  352.  
  353.  
  354. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  355. " => Editing mappings
  356. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  357. " Remap VIM 0 to first non-blank character
  358. map 0 ^
  359.  
  360. " Move a line of text using ALT+[jk] or Command+[jk] on mac
  361. nmap <M-j> mz:m+<cr>`z
  362. nmap <M-k> mz:m-2<cr>`z
  363. vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
  364. vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
  365.  
  366. if has("mac") || has("macunix")
  367.   nmap <D-j> <M-j>
  368.   nmap <D-k> <M-k>
  369.   vmap <D-j> <M-j>
  370.   vmap <D-k> <M-k>
  371. endif
  372.  
  373. " Delete trailing white space on save, useful for some filetypes ;)
  374. fun! CleanExtraSpaces()
  375.     let save_cursor = getpos(".")
  376.     let old_query = getreg('/')
  377.     silent! %s/\s\+$//e
  378.     call setpos('.', save_cursor)
  379.     call setreg('/', old_query)
  380. endfun
  381.  
  382. if has("autocmd")
  383.     autocmd BufWritePre *.txt,*.js,*.jsx,*.py,*.wiki,*.sh,*.coffee :call CleanExtraSpaces()
  384. endif
  385.  
  386.  
  387. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  388. " => Spell checking
  389. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  390. " Pressing ,ss will toggle and untoggle spell checking
  391. map <leader>ss :setlocal spell!<cr>
  392.  
  393. " Shortcuts using <leader>
  394. map <leader>sn ]s
  395. map <leader>sp [s
  396. map <leader>sa zg
  397. map <leader>s? z=
  398.  
  399.  
  400. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  401. " => Misc
  402. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  403. " Remove the Windows ^M - when the encodings gets messed up
  404. noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
  405.  
  406. " Quickly open a buffer for scribble
  407. map <leader>q :e ~/buffer<cr>
  408.  
  409. " Quickly open a markdown buffer for scribble
  410. map <leader>x :e ~/buffer.md<cr>
  411.  
  412. " Toggle paste mode on and off
  413. map <leader>pp :setlocal paste!<cr>
  414.  
  415. " Run ctrlp
  416. map <leader>, :CtrlP<cr>
  417.  
  418.  
  419. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  420. " => Helper functions
  421. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  422. " Returns true if paste mode is enabled
  423. function! HasPaste()
  424.     if &paste
  425.         return 'PASTE MODE  '
  426.     endif
  427.     return ''
  428. endfunction
  429.  
  430. " Don't close window, when deleting a buffer
  431. command! Bclose call <SID>BufcloseCloseIt()
  432. function! <SID>BufcloseCloseIt()
  433.    let l:currentBufNum = bufnr("%")
  434.    let l:alternateBufNum = bufnr("#")
  435.  
  436.    if buflisted(l:alternateBufNum)
  437.      buffer #
  438.    else
  439.      bnext
  440.    endif
  441.  
  442.    if bufnr("%") == l:currentBufNum
  443.      new
  444.    endif
  445.  
  446.    if buflisted(l:currentBufNum)
  447.      execute("bdelete! ".l:currentBufNum)
  448.    endif
  449. endfunction
  450.  
  451. function! CmdLine(str)
  452.     exe "menu Foo.Bar :" . a:str
  453.     emenu Foo.Bar
  454.     unmenu Foo
  455. endfunction
  456.  
  457. function! VisualSelection(direction, extra_filter) range
  458.     let l:saved_reg = @"
  459.     execute "normal! vgvy"
  460.  
  461.     let l:pattern = escape(@", "\\/.*'$^~[]")
  462.    let l:pattern = substitute(l:pattern, "\n$", "", "")
  463.  
  464.    if a:direction == 'gv'
  465.        call CmdLine("Ack '" . l:pattern . "' " )
  466.    elseif a:direction == 'replace'
  467.        call CmdLine("%s" . '/'. l:pattern . '/')
  468.    endif
  469.  
  470.    let @/ = l:pattern
  471.    let @" = l:saved_reg
  472. endfunction
  473. set number
  474. set mouse+=a
  475. autocmd StdinReadPre * let s:std_in=1
  476. " autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
  477.  
  478. let g:syntastic_always_populate_loc_list = 1
  479. let g:syntastic_auto_loc_list = 1
  480. let g:syntastic_check_on_open = 1
  481. let g:syntastic_check_on_wq = 0
  482. let g:syntastic_javascript_checkers = ['eslint']
  483. let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard |grep -v "\.png" |grep -v "dist\/"']
  484. let g:ycm_server_python_interpreter = '/usr/bin/python2'
  485. let g:javascript_plugin_jsdoc = 1
  486. let g:javascript_plugin_flow = 1
  487. let g:flow#autoclose = 1
  488. let g:flow#errjmp = 0
  489. let g:flow#omnifunc = 1
  490.  
  491. map <leader>gg :YcmCompleter GoTo<cr>
  492. map <leader>gr :YcmCompleter GoToReferences<cr>
  493. map <leader>gt :YcmCompleter GetType<cr>
  494. map <leader>gd :YcmCompleter GetDoc<cr>
  495. map <leader>gs :YcmCompleter RestartServer<cr>
  496. map <leader>rf :YcmCompleter RefactorRename<cr>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement