Skip to content

Instantly share code, notes, and snippets.

@nfarrar nfarrar/.vimrc
Created Nov 21, 2014

Embed
What would you like to do?
" Author: Nathan Farrar
" Email: nathan.farrar@gmail.com
" Website: http://crunk.io/
" INITIALIZATION {{{1
" This file is utf-8. Ensure we read it correctly.
scriptencoding utf-8
" If we're running vim-tiny or vim-small stop sourcing the vim configuration.
if !1 | finish | endif
" If we're using vim, disable vi compatibility (enaable vim features).
if has('vim_starting')
set nocompatible
endif
" Sometimes our operating system tries to set defaults for us that get in our
" way. The following line resets all the configured settings to the defaults.
" set all&
" I keep my autocommands in the autocommand group 'vimrc'. Since we don't want
" to redefine them everytime we reload our vim configuration, we delete them
" here.
if has('augroup')
augroup vimrc
autocmd!
augroup END
endif
" The following allows us to determine our operating system so that we can
" do some platform-specific configuration. Note the 'mac' feature is only
" true if we're using macvim on osx. In this case, "unix" will also be true.
let s:is_mac = has('mac') || has('macunix') || has('gui_macvim')
let s:is_win = has('win16') || has('win32') || has('win64')
let s:is_cygwin = has('win32unix')
let s:is_unix = has('unix') && ! s:is_mac && ! s:is_cygwin
" FUNCTIONS {{{1
" This function creates a specified directory if it does not exist.
function! EnsureDirectory (dir)
if !isdirectory(a:dir)
if exists("*mkdir")
call mkdir(a:dir,'p')
echo "Created directory: " . a:dir
else
echo "Please create directory: " . a:dir
endif
endif
endfunction
" Testing custom fold labels.
function! CustomFoldText()
let nl = v:foldend - v:foldstart + 1
let comment = substitute(getline(v:foldstart),"^ *","",1)
let linetext = substitute(getline(v:foldstart+1),"^ *","",1)
let txt = '+ ' . linetext . ' : "' . comment . '" : length ' . nl
return txt
endfunction
" Testing custom fold labels.
function! CustomFoldText2()
let line = getline(v:foldstart)
let nucolwidth = &fdc + &number * &numberwidth
let windowwidth = winwidth(0) - nucolwidth - 3
let foldedlinecount = v:foldend - v:foldstart
" expand tabs into spaces
let onetab = strpart(' ', 0, &tabstop)
let line = substitute(line, '\t', onetab, 'g')
let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
let fillcharcount = windowwidth - len(line) - len(foldedlinecount) - 4
return line . '' . repeat(" ",fillcharcount) . foldedlinecount . ' '
endfunction
" Return the identation level of the specified line. If no line is specified
" the return the indentation level of the current line. Used primarily for
" debugging indent-based folding scripts.
function! IndentLevel(...)
if a:0 > 0
let lnum = a:1
else
let lnum = line(".")
endif
return indent(lnum) / &shiftwidth
endfunction
" Return the fold level of the specified line. If no line is specified
" then return the indentation leve of the current line. Used primarly for
" debugging folding scripts.
function! FoldLevel(...)
if a:0 > 0
let lnum = a:1
else
let lnum = line(".")
endif
" return foldlevel(lnum) / &shiftwidth
return foldlevel(lnum)
endfunction
" REQUIRED DIRECTORIES {{{1
" This configuration requires the following directories to store various vim
" files.
call EnsureDirectory($HOME . '/.vim/backup')
call EnsureDirectory($HOME . '/.vim/bundle')
call EnsureDirectory($HOME . '/.vim/debug')
call EnsureDirectory($HOME . '/.vim/swap')
call EnsureDirectory($HOME . '/.vim/undo')
call EnsureDirectory($HOME . '/.vim/view')
" PLUGINS {{{1
" Install NeoBundle if it's not present.
if !isdirectory(expand('~/.vim/bundle/neobundle.vim'))
echo "Installing NeoBundle ...\n"
silent execute '!mkdir -p ~/.vim/bundle'
silent execute '!git clone https://github.com/Shougo/neobundle.vim
\ ~/.vim/bundle/neobundle.vim'
endif
" Disable plugin and indent detection for NeoBundle.
filetype plugin indent off
" Add the NeoBundle plugin directory to the runtime path.
set runtimepath+=~/.vim/bundle/neobundle.vim/
" Use https as the default git protocol.
let g:neobundle_default_git_protocol = 'https'
" Starting our NeoBundle initialization.
call neobundle#begin(expand('~/.vim/bundle/'))
" Let NeoBundle manage NeoBundle.
NeoBundleFetch "Shougo/neobundle.vim"
" PLugins.
NeoBundle 'flazz/vim-colorschemes' " monolithic colorscheme pack
NeoBundle 'sheerun/vim-polyglot' " monolithic language pack
NeoBundle 'LokiChaos/vim-tintin' " tintin language syntax
NeoBundle 'vim-scripts/restore_view.vim' " use viewoptions to restore views
NeoBundle 'myusuf3/numbers.vim' " better line numbering
NeoBundle 'ciaranm/securemodelines' " make modelines less secure
NeoBundle 'vim-scripts/utl.vim' "
" End of Neobundle initialization.
call neobundle#end()
" Install Bundles:
" If we have defined bundles in the previous section that are not installed,
" this will prompt us to install them.
NeoBundleCheck
" Update Bundles:
" TODO: Add logic to run this automatically at a specific interval.
" Update our bundles. This executes slowly, so we don't want it to run every
" time we start vim.
" NeoBundleCheckUpdate
" Cleanup Bundles:
" TODO: Add logic to run this automatically at a specific interval.
" This removes bundles that are no longer defined. We don't want this to run
" everytime we start vim.
" NeoBundleClean
" Re-enable filetype-based indentation and plugins.
filetype indent plugin on
" SETTINGS {{{1
" If the shellslash feature is available and we're using cygwin, enable it.
if exists('+shellslash') && s:is_cygwin
set shellslash
endif
" character encoding
set encoding=utf-8 " default encoding used inside vim
set fileformats="unix,dos,mac" " the EOL order type matching
" backup files
set dir+=~/.vim/swap/ " swap file directory
set bdir+=~/.vim/backup/ " backup file directory
set undodir=~/.vim/undo// " undo directory
set undofile " persistent backup file
set undolevels=1000 " number of changes that can be undone
set undoreload=10000 " number of changes to load with buffer
" editor behavior
set backspace=indent,eol,start " backspace over everything in insert mode
set confirm " dialogues rather than error messages
set formatoptions+=1 " don't end lines with 1-letter words when wrapping paragraphs
set ignorecase " ignore case when searching
set incsearch " show matches as you type
set lazyredraw " don't update display during macros
set noerrorbells " no beeping!
set smartcase " do not ignore case when search pattern is mixed-case
set textwidth=80 " maximum width of text when inserting
set title " set the window title
set visualbell " disable visual bell
" indentation
set autoindent " always turn on autoindent
set copyindent " copy the previous indent when autoindenting
set expandtab " expand all tabs (to spaces) by default
set softtabstop=4 " when backspacing, pretend a tab is removed (4 spaces)
set shiftwidth=4 " number of spaces used for autoindenting
set shiftround " use a multiple of shiftwidth when using < and >
set tabstop=4 " tab == 4 spaces
set smarttab " insert tabs on start of line according to shiftwidth, not tabstop
set smartindent
" menu behavior
set wildmenu " better tab-completion for buffers
set wildmode=list:full " show a list when hitting tab
set wildignore=*.swp,*.bak,*.pyc,*.class
" terminal settings
set termencoding=utf-8 " encoding type used in the terminal
set t_Co=256 " enable 256 color support
set ttyfast " improve performance with fast ttys
" visual styling
syntax on " enable syntax highlighting
colorscheme jellybeans " use jellybeans colorscheme
set background=dark " assume a dark background
set cmdheight=2 " 2-line status bar
set colorcolumn=81 " highlight column at 81 spaces
set cursorline " highlight the current line
set hidden " allow buffer switching without saving
set hlsearch " highlight search terms
set laststatus=2 " always show status line
set mousehide " hide the mouse cursor while typing
set number " show line numbers
set scrolloff=4 " keep 4 lines off the edges of the screen
set showcmd " show partial command on last line
set showmatch " highlight matching parens/braces
set showmode " always show the current editing mode
" unprintable characters
set list
set listchars=tab:▸\ " tab representation
set listchars+=extends: " extended line representation
set listchars+=precedes: " reverse extended line
set listchars+=nbsp:␣ " non breaking space
set listchars+=trail:· " trailing spaces
set showbreak= " wraped lines
" set listchars=tab:▸\ ,trail:·,extends:#,nbsp:·
" set nowrap " do not wrap lines
" set wrapscan " wrap searches to start of buffer
" set virtualedit=block,onemore " allow the cursor anywhere
" set gdefault " search/replace with the /g flag by default
" FEATURE SETTINGS {{{1
" mouse support
if has('mouse')
set mouse=a
if has('mouse_sgr') || v:version > 703 || v:version == 703 && has('patch632')
set ttymouse=sgr
else
set ttymouse=xterm2
endif
" Paste
nnoremap <RightMouse> "+p
xnoremap <RightMouse> "+p
inoremap <RightMouse> <C-r><C-o>+
cnoremap <RightMouse> <C-r>+
endif
" clipboard support
if has('clipboard') " better clipboard integration.
if has('unnamedplus') " use + register for copy-paste
set clipboard=unnamed,unnamedplus
else
set clipboard=unnamed " on osx & windows, use * register for
endif " copy-paste
endif
" PLUGIN SETTINGS {{{1
" restore_view.vim
set viewoptions=cursor,folds,slash,unix
let g:skipview_files = ['*\.vim']
" utl.vim
if has("mac")
let g:utl_cfg_hdl_scm_http_system = "!open '%u'"
end
nmap <leader>o :Utl
" AUTO COMMANDS {{{1
" reload our vimrc whenever its modified
augroup myvimrc
au!
au BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so
\ $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
augroup END
" redraw the cursorline and cursorcolumn highlighting when switching windows
au WinLeave * set nocursorline nocursorcolumn
au WinEnter * set cursorline cursorcolumn
" Open help files in a tab instead of split.
" cabbrev help tab help
" KEY BINDINGS {{{1
let mapleader="," " change mapleader to ,
" Source our $VIMRC file.
:nmap <Leader>s :source $MYVIMRC
" Open our $MYVIMRC in a new tab.
nmap <leader>v :tabedit $MYVIMRC<CR>
" Resize windows with the arrow keys
noremap <up> <C-W>+
noremap <down> <C-W>-
noremap <left> 3<C-W>>
noremap <right> 3<C-W><
" Spell correct current word
imap <c-z> <esc>,zea
" replace visual selection with yank register when you hit p
" vnoremap p <Esc>:let current_reg = @"<CR>gvdi<C-R>=current_reg<CR><Esc>
" Clear the current search pattern and return to the previous cursor position.
" nnoremap <esc> :let @/=""<CR><CR>
" Toggle folds open/closed by pressing F9. If you have :set foldmethod=manual,
" you can visually select some lines, then press F9 to create a fold.
inoremap <F9> <C-O>za
nnoremap <F9> za
onoremap <F9> <C-C>za
vnoremap <F9> zf
" Press space to toggle the current fold open/closed.
" If the cursor is not in a fold, move to the right (the default behavior).
" In addition, with the manual fold method, you can create a fold by visually
" selecting some lines, then pressing Space.
" nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
" vnoremap <Space> zf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.