" ============================================================================== " vimrc file for niblock :: Use `:so %` to re-source after changes " ============================================================================== " ============================================================================== " General Settings " ============================================================================== set nocompatible " Why? (https://goo.gl/2RiJoo) if !exists('g:syntax_on') syntax enable " Syntax hilighting endif filetype plugin indent on " Enable filetype/indent/plugins set encoding=utf-8 " Character encoding set spelllang=en_us " Set default dictionary set autoread " Auto-reload modified files set hidden " Allow for un-saved buffers set autochdir " Change directory automatically set autoindent " Enable auto-indentation set expandtab " Spaces for tab set shiftwidth=4 " Spaces per shift set softtabstop=4 " Spaces to use when editing set number " Enable line numbers set wrap " Wrap text set textwidth=80 " How long a line is set winwidth=90 " Minimum width of a window set scrolloff=5 " 5 line scroll buffer set foldmethod=indent " Fold on indent set foldlevelstart=99 " No default folding set wildmenu " Enable wildmenu set wildmode:longest:full,full " Configure wildmenu set ignorecase smartcase " Ignore case, unless it matters set incsearch " Zoom to results as I search set nohlsearch " Disable search highlighting let g:netrw_liststyle=3 " Netrw Tree list style let g:netrw_banner=0 " Disable the netrw banner augroup ruby_settings " Custom settings: Ruby{-like} autocmd! autocmd FileType ruby,eruby,yaml \ setlocal shiftwidth=2 \ softtabstop=2 \ makeprg=rubocop augroup END augroup spellcheckr " Spelling, for some files... autocmd! autocmd BufNewFile,BufRead *.md,*.rdoc,*.txt,*.wiki \ setlocal spell augroup END augroup lintr " Linting, based on :make! autocmd! autocmd BufWritePost *.rb,*.sh \ silent make! | silent redraw! autocmd QuickFixCmdPost [^l]* cwindow augroup END " ============================================================================== " Colors " ============================================================================== augroup user_stl_colors " Custom status-line colors autocmd! autocmd ColorScheme * \ hi User1 term=bold cterm=bold ctermfg=Red ctermbg=DarkGrey | \ hi User2 term=bold cterm=bold ctermfg=Cyan ctermbg=DarkGrey | \ hi User3 term=bold cterm=bold ctermfg=White ctermbg=DarkGrey | \ hi User4 ctermfg=White ctermbg=Black | \ hi User5 ctermfg=150 ctermbg=Black | \ hi User6 ctermfg=Grey ctermbg=Black augroup END if filereadable(expand('~/.vim/colors/minimalist.vim')) colorscheme minimalist " Set colorscheme endif " ============================================================================== " Status Line " ============================================================================== set laststatus=2 " Enable the statusline set statusline= " Initialize it set statusline+=%3*%m " Modified flag set statusline+=%6*%{expand('%:p:h')}/ " Full-path to current buffer set statusline+=%4*%t " File name set statusline+=%5*%{GitBranch()} " Show Git branch, if applicable set statusline+=%= " Switch to right-side set statusline+=%4*%y\ " Filetype set statusline+=%3* " Color change (see :hi) set statusline+=\|%4l\:%2c\| " Line and column set statusline+=%2*%{&spell?'[SPELL]':''} " Spell flag set statusline+=%1*%r%0* " Read-only flag " ============================================================================== " Mappings " ============================================================================== let mapleader = ',' " Make moving up/down work on wrapped lines of text nnoremap j gj nnoremap k gk nnoremap ^ g^ nnoremap $ g$ " Toggle fold with space if we're in a fold, otherwise just space nnoremap @=(foldlevel('.')?'za':"\") vnoremap zf " Allow saving of files as sudo when I forgot to start vim using sudo. cmap w!! w !sudo tee > /dev/null % " Remove Trailing Whitespaace nnoremap rtw :%s/\s\+$//e " Open help topic in a full new tab command! -nargs=1 -complete=help H :tabnew | :set buftype=help | :h " Simple mapping to dotfiles directory (f = current tab; F = new tab) nnoremap f :edit ~/.dotfiles/ nnoremap F :tabnew ~/.dotfiles/ " Emulate vim-vinegar nnoremap - :silent edit =empty(expand('%')) ? '.' : expand('%:p:h') " Some notes/wiki shortcuts nnoremap ww :edit ~/Documents/Wiki/index.md nnoremap ws :vsplit ~/Documents/Wiki/scratchpad.md nnoremap wt :vsplit ~/Documents/Wiki/to-do.md nnoremap wd :edit ~/Documents/Wiki/diary/diary.wiki nnoremap tj :call NewJournal() " ============================================================================== " Functions " ============================================================================== " Read from the journal template, and replace 'Date' with today's date function! NewJournal() abort .-1read ~/.vim/templates/journal s/Date/\=strftime("%A, %B %d")/ endfunction " Fetch the git branch of the current file, if applicable function! GitBranch() abort let l:branchname = system("git rev-parse --abbrev-ref HEAD 2>/dev/null \ | tr -d '\n'") return strlen(l:branchname) > 0 ? '#'.l:branchname : '' endfunction " ============================================================================== " Plugins " ============================================================================== if filereadable(expand('~/.vimrc-plugins')) source ~/.vimrc-plugins endif