vim snippets

How to install MacVim with Homebrew

Tagged homebrew, macvim, vim  Languages bash
brew install -v macvim --no-icons
mv /usr/local/Cellar/macvim/snapshot-55/MacVim.app /Applications/

The --no-icons switch is a fix for:

PhaseScriptExecution "Make Document Icons" /tmp/...
(1 failure)

How to center and open multiple windows at Vim startup

Tagged vim, split  Languages 

For maximum productivity I like to split the Vim window into 3 viewports. The main viewport is to the left and two viewports to the right. I also like to maximize the Vim window. Put this in your ~/.vimrc configuration file to make Vim use this setup by default at startup:

set columns=180
set lines=180

:winpos 50 50 " Center window
vsplit    " Split window vertically. e.g. 100vsplit
wincmd l  " Move to right window
split     " Split window horizontally

My ~/vimrc.local

Tagged macvim, vim, janus  Languages 

For use with Janus:

" Position and maximize window
:winpos 0 0 " Center window
vsplit " Split window vertically
wincmd l  " Move to right window
split     " Split window horizontally

" Remove stuff
set guioptions-=L
"set guioptions-=r " Disable window resize
set guioptions-=T
set fuopt=maxvert,maxhorz " Maximize width and height
endif

My Janus Installation

Tagged janus, macvim, vim  Languages 

.vimrc.before:

"call janus#disable_plugin('nerdcommenter')
let mapleader = ","

highlight OverLength ctermbg=red ctermfg=white guibg=#592929
match OverLength /\%81v.\+/

map <C-h> 5<C-w>>
map <C-j> 5<C-w><
map <C-k> 3<C-w>+
map <C-l> 3<C-w>-
map <leader><leader> :ZoomWin<cr>

set undofile
set undodir=~/.vimundo/

set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*/log/*,*/vendor/bundle/*

let g:ctrlp_working_path_mode = 0
let g:ctrlp_max_height = 30

" No wrapping
set nowrap
set textwidth=0 wrapmargin=0

" Strip trailing whitespace
function! <SID>StripTrailingWhitespaces()
    if &ft =~ '\|ruby\|javascript\|perl'
        return
    endif
    " 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
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()

Optional .gvimrc.after:

colorscheme jellybeans
" colorscheme molokai
"colorscheme vibrantink
set guifont=Monaco:h13

" Position and maximize window
:winpos 0 0 " Center window
vsplit " Split window vertically
wincmd l  " Move to right window
split     " Split window horizontally
set fuopt=maxvert,maxhorz  " Maximize

" Remove stuff
set guioptions-=L
"set guioptions-=r " Disable window resize
set guioptions-=T

Optional .vimrc.after:

colorscheme vibrantink

Strip trailing whitespace with vim

Tagged vim, whitespace  Languages 
" Strip trailing whitespace
function! <SID>StripTrailingWhitespaces()
    " Skip these
    if &ft =~ '\|slim|haml'
        return
    endif
    " 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
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()

How to make Vim yank to the OSX clipboard

Tagged clipboard, osx, vim, yank  Languages bash, vim

Add this to .vimrc:

set clipboard=unnamed

If you use Tmux you probably need this: https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard

$ brew install reattach-to-user-namespace

Note, do NOT use something like this because it doesn’t work perfectly:

function! ClipboardYank()
  call system('pbcopy', @@)
endfunction
function! ClipboardPaste()
  let @@ = system('pbpaste')
endfunction

vnoremap <silent> y y:call ClipboardYank()<cr>
vnoremap <silent> d d:call ClipboardYank()<cr>
nnoremap <silent> p :call ClipboardPaste()<cr>p