From bb21c0b6b5a89eff0722641123982d34a2b6f395 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 31 Oct 2014 18:12:14 +0100 Subject: vim: Switching from yadr to VAM. Includes all modifications for vimrc, the loading of plugins and their customization. --- .gitignore | 7 +- .vim/addons-settings.vim | 181 ++++++++++++++++++++++++++++++++++ .vim/addons.vim | 56 +++++++++++ .vim/custom-functions.vim | 37 +++++++ .vim/custom-settings.vim | 240 ++++++++++++++++++++++++++++++++++++++++++++++ .vimrc | 118 +++++++++++++++++++++++ 6 files changed, 636 insertions(+), 3 deletions(-) create mode 100644 .vim/addons-settings.vim create mode 100644 .vim/addons.vim create mode 100644 .vim/custom-functions.vim create mode 100644 .vim/custom-settings.vim create mode 100644 .vimrc diff --git a/.gitignore b/.gitignore index 4a31867..533d9ca 100644 --- a/.gitignore +++ b/.gitignore @@ -332,12 +332,13 @@ svn/ .tuxguitar-1.2/ .unescaped_colors.rb .vdirsyncer/status -.vim +.vim/backups/ +.vim/sessions/ +.vim/vim-addons/ .viminfo .vimperator/ .vimpressrc -.vimrc -.viminf* +.viminfo .vmoviedb/ .wine .wireshark/ diff --git a/.vim/addons-settings.vim b/.vim/addons-settings.vim new file mode 100644 index 0000000..77a36aa --- /dev/null +++ b/.vim/addons-settings.vim @@ -0,0 +1,181 @@ +" ================ CTRLP settings ================ +if exists("g:ctrlp_user_command") + unlet g:ctrlp_user_command +endif +if executable('ag') + " Use ag in CtrlP for listing files. Lightning fast and respects .gitignore + let g:ctrlp_user_command = + \ 'ag %s --files-with-matches -g "" --ignore "\.git$\|\.hg$\|\.svn$"' + + " ag is fast enough that CtrlP doesn't need to cache + let g:ctrlp_use_caching = 0 +else + " Fall back to using git ls-files if Ag is not available + let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$' + let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . --cached --exclude-standard --others'] +endif + +" Default to filename searches - so that appctrl will find application +" controller +let g:ctrlp_by_filename = 1 + +" Don't jump to already open window. This is annoying if you are maintaining +" several Tab workspaces and want to open two windows into the same file. +let g:ctrlp_switch_buffer = 0 + +" We don't want to use Ctrl-p as the mapping because +" it interferes with YankRing (paste, then hit ctrl-p) +let g:ctrlp_map = ',t' +nnoremap ,t :CtrlP + +" Additional mapping for buffer search +nnoremap ,b :CtrlPBuffer + +" Cmd-Shift-P to clear the cache +nnoremap :ClearCtrlPCache + +" Idea from : http://www.charlietanksley.net/blog/blog/2011/10/18/vim-navigation-with-lustyexplorer-and-lustyjuggler/ +" Open CtrlP starting from a particular path, making it much +" more likely to find the correct thing first. mnemonic 'jump to [something]' +map ,ja :CtrlP app/assets +map ,jm :CtrlP app/models +map ,jc :CtrlP app/controllers +map ,jv :CtrlP app/views +map ,jh :CtrlP app/helpers +map ,jl :CtrlP lib +map ,jp :CtrlP public +map ,js :CtrlP spec +map ,jf :CtrlP fast_spec +map ,jd :CtrlP db +map ,jC :CtrlP config +map ,jV :CtrlP vendor +map ,jF :CtrlP factories +map ,jT :CtrlP test + +"Cmd-Shift-(M)ethod - jump to a method (tag in current file) +"Ctrl-m is not good - it overrides behavior of Enter +nnoremap :CtrlPBufTag + +" ================ fugitive settings ================ +" For fugitive.git, dp means :diffput. Define dg to mean :diffget +nnoremap ,dg :diffget +nnoremap ,dp :diffput +" The tree buffer makes it easy to drill down through the directories of your +" git repository, but it’s not obvious how you could go up a level to the +" parent directory. Here’s a mapping of .. to the above command, but +" only for buffers containing a git blob or tree +autocmd User fugitive + \ if fugitive#buffer().type() =~# '^\%(tree\|blob\)$' | + \ nnoremap .. :edit %:h | + \ endif + +" Every time you open a git object using fugitive it creates a new buffer. +" This means that your buffer listing can quickly become swamped with +" fugitive buffers. This prevents this from becomming an issue: + +autocmd BufReadPost fugitive://* set bufhidden=delete + +" ================ jquery settings ================ +autocmd BufRead,BufNewFile *.js set ft=javascript syntax=jquery + +" ================ lightline settings ================ +let g:lightline = { + \ 'colorscheme': 'wombat', + \ 'active': { + \ 'left': [ [ 'mode' ], + \ [ 'fugitive', 'readonly', 'filename', 'modified' ] ] + \ }, + \ 'component': { + \ 'readonly': '%{&readonly?"⭤":""}', + \ 'fugitive': '%{exists("*fugitive#head")?fugitive#head():""}' + \ }, + \ 'component_visible_condition': { + \ 'fugitive': '(exists("*fugitive#head") && ""!=fugitive#head())' + \ }, + \ 'separator': { 'left': '⮀', 'right': '⮂' }, + \ 'subseparator': { 'left': '⮁', 'right': '⮃' } + \ } + +set laststatus=2 + +" ================ nerdtree-tabs settings ================ +" Auto open nerd tree on startup +let g:nerdtree_tabs_open_on_gui_startup = 0 +" Focus in the main content window +let g:nerdtree_tabs_focus_on_files = 1 + +" ================ nerdtree settings ================ +" Make nerdtree look nice +let NERDTreeMinimalUI = 1 +let NERDTreeDirArrows = 1 +let g:NERDTreeWinSize = 30 + +" ================ persistent-undo settings ================ +" persistent undos - undo after you re-open the file +" but this gives warnings under command line vim +" use only in macvim +if v:version > '702' + set undodir=~/.vim/backups + set undofile +endif + +" ================ showmarks settings ================ +" Tell showmarks to not include the various brace marks (),{}, etc +let g:showmarks_include = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY" + +" ================ syntastic settings ================ +"mark syntax errors with :signs +let g:syntastic_enable_signs=1 +"automatically jump to the error when saving the file +let g:syntastic_auto_jump=0 +"show the error list automatically +let g:syntastic_auto_loc_list=1 +"don't care about warnings +let g:syntastic_quiet_messages = {'level': 'warnings'} + +" ================ tComment settings ================ +" tComment maps 'gcc' to comment current line +" this adds 'gcp' comment current paragraph (block) +" using tComment's built in p mapping +nmap gcp p + +" ================ tidy settings ================ +:vmap ,gt :!tidy -q -i --show-errors 0 + +" ================ vim-indent-guides settings ================ +let g:indent_guides_auto_colors = 1 +let g:indent_guides_start_level = 2 +let g:indent_guides_guide_size = 1 + +" ================ vim-session settings ================ +" Prevent vim-session from asking us to load the session. +" If you want to load the session, use :SaveSession and :OpenSession +let g:session_autosave = 'no' +let g:session_autoload = 'no' + +" ================ tabular settings ================ +" Hit Cmd-Shift-A then type a character you want to align by +nmap :Tabularize / +vmap :Tabularize / + +" ================ sudo settings ================ +" w!! to write a file as sudo +" stolen from Steve Losh +cmap w!! w !sudo tee % >/dev/null + +" ================ YankRing settings ============== + +let g:yankring_history_dir = '$HOME/.vim' +"let g:yankring_history_file = '.yankring-history' +nnoremap ,yr :YRShow +nnoremap :YRShow + +" ================ vim-processing settings ============== +let g:processing_doc_style='local' +let g:processing_doc_path='~/.vim/bundle/vim-processing/syntax/processing.vim' + +" ================ vim-colors-solarized ============== +let g:solarized_termcolors=256 +let g:solarized_termtrans=1 +"set background=black +"colorscheme solarized diff --git a/.vim/addons.vim b/.vim/addons.vim new file mode 100644 index 0000000..470014c --- /dev/null +++ b/.vim/addons.vim @@ -0,0 +1,56 @@ +" git +VAMActivate fugitive +VAMActivate github:tpope/vim-git +" appearance +VAMActivate showmarks +VAMActivate github:itchyny/lightline.vim +VAMActivate github:skwp/vim-colors-solarized +" languages +VAMActivate iptables +VAMActivate github:pangloss/vim-javascript +VAMActivate github:itspriddle/vim-jquery +VAMActivate github:scrooloose/syntastic.git +VAMActivate github:honza/vim-snippets +VAMActivate github:garbas/vim-snipmate +VAMActivate github:gerw/vim-latex-suite +VAMActivate github:sudar/vim-arduino-syntax +VAMActivate github:sudar/vim-arduino-snippets +VAMActivate github:sophacles/vim-processing +VAMActivate github:Matt-Stevens/vim-systemd-syntax +VAMActivate github:klen/python-mode.git +VAMActivate github:sjas/octave.vim +VAMActivate github:wannesm/wmgraphviz.vim.git +" project +VAMActivate github:scrooloose/nerdtree.git +VAMActivate github:jistr/vim-nerdtree-tabs.git +VAMActivate github:xolox/vim-misc +VAMActivate github:xolox/vim-session +VAMActivate github:kien/ctrlp.vim +" textobjects +VAMActivate github:coderifous/textobj-word-column.vim +VAMActivate github:kana/vim-textobj-datetime +VAMActivate github:kana/vim-textobj-entire +VAMActivate github:kana/vim-textobj-function +VAMActivate github:kana/vim-textobj-user +VAMActivate github:lucapette/vim-textobj-underscore +VAMActivate github:nathanaelkane/vim-indent-guides +VAMActivate github:thinca/vim-textobj-function-javascript +VAMActivate github:vim-scripts/argtextobj.vim +VAMActivate github:austintaylor/vim-indentobject +" improvements +VAMActivate sudo +VAMActivate tmux +VAMActivate YankRing +VAMActivate netrw +VAMActivate tComment +VAMActivate VimRepress +VAMActivate github:tpope/vim-abolish +VAMActivate github:tpope/vim-endwise.git +VAMActivate github:tpope/vim-ragtag +VAMActivate github:tpope/vim-repeat.git +VAMActivate github:tpope/vim-surround.git +VAMActivate github:tpope/vim-unimpaired +VAMActivate github:goldfeld/ctrlr.vim +VAMActivate github:jamessan/vim-gnupg +VAMActivate github:Valloric/YouCompleteMe.git +VAMActivate github:godlygeek/tabular diff --git a/.vim/custom-functions.vim b/.vim/custom-functions.vim new file mode 100644 index 0000000..ecf92bd --- /dev/null +++ b/.vim/custom-functions.vim @@ -0,0 +1,37 @@ +" ================ strip trailing whitespaces ================ +" via: http://rails-bestpractices.com/posts/60-remove-trailing-whitespace +" Strip trailing whitespace +function! StripTrailingWhitespaces() + " Preparation: save last search, and cursor position. + let _s=@/ + let l = line(".") + let c = col(".") + " Do the business: + %s/\s\+$//e + " Clean up: restore previous search history, and cursor position + let @/=_s + call cursor(l, c) +endfunction +command! StripTrailingWhitespaces call StripTrailingWhitespaces() +nmap ,w :StripTrailingWhitespaces +" ================ text wrapping ================ +" http://vimcasts.org/episodes/soft-wrapping-text/ +function! SetupWrapping() + set wrap linebreak nolist + set showbreak=… +endfunction + +" TODO: this should happen automatically for certain file types (e.g. markdown) +command! -nargs=* Wrap :call SetupWrapping() + +vmap gj +vmap gk +vmap g$ +vmap g^ +vmap g^ +nmap gj +nmap gk +nmap g$ +nmap g^ +nmap g^ + diff --git a/.vim/custom-settings.vim b/.vim/custom-settings.vim new file mode 100644 index 0000000..9233b35 --- /dev/null +++ b/.vim/custom-settings.vim @@ -0,0 +1,240 @@ +" ================ keymap settings ================ +" ======================================== +" General vim sanity improvements +" ======================================== +" +" +" alias yw to yank the entire word 'yank inner word' +" even if the cursor is halfway inside the word +" FIXME: will not properly repeat when you use a dot (tie into repeat.vim) +nnoremap ,yw yiww + +" ,ow = 'overwrite word', replace a word with what's in the yank buffer +" FIXME: will not properly repeat when you use a dot (tie into repeat.vim) +nnoremap ,ow "_diwhp + +"make Y consistent with C and D +nnoremap Y y$ +function! YRRunAfterMaps() + nnoremap Y :YRYankCount 'y$' +endfunction + +" Make 0 go to the first character rather than the beginning +" of the line. When we're programming, we're almost always +" interested in working with text rather than empty space. If +" you want the traditional beginning of line, use ^ +nnoremap 0 ^ +nnoremap ^ 0 + +" ======================================== +" RSI Prevention - keyboard remaps +" ======================================== +" Certain things we do every day as programmers stress +" out our hands. For example, typing underscores and +" dashes are very common, and in position that require +" a lot of hand movement. Vim to the rescue +" +" Now using the middle finger of either hand you can type +" underscores with apple-k or apple-d, and add Shift +" to type dashes +imap _ +imap _ +imap - +imap - + +" ,# Surround a word with #{ruby interpolation} +map ,# ysiw# +vmap ,# c#{"} + +" ," Surround a word with "quotes" +map ," ysiw" +vmap ," c""" + +" ,' Surround a word with 'single quotes' +map ,' ysiw' +vmap ,' c'"' + +" ,) or ,( Surround a word with (parens) +" The difference is in whether a space is put in +map ,( ysiw( +map ,) ysiw) +vmap ,( c( " ) +vmap ,) c(") + +" ,[ Surround a word with [brackets] +map ,] ysiw] +map ,[ ysiw[ +vmap ,[ c[ " ] +vmap ,] c["] + +" ,{ Surround a word with {braces} +map ,} ysiw} +map ,{ ysiw{ +vmap ,} c{ " } +vmap ,{ c{"} + +map ,` ysiw` + +" gary bernhardt's hashrocket +imap => + +" Change inside various enclosures with Cmd-" and Cmd-' +" The f makes it find the enclosure so you don't have +" to be standing inside it +nnoremap f'ci' +nnoremap f"ci" +nnoremap f(ci( +nnoremap f)ci) +nnoremap f[ci[ +nnoremap f]ci] + +"Go to last edit location with ,. +nnoremap ,. '. + +"When typing a string, your quotes auto complete. Move past the quote +"while still in insert mode by hitting Ctrl-a. Example: +" +" type 'foo +" +" the first quote will autoclose so you'll get 'foo' and hitting will +" put the cursor right after the quote +imap wa + +" ==== NERD tree +" Cmd-Shift-N for nerd tree +nmap :NERDTreeToggle +" Open the project tree and expose current file in the nerdtree with Ctrl-\ +nnoremap :NERDTreeFind:vertical res 30 + +" ,q to toggle quickfix window (where you have stuff like Ag) +" ,oq to open it back up (rare) +nmap ,qc :cclose +nmap ,qo :copen + +" move up/down quickly by using Cmd-j, Cmd-k +" which will move us around by functions +nnoremap } +nnoremap { +autocmd FileType ruby map ]m +autocmd FileType ruby map [m +autocmd FileType rspec map } +autocmd FileType rspec map { +autocmd FileType javascript map } +autocmd FileType javascript map { + + +" Command-/ to toggle comments +map :TComment +imap :TCommenti + + +"Move back and forth through previous and next buffers +"with ,z and ,x +nnoremap ,z :bp +nnoremap ,x :bn + +" ============================== +" Window/Tab/Split Manipulation +" ============================== +" Move between split windows by using the four directions H, L, I, N +nnoremap h +nnoremap l +nnoremap k +nnoremap j + +" Make gf (go to file) create the file, if not existent +nnoremap gf :e +nnoremap f :sp +e +nnoremap gf :tabe + +" Zoom in +map ,gz o + +" Use numbers to pick the tab you want (like iTerm) +map :tabn 1 +map :tabn 2 +map :tabn 3 +map :tabn 4 +map :tabn 5 +map :tabn 6 +map :tabn 7 +map :tabn 8 +map :tabn 9 + +" Create window splits easier. The default +" way is Ctrl-w,v and Ctrl-w,s. I remap +" this to vv and ss +nnoremap vv v +nnoremap ss s + +" Resize windows with arrow keys +nnoremap + +nnoremap - +nnoremap < +nnoremap > + +" create <%= foo %> erb tags using Ctrl-k in edit mode +imap <%= %>3hi + +" create <%= foo %> erb tags using Ctrl-j in edit mode +imap <% %>2hi + +" ============================ +" Shortcuts for everyday tasks +" ============================ + +" copy current filename into system clipboard - mnemonic: (c)urrent(f)ilename +" this is helpful to paste someone the path you're looking at +nnoremap ,cf :let @* = expand("%:~") +nnoremap ,cn :let @* = expand("%:t") + +"Clear current search highlight by double tapping // +nmap // :nohlsearch + +"(v)im (c)ommand - execute current line as a vim command +nmap ,vc yy:p + +"(v)im (r)eload +nmap ,vr :so % + +" Type ,hl to toggle highlighting on/off, and show current value. +noremap ,hl :set hlsearch! hlsearch? + +" These are very similar keys. Typing 'a will jump to the line in the current +" file marked with ma. However, `a will jump to the line and column marked +" with ma. It’s more useful in any case I can imagine, but it’s located way +" off in the corner of the keyboard. The best way to handle this is just to +" swap them: http://items.sjbach.com/319/configuring-vim-right +nnoremap ' ` +nnoremap ` ' + +" ============================ +" Tabularize - alignment +" ============================ +" Hit Cmd-Shift-A then type a character you want to align by +nmap :Tabularize / +vmap :Tabularize / + +" ============================ +" SplitJoin plugin +" ============================ +nmap sj :SplitjoinSplit +nmap sk :SplitjoinJoin + +" Get the current highlight group. Useful for then remapping the color +map ,hi :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" . " FG:" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"fg#") + +" Source current file Cmd-% (good for vim development) +map :so % + +" ,hp = html preview +map ,hp :!open -a Safari % +" ================ search settings ================ +" ================ Search Settings ================= + +set incsearch " Find the next match as we type the search +set hlsearch " Hilight searches by default +set viminfo='100,f1 " Save up to 100 marks, enable capital marks +set ignorecase " Ignore case when searching... +set smartcase " ...unless we type a capital + diff --git a/.vimrc b/.vimrc new file mode 100644 index 0000000..6b938b5 --- /dev/null +++ b/.vimrc @@ -0,0 +1,118 @@ +" Use Vim settings | +set nocompatible | filetype indent plugin on | syn on + +" ================ General Config ==================== + +set number "Line numbers are good +set backspace=indent,eol,start "Allow backspace in insert mode +set history=1000 "Store lots of :cmdline history +set showcmd "Show incomplete cmds down the bottom +set showmode "Show current mode down the bottom +set gcr=a:blinkon0 "Disable cursor blink +set visualbell "No sounds +set autoread "Reload files changed outside vim +set cursorline "Show cursorline + +" This makes vim act like all other editors, buffers can +" exist in the background without being in a window. +" http://items.sjbach.com/319/configuring-vim-right +set hidden + +"turn on syntax highlighting +syntax on + +" Change leader to a comma because the backslash is too far away +" That means all \x commands turn into ,x +" The mapleader has to be set before vundle starts loading all +" the plugins. +let mapleader="," + +" ================ Turn Off Swap Files ============== + +set noswapfile +set nobackup +set nowb + + +" ================ Persistent Undo ================== + +" Keep undo history across sessions, by storing in file. +" Only works all the time. +if has('persistent_undo') + silent !mkdir ~/.vim/backups > /dev/null 2>&1 + set undodir=~/.vim/backups + set undofile +endif + +" ================ Indentation ====================== + +set autoindent +set smartindent +set smarttab +set shiftwidth=2 +set softtabstop=2 +set tabstop=2 +set expandtab + +"filetype plugin on +"filetype indent on + +" Display tabs and trailing spaces visually +set list listchars=tab:\ \ ,trail:· + +set nowrap "Don't wrap lines +set linebreak "Wrap lines at convenient points + +" ================ Folds ============================ + +set foldmethod=indent "fold based on indent +set foldnestmax=3 "deepest fold is 3 levels +set nofoldenable "dont fold by default + +" ================ Completion ======================= + +set wildmode=list:longest +set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches +set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing +set wildignore+=*vim/backups* +set wildignore+=*sass-cache* +set wildignore+=*DS_Store* +set wildignore+=vendor/rails/** +set wildignore+=vendor/cache/** +set wildignore+=*.gem +set wildignore+=log/** +set wildignore+=tmp/** +set wildignore+=*.png,*.jpg,*.gif + +" ================ Scrolling ======================== + +set scrolloff=8 "Start scrolling when we're 8 lines away from margins +set sidescrolloff=15 +set sidescroll=1 + +" ================ Vim-Addon-Manager ======================== + +fun! SetupVAM() + let c = get(g:, 'vim_addon_manager', {}) + let g:vim_addon_manager = c + let c.plugin_root_dir = expand('$HOME', 1) . '/.vim/vim-addons' + " most used options you may want to use: + " let c.log_to_buf = 1 + " let c.auto_install = 0 + let &rtp.=(empty(&rtp)?'':',').c.plugin_root_dir.'/vim-addon-manager' + if !isdirectory(c.plugin_root_dir.'/vim-addon-manager/autoload') + execute '!git clone --depth=1 git://github.com/MarcWeber/vim-addon-manager ' + \ shellescape(c.plugin_root_dir.'/vim-addon-manager', 1) + endif + + " This provides the VAMActivate command, you could be passing plugin names, too + call vam#ActivateAddons([], {}) +endfun +call SetupVAM() + +" ================ Addons and their settings ======================== +so ~/.vim/addons.vim " addons +so ~/.vim/addons-settings.vim " addon settings +so ~/.vim/custom-settings.vim " custom settings +so ~/.vim/custom-functions.vim " custom functions + -- cgit v1.2.3-70-g09d2