Latewire
A place for the insomniac and the strange
 
Register (free)
Grab Twitter Feed: Latewire / Coughlin
Username: Password: NVR4GET
Articles Relating to Vim: «· Previous Page Next Page ·»

Vim cheat sheet for cro-mags!

Nicholas DiBiase
Poster: Nicholas DiBiase @ Sun Jun 13, 2010 2:15 am



After about four years of using TextWrangler to write HTML/CSS and other basic code, I got tired of it this week and wanted to move to something a little hipper and, ideally, open-source. I wanted to install Apple's own Xcode program, but the damned thing takes up 2.37 gigs of hard drive space, which is more than I have free on my Mac. So I downloaded the highly-lauded yet daunting text editor called Vim, which takes up a grand total of 30 megabytes.

Vim is a modified version of vi, which is one of the classic editors for hardcore coders, hackers, and nerds. The other real classic is Emacs, but the OSX implementation of Emacs didn't really feel rad to me, so after consulting with my good friend and CERN physicist Grayson W, I turned to Vim.

At first, this looked like a really big mistake, because after I installed and opened Vim, I started typing and... nothing! I saw the cursor, but it wouldn't actually type! Looking around in the menus, I had no idea what to do. I got really frustrated and called Grayson again, who told me that Vim was a modal editor, which means that in order to add new lines to the document, you have to be in a mode called 'Insert.'

“Maybe you should stick to Emacs,” said Grayson.

He may be right. After all, technology is supposed to make work easier, not harder. Why should I waste time learning the complex operating methods of a text editor instead of creating new stuff? I don't have a really good answer for why I didn't give up right then, but I think it has something to do with my characteristic refusal to admit defeat and also an embarrassing but nonetheless real desire to feel like I 'fit in' with the hardcore-coder crowd.

So, I decided to give it a shot. I figured that I'd learn the commands better if I typed up a cheat sheet myself instead of just memorizing one that'd be typed already, so I watched a few YouTube video tutorials on Vim and wrote down the info they shared. Will I become proficient enough to be useful in a reasonably short time? Or will I languish and fail as I did when I tried to learn Linux administration ten years ago? To quote Michael Madsen in 'Kill Bill 2,' – “I guess we'll just...see, now, won't we?”


Vim is 'modal' - -
In “normal mode,” you move around and make changes to the document
In “insert mode,” you actively write code
You can toggle these modes with the escape key, but :
Instead of esc, you can use control-[ to toggle modes

Vim commands :

Move down : j
Move up : k
Move right : l
Move left : h

Search : / [follow with search term]
Find next instance of search term : *
Find next occurrence of search term : n
Find previous occurrence of search term : N
Find a specific symbol to right : f [followed by symbol]
Find a specific symbol to the left : F [followed by symbol]
Find next instance of symbol : ;
Find previous occurrence of symbol ; ,
Substitute : s [used like this : s/youwanttochangethis/tothis/g ← where g {global} is over entire document; to ignore case (lowercase / capital), use gi]
Find an instance above cursor : #


Copy : y [“yank” - must qualify with a motion]
Motions : Copy a whole line of text : yy ; can use any other command
Paste a line of text : p
Change a character : c [also requires a motion]
Motions : w [whole word]; t and a character ['til, as in all characters through X] can use any other comand, like $

Range : [this is a range of text within the document]
Entire document : %


Note that any command can be executed automatically multiple times by typing the desired number of executions (say, 10) and then the command – e.g., “10p” - this will paste a line ten times.

Undo : u
Delete : d [wants a motion; Note : 'delete' functions like 'cut' – it puts whatever you delete into the clipboard]
Delete whole line: dd [with cursor on line]
Join lines : J
Next / previous word or punctuation mark : w / b
Next sentence : )
Previous sentence : (
Beginning of current line : 0
Home : ^ [shift + 6]
End of current line : $
Page up : control + u
Page down : control + d

Delete one word / punctuation mark to the left : dw
Delete one word / punctuation mark to the right : db
Delete one sentence : das
Delete sentence to the left : d(
Delete sentence to right : d)
Delete one character : x or [delete key]

Insert before the cursor : i
Insert after the cursor : a [“append text”]
Insert at beginning of line : I
Insert at end of line : A
Insert below current line : o
Insert above current line : O


in command mode : [Note! You must type a colon before any of these commands!]
write / save file : w
Open / edit file : e and type filepath e.g., c:/snakes/bats.html
Reload current file : e!
Quit the program : q
Save and then quit : wq


Don't use the arrow keys in insert mode to navigate. Unless you're actively typing text, use noarmal mode.

Sources :
Aaron Jensen : Perdidle on YouTube : http://www.youtube.com/watch?v=c6WCm6z5msk
DggoldST on YouTube : http://www.youtube.com/watch?v=71YTkxUNwmg




Here's a sneak preview couplet from a new song I'm writing, by way of a couplet :

When she found me outside Houston I was hardly alone
How she caught up with me, I will never know

(33,485)
Keywords: Vim  Text  Editing  Coding  Code  Software  Html  Computers  Cool  Emacs  Textwrangler 
Comments: 0  •  Post Comment  •  Share Share Top

Not working? Try this.

Best Of Latewire
- Is Russia behind the global terrorist epidemic?
- Intern Hell
- S&P's Torrid Love Affair With The Government
- Green Subsidies Destroying Energy Market & Environment
- Why Economic Stimulus Doesn't Work (Latewire Original Video)
- The Season of Reason
- Happy Holidays from your pals at Latewire
- The Healthcare Disaster and Why Obamacare Will Make It Worse
- Video: Interest Rates, The Fed, and History Repeating
- Urban agriculture : Planning your vegetable garden part V
- Urban Agriculture : Planning your Vegetable Garden part IV
- Why The Government Wont Rescue The Dollar
- How the US Government Is Destroying the Dollar -Latewire Vid
- Governing Crazy: Broken Minds & Alcohol
- Urban Agriculture : planning your vegetable garden part III
- Urban Agriculture : Planning Your Vegetable Garden part II
- Urban agriculture for self-reliance : garden planning pt 1
- Why Bailouts Are Stupid (Illustrated Version)
- The Great Depression II, The Making of
- MySpace: A Place for The Damned. Part 1
- Happy Birthday, Latewire! I wrote you a song.
- The Worst Movie Ever!
- Best Long Island Iced Tea EVER
- Everyone loves a top 10 list.
- The Good Ol' Days
- I got your subject right here:
- Male members must represent, like you didn't know.
- Photo Radar: An Extravagant Way To Screw Ourselves
- The Inadequacy of Hope
- TV Companies WANT YOU... to Pirate
- The Gettin' Place
- 46 & ***
- The White Whale


Top 15 Keywords
- Alcohol (12)
- Bailouts (30)
- Bernanke (11)
- Doom (11)
- Economics (25)
- Food (22)
- Goth (13)
- History (12)
- Music (22)
- Obama (14)
- Poetry (18)
- Poison (11)
- Slavery (12)
- Snakes (29)
- Urban Farming (11)

Links
- Latewire Latewear-Shirts&Stuff
- Snatchies Underthings
- Grief Brothers Band
Our Parked Domains:
- Latewire Video
- Poison-Free Diet
- Inflation Hell
- Policy Horn(DUPE)
- Policy Walk(DUPE)
- Policy Reader(DUPE)
- Faux Future(DUPE)
- Scarewire(DUPE)
- Urban Agriculture: The Road to Self-Reliance
- Urban Agriculture: The Road to Self-Reliance(DUPE)
- Urban Agriculture: The Road to Self-Reliance(DUPE)
- Urban Agriculture: The Road to Self-Reliance(DUPE)
- Interview With Dr. LSD
- Dr. LSD(DUPE)

cron
© 2008 Latewire.com