Vimrc

.vimrc Configuration file for vim editor in Unix.

Preview

Vimrc - 图1

Configuration

Package manager

First install Vundle

Fonts & Symbols

  • In OSX, install powerline symbols for Airline plugin
  • In iTerm, set non-ASCII font to Powerline.

Setup .vimrc file

Usually found in ~/.vimrc

Replace your current .vimrc file content with the following blob.

  1. set nocompatible " be improved, required
  2. filetype off " required
  3. " Vundle is the package manager
  4. set rtp+=~/.vim/bundle/Vundle.vim
  5. call vundle#begin()
  6. " alternatively, pass a path where Vundle should install plugins
  7. " call vundle#begin('~/some/path/here')
  8. " let Vundle manage Vundle, required
  9. Plugin 'VundleVim/Vundle.vim'
  10. " Color theme
  11. Plugin 'crusoexia/vim-monokai'
  12. " NERDTREE
  13. Plugin 'scrooloose/nerdtree.git'
  14. " close vim if NERDTREE is the only window left
  15. autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
  16. " Ctrl-P to search/open files
  17. Plugin 'ctrlpvim/ctrlp.vim.git'
  18. let g:ctrlp_map = '<leader>p' " Map :CtrlP
  19. let g:ctrlp_cmd = 'CtrlP' " Map :CtrlP
  20. let g:ctrlp_custom_ignore = {
  21. \ 'dir': '\v[\/](\.git|node_modules|build)$',
  22. \ 'file': '\v\.(exe|so|dll)$',
  23. \ }
  24. " Syntaxis checker
  25. Plugin 'scrooloose/syntastic.git'
  26. set statusline+=%#warningmsg#
  27. set statusline+=%{SyntasticStatuslineFlag()}
  28. set statusline+=%*
  29. let g:syntastic_always_populate_loc_list = 1
  30. let g:syntastic_auto_loc_list = 1
  31. let g:syntastic_check_on_open = 1
  32. let g:syntastic_check_on_wq = 0
  33. " JS syntax highlighting
  34. Plugin 'pangloss/vim-javascript'
  35. " JSX highlighting. Depends on 'pangloss/vim-javascript'
  36. Bundle 'mxw/vim-jsx'
  37. let g:jsx_ext_required = 0 " to enable jsx in .js files
  38. " Use eslint
  39. let g:syntastic_javascript_checkers = ['eslint']
  40. " Inserts pairs of quotes, brackets, braces
  41. Plugin 'jiangmiao/auto-pairs.git'
  42. " Cool status bar
  43. Plugin 'vim-airline/vim-airline'
  44. " use powerline symbols
  45. let g:airline_powerline_fonts = 1
  46. " EditorConfig
  47. Plugin 'editorconfig/editorconfig-vim'
  48. " Elm synthax highlight
  49. Plugin 'lambdatoast/elm.vim.git'
  50. " Highlight html in JS string templates
  51. Plugin 'Quramy/vim-js-pretty-template'
  52. " All of your Plugins must be added before the following line
  53. call vundle#end() " required
  54. filetype plugin indent on " required
  55. " Put your non-Plugin stuff after this line
  56. set number
  57. set tabstop=2
  58. set shiftwidth=2
  59. set expandtab
  60. set autoindent
  61. set smarttab
  62. set colorcolumn=80,100,120
  63. set ruler
  64. let mapleader = "-"
  65. nnoremap <leader>w <c-w>
  66. nnoremap <leader>n :NERDTreeToggle<CR>
  67. syntax on
  68. set t_Co=256
  69. colorscheme monokai

Vundle

Vundle is the plugin/package manager

To ignore plugin indent changes, instead use:
filetype plugin on

commands description
:PluginList lists configured plugins
:PluginInstall installs plugins; append ! to update or just :PluginUpdate
:PluginSearch foo searches for foo; append ! to refresh local cache
:PluginClean confirms removal of unused plugins; append ! to auto-approve removal

See :h vundle for more details or wiki for FAQ

Plugins installed in this .vimrc

name source description
Monokai crusoexia/vim-monokai Color theme like SublimeText
NerdTree scrooloose/nerdtree.git Navigator side-bar
Ctrl-P ctrlpvim/ctrlp.vim.git File opener
Syntastic scrooloose/syntastic.git Syntax highlighting
Vim Javascript pangloss/vim-javascript JS highlighting
Vim JSX mxw/vim-jsx JSX support
Auto Pairs jiangmiao/auto-pairs.git Automatically closes {},[], "", '', etc.
Airline vim-airline/vim-airline Cool status bar
Editor Config editorconfig/editorconfig-vim Enables text editor rules in .editorconfig

Troubleshooting

  1. When copy-pasting this config for the second time, the autopair plugin can insert " where there
    shouldn’t be. That might comment out code that you need.
  2. Also the long command for the NERDTREE might be split by the copy-paste. Make sure it is in one single line.
  3. If tern server fails, make sure you run npm i in the bundle directory.