Skip to content

Instantly share code, notes, and snippets.

@spruce-bruce
Last active February 8, 2017 22:08
Show Gist options
  • Save spruce-bruce/b0aeb1a3d00a0a9f427db1d0de7d6520 to your computer and use it in GitHub Desktop.
Save spruce-bruce/b0aeb1a3d00a0a9f427db1d0de7d6520 to your computer and use it in GitHub Desktop.
Setting up vim for javascript development

Setting up vim for javascript development

Even though most of this stuff has nothing to do with javascript

Install vim 8

The newest version of vim won't necessarily be the version you have installed. Run vim --version to check your version. brew install vim --override-system-vim is the easiest way to install the latest version on mac.

Plugins

TODO

Colors

  1. Make sure you have colors turned on in your terminal. Add export CLICOLOR=1 to your .bash_profile
  2. In order to have really nice colors, use 256 colors with iterm2. I highly recommend using the base16 project's themes in iterm2.
  3. You also have to do the installation steps for base16-shell. Use the colortest script provided to make sure everything looks right in your shell before configuring in vim.
  4. Once you have 256 colors in your terminal you can install (and configure) the base16-vim plugin. Make sure you have the line syntax on in your .vimrc.

JS and JSX

Simply install these two plugins. They should require little to no configuration.

  1. vim-javascript
  2. vim-jsx

Syntax checking and linting

I like syntastic. Syntastic does not yet make use of vim 8 async features, though, so you'll need to jump through some hoops to get fast linting. If linting doesn't seem to be working debug by running eslint_d /path/to/your/file. Usually any problem with linting is because of the linter on the machine and not becuase of syntastic configuration.

  1. Install eslint_d. It runs eslint as a daemon so it doesn't have overhead every time the eslint command is run.
  2. I configure syntastic like this in my .vimrc:
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 2
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

let g:syntastic_javascript_checkers = ['eslint']
let g:syntastic_javascript_eslint_exec = 'eslint_d'
let g:syntastic_javascript_eslint_args = '--parser=babel-eslint'
let g:syntastic_javascript_eslint_args = "--cache"
let g:jsx_ext_required=0

Nicer UI elements

" AIRLINE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

let g:airline#extensions#tabline#enabled = 1
let g:airline_theme='bubblegum'
set laststatus=2
set ttimeoutlen=50

File navigation

" NERDTREE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <C-n> :NERDTreeToggle<CR>
let g:NERDTreeWinSize=40
let NERDSpaceDelims=1

Code Folding

TODO

Search

Vim uses third party search applications. By default it uses grep which can be quite slow. There are lots of alternatives, like the silver searcher or ripgrep. Ripgrep is the new hotness so I'm using that.

You can install ripgrep with brew install ripgrep. Then configure your .vimrc like this:

" SEARCH - RIPGREP (shamelessly stolen from thoughtbot)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

if executable('rg')
  set grepprg=rg\ --vimgrep\ --no-heading\ --ignore-case .            " tell vim to "grep" with ripgrep
  set grepformat=%f:%l:%c:%m,%f:%l:%m         
  let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'  " tell ctrlp to use ripgrep
  let g:ctrlp_use_caching = 0
endif

command -nargs=+ -complete=file -bar Rg silent! grep! <args>|cwindow|redraw!    " create a :Rg command that searches
nnoremap \ :Rg<SPACE>                                                           " map :Rg to \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment