Skip to content

Instantly share code, notes, and snippets.

@jedp
Created August 12, 2014 02:57
Show Gist options
  • Save jedp/a9950b3fa297906baa1a to your computer and use it in GitHub Desktop.
Save jedp/a9950b3fa297906baa1a to your computer and use it in GitHub Desktop.

Revisions

  1. jedp created this gist Aug 12, 2014.
    187 changes: 187 additions & 0 deletions .vimrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,187 @@
    if version < 704
    " if we are somehow running a version lower than 7.4,
    " something's wrong, so just stop processing this file.
    finish
    endif

    " auto reload vimrc after edit
    autocmd! bufwritepost .vimrc source %

    " vi? is it even possible to run original vi anymore?
    set nocompatible

    " Fix modelines security vulnerability
    " http://lists.alioth.debian.org/pipermail/pkg-vim-maintainers/2007-June/004020.html
    set modelines=0

    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " Tabs and indentation.
    set expandtab
    set smarttab
    set shiftwidth=4
    set tabstop=4
    set softtabstop=4

    " Above settings are friendly to Python and C
    " Javascript tab settings have been added in
    " ~/.vim/after/ftplugin/javascript.vim

    syntax enable
    filetype plugin indent on
    au BufNewFile,BufRead *.jsm set filetype=JavaScript
    au BufNewFile,BufRead *.sjs set filetype=JavaScript
    au BufNewFile,BufRead *.rdf set filetype=XML
    au BufNewFile,BufRead *.ino set filetype=C++ " arduino sketch

    set hidden " allow changing buffers without saving
    set nojoinspaces " don't insert two spaces when joining sentences
    set scrolloff=3 " keep 3 lines above and below when scrolling

    set autoindent
    set showmode
    set showcmd
    "set wildmenu
    "set wildmode=list:longest
    set visualbell
    set ttyfast " smoother redraw on newer terminals
    set laststatus=2
    set relativenumber " love relative line numbering
    set numberwidth=1 " use min spaces for numbers
    "set undofile
    "set ruler
    set list " display unprintable characters

    set encoding=utf-8

    set ignorecase " lowercase = case-insensitive
    set smartcase " mixed case = case-sensitive
    set gdefault " make g the default in :%s/foo/bar/
    set incsearch " highlight results as you type
    set showmatch " highlight matching brackets
    set matchtime=4 " blink matching brackets for 4/10 sec
    set hlsearch " highlight the last used pattern

    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " key mapping
    let mapleader=","

    " save a keystroke
    noremap ; :
    " searching and regexes
    nnoremap/ /\v
    vnoremap/ /\v
    " clear search
    nnoremap <leader><space> :noh<cr>
    " handle long lines
    " see :help fo-table for soft and hard wrapping
    set wrap
    set textwidth=79
    set formatoptions=qrn1
    set colorcolumn=80

    " forgot to open the file with sudo? no probalo
    cnoremap w!! w !sudo tee % >/dev/null
    " Justify text center, left, or right
    noremap <silent> <Leader>jc :center<CR>
    noremap <silent> <Leader>jl :left<CR>
    noremap <silent> <Leader>jr :right<CR>
    au FocusLost * :wa " save file when window focus is lost

    nnoremap <leader>q gqip " paragraph formatting
    nnoremap <leader>v V`] " select text just pasted
    " open and vertical split and switch over to file
    nnoremap <leader>w <C-w><C-w>l
    if has("gui_running")
    set guioptions=egmrt " hide the tool bar in gui vim
    endif

    set listchars=tab:▸\ ,extends:>,precedes:<

    set fo=cq " auto-wrap comments, format comments
    "set number " line numbering

    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " Highlight EOL whitespace
    " See http://vim.wikia.com/wiki/Highlight_unwanted_spaces
    highlight ExtraWhitespace ctermbg=red guibg=red
    autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red
    autocmd BufWinEnter * match ExtraWhitespace /\s\+$/

    " The above flashes annoyingly while typing, be calmer in insert mode
    autocmd InsertLeave * match ExtraWhitespace /\s\+$/
    autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/

    function! s:FixWhitespace(line1,line2)
    let l:save_cursor = getpos(".")
    silent! execute ':' . a:line1 . ',' . a:line2 . 's/\s\+$//'
    call setpos('.', l:save_cursor)
    endfunction

    " Run :FixWhitespace to remove end of line white space
    command! -range=% FixWhitespace call <SID>FixWhitespace(<line1>,<line2>)

    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " Plugins loaded with pathogen
    "
    " YouCompleteMe https://github.com/Valloric/YouCompleteMe.git
    " Requires git submodules --init --recursive
    " Then Compile with ./install.sh --clang-completer
    " jellybean https://github.com/nanotech/jellybeans.vim.git
    " jshint2 https://github.com/Shutnik/jshint2.vim.git
    " nerdtree https://github.com/scrooloose/nerdtree.git
    " powerline https://github.com/Lokaltog/powerline.git
    " Read https://powerline.readthedocs.org/en/latest/index.html
    " Note especially instructions regarding "hacked fonts"
    " syntastic https://github.com/scrooloose/syntastic.git
    " vim-javascript https://github.com/pangloss/vim-javascript.git

    execute pathogen#infect()
    call pathogen#helptags()

    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " YouCompleteMe
    " Default settings seem fine
    "let g:ycm_key_list_select_completion = ['<TAB>', '<Down>']

    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " jellybeans
    colorscheme jellybeans

    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " NERDTree
    "autocmd vimenter * NERDTree
    nnoremap <leader>nt :NERDTree<CR>
    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " powerline
    set rtp+=/Users/jed/.vim/bundle/powerline/powerline/bindings/vim
    set guifont=Source\ Code\ Pro\ for\ Powerline

    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " Syntastic checkers
    " XXX python is crashing for me
    " nb - using jshint for js
    " let g:syntastic_python_checkers

    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " jshint2
    let jshint2_command = "/Users/jed/code/node_modules/.bin/jshint"
    let jshint2_read = 1
    let jshint2_save = 1
    nnoremap <leader>jh :JSHint<CR>
    nnoremap <leader>jn :lnext<CR>
    nnoremap <leader>jp :lprevious<CR>
    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " vim-javascript
    " note that early version of vim 7.4 break this plugin
    let b:javascript_fold = 0
    let g:javascript_conceal = 1