Cheatsheet
Vim filters tips; in command mode:
" Read results of a command to cursor location:
r !pwd
" Read results of a command to line 42:
42r !pwd
" Use ruby to upcase entire file
%!ruby -ne 'puts $_.upcase'
" Use ruby to upcase current line (also works for visually selected line)
!!ruby -ne 'puts $_.upcase'
Diff
Compare and diff a file on current branch with master branch version:
- Open foo.rb right tab
- Open foo.rb from master in the left tab
:Gedit master:foo.rb
- Diff the files using
:windo diffthis
- Close diff view with
:diffoff
Vimscript
function HelloWorld()
echo "Hello, world!"
endfunction
call HelloWorld()
function ReturnSomethign()
return "Something"
endfunction
echo ReturnSomethign()
function Foo()
endfunction
" Returns 0 by default
function TooBigEh(foo)
if a:foo > 10
return 1
end
endfunction
" Returns 1 if cond matches, falls back to 0 otherwise
" a:foo is for variable scoping - tells vimscript that it's the argument foo
" Truthiness
" 'hey' is coerced in to 0, so falsey
" '8 hello' is coerced to 8 because it starts with a number, so truthy
" Local vars
function Foo()
let bar = 'baz'
return bar
endfunction
" Match url in the following line:
" foo bar http://hello.baz hai
" Matches string starting with http, until it runs into spaces
matchstr(getline('.', "http[^ ]*"))
Links
- Vim Awesome - Search for vim plugins
- Vim and Ctags
- Vim Splits - Move Faster and More Naturally
- Vim as your IDE
- Clipboard sharing in OSX
- Mapping keys
- Vim, Tmux and system clipboard
- Extending Rails.vim with custom commands
- An Extremely Quick and Simple Introduction to the Vi Text Editor
- Vim for Rubyists
- Vim Revisited, a post by Mislav Marohnić
- Vim After 11 Years
- Best of Vim Tips
- Supercharge Your Vim Into an IDE With Ctags
- Vim for Elixir
- Configuring Vim Right
Screencasts
Other vim implementations
Books
Videos: