» Learning Vim
In an attempt to familiarize myself with the unfamiliar, I decided to build
a fun side-project in Ruby and Vim.
Effectively learning a new language, framework, and editor.
Coming from Nano, Quanta,
Eclipse PDT,
TextMate,
Netbeans; I found (Mac/g)Vim is big a step, and
first two weeks you should not expect to be productive.
But after some persistence, I'm now faster in Vim than I was in my previous editors. Except for NetBeans still. Maybe that changes as I get better, but having an editor that understands your code is also a powerful thing. Scope-aware refactoring and jumping to declarations make that I keep both NetBeans and Vim around. Cause Vim on the other hand let's you navigate and hack on text like no other.
Investing in a tool like this pays off. For life.
Cause as so long as computers can't read our minds, we're better of maximizing
the efficiency of our typing. If your brain has to wait for your hands to
transfer the message, you're just throwing away time & creativity flow.
Here are the resources that helped me get started with Vim.
Vim screencast tutorial (awesome series):
Other screencasts:
More resources:
- Vim Keyboard Cheat Sheet
- Vim Cheat Sheet
- Vim tips: Using tabs
- Use Vim like a pro
- Sync Vim Config across workspaces (on this blog)
Keyboard shortcuts
There are many Vim cheat-sheets out there, better than this one (see resources above). But still, I'll continuously log useful shortcuts here so I won't regress :)
Mode switching
^[ exit mode
: enter command mode
i enter insert mode before cursor
a enter insert mode after cursor
Command mode
w [filename] write file
e filename edit file
e! reload current file
<range>s substitute
. repeat commands
Normal mode
This is the mode you should generally be in. Don't stick around in others longer than necessary.
Movement / Motions
j move down
k move up
h move left
l move right
0 move to line start
^ move to first char in line
$ move to last char in line
} move down a paragraph
{ move up a paragraph
^d down a page
^u up a page
gg move to top
G move to bottom
# prev word like current
* next word like current
% move to matching closing/starting tag/comment/brace/statement
" move to your last edit
b back a word
w to next word
W to next WORD (space terminated, ignore e.g. commas)
e to end of the current word
E end of the current WORD (space terminated)
Manipulation
u undo
x delete character (and saves to clipboard)
c<motion> change (enters insert mode)
y<motion> copy (yank)
d<motion> cut (delete) (and saves to clipboard)
p paste after cursor
P paste before cursor
< unindent
> indent
Search & Replace
/ start search down the document
? start search up the document
^M stop search
n move to next occurance
N move to prev occurance
f find symbol after cursor
F find symbol before cursor
; move to next occurance of symbol
t find until symbol after cursor
Ranges
% entire document
Combined
ctK change until next capital 'K'
yy copy (yank) line
d2e delete till the end of the second word
%s/name/kevin/g change all occurances of name to kevin in entire document
3,6 s/name/kevin/g change all occurances of name to kevin from line 3 to 6
D delete til end of line
Y copy (yank) til end of line
ct, change until ','
cf, change until & including ','
>7j indent this line & 7 next lines
<} unindent until next paragraph
3dd delete 3 lines (3x delete current line)
12x delete 12 characters
Insert mode
^n Next autocomplete suggestion
^p Previous autocomplete suggestion
Shell filtering
! enter mode
!!<command> apply filter on current line
!}sort sort paragraph
:%!sort sort entire file
!G sort until bottom
Alright, that's all I got for now. What are your experiences with Vim?
You Probably Shouldn't Follow Me
Like this Article?
| I'd appreciate it if you leave a comment, spread the word, or consider a small donation |
RelatedArticles like this one» My new IDE: NetBeans |
tags: ide, netbeans, eclipse, programming, vim
category: Programming
read: 8,174 times
tagcloud
#5. Bryce Verdier on 07 February 2012
Thanks for the article, might I also recommend the pdf from vimgeeks here: http://billodom.com/vim/vim-from-essentials-to-mastery-2011.pdf
Lots of really cool tips and tricks in there to really help with your VIM mastery.
#4. Tin Dalos on 27 July 2011
How the hell can you ( efficiently ) administer linux (UNIX) servers without knowing vi ( or vim if available ) ? No graphic sessions possible on secured machine and Nano is not always available.
Note: On Windows you can gVIM too, kill Notepad
#3. Kevin on 17 April 2011
#2. primeminister on 24 March 2011
What editor do you use on the mac? Just vin in your terminal of macvim or something else?
#1. dilicious on 24 March 2011