Skip to content

Latest commit

 

History

History
55 lines (39 loc) · 4.74 KB

vim.md

File metadata and controls

55 lines (39 loc) · 4.74 KB

Use Case 2: vim

Use a Text Editor

  • note: show gang sign you made up for vim
  • Ok. I love vim but I recognize there are other text editors out there that do a pretty ok job too so don't let anyone get dogmatic on ya.
  • That said, if haven't declared your allegiance yet, pay attention and watch vim optimize your life.
    • This is all true. Greyson has gone as far as to put vim keybindings in his browser.

Vim Philosophy

Doing things the Vim way

  • Keep your fingers as close to home row as possible

The Basics

  • In the terminal, start editing a file (or create a new file) by typing
vim filename
  • The default mode for vim is Command. If you try to type something, it won't work. Switch to Insert mode by pressing i.

  • There are several different modes to vim but the only ones we are going to work with are Command and Insert. Just remember, Command is do stuff and Insert is write stuff.

  • Now that we are in Insert mode, write some code or whatever.

  • Save it by switching back to Command mode by pressing esc (the escape key) and entering :w<enter>

  • Then quit by entering :q<enter>

  • Right away, we are bummed because it takes two steps to save and quit. Not so! Combine your commands :wq<enter> will save and quit.

  • Ok lets open the file up again. In practice since we are using the terminal, we will only rarely quit vim. Instead, the more common and useful pattern is to put vim in the background when you leave it using crtl-Z and bring it back to the foreground using fg

More Navigation

  • Sorry to run through commands like this, but you need a base layer to get moving. Does this feel like a crash course? Thats because it is! Take away as much as you can, get curious and google/check this document out afterwards!

  • So in Insert mode movement is easy: arrow keys

  • But you should be spending most of your time in Command mode

  • In Command mode you can also move with the arrow keys put that would move your fingers off home row which is no bueno

  • Instead you can use h to move one character to the left, l to move one right, j to move one down and k to move one up. Is that hard to remember? Train your fingers using vim snake!. #notajoke

  • Notice the line numbers on the side; those will be your guide to moving really fast without a mouse. Want to change something on line 40? In Command mode, go 40gg. Top of the page? gg, Bottom? G.

  • What if you just want to scroll down or over? There are a variety of ways to do it, but the one that has worked the best for me is to go 10j to go down 10 lines. (or h, k, l for the other directions)

  • To go to the beginning of the line _, to go to the end $.

  • Ok that was a whirlwind tour through vim motion. Don't worry if you missed any of it, there is more to come. On a more serious note, this stuff will only sink in through practice. If everyday you code you try the terminal instead of your IDE or whatever, you will become a pro in no time. I want you to take in how powerful a tool like vim is.

Editing

  • Ok almost done with our vim basics
  • dd cuts a line, p pastes whatever you have just deleted, yy copies a line.
  • Similar to the movement commands 10dd deletes 10 lines and 10yy copies 10 lines.
  • To indent blocks of text use >> to indent in or << to indent out and, of course, 10>> to indent 10 lines
  • you can search with /searchquery and move between matches with n and N
  • The coolest thing here is you can set a mark on a line using m<letter> and travel to that mark from anywhere with '<letter>. For example, ma ... go somewhere else ... 'a takes you right back to that line. Pretty dope