 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)
|