Skip to content

Instantly share code, notes, and snippets.

@alexlafroscia
Last active August 29, 2015 14:16
Show Gist options
  • Save alexlafroscia/d97ae6b81442ca7b8d9c to your computer and use it in GitHub Desktop.
Save alexlafroscia/d97ae6b81442ca7b8d9c to your computer and use it in GitHub Desktop.
Vim Presentation
" Set Insert mode to allow the backspace key
" for deleting characters
set backspace=2
" Instead of using a tab, use 2 spaces
filetype plugin indent on
set tabstop=4
set shiftwidth=4
set expandtab
/**
* Hello! If you're reading this file, it's because you're interested in the Vim
* text editor and probably want to learn some more. I'll guide you through making
* some modifications to this file so that you can get familiar with how to use vim.
*
* To start out, download this file to your computer with the following command:
*
* wget https://gist.githubusercontent.com/alexlafroscia/d97ae6b81442ca7b8d9c/raw/HelloVim.java
*
* This will download the file you're reading right now, which we'll be editing together
* using Vim. You can then open it in Vim using
*
* vim HelloVim.java
*
* Next we want to give Vim some basic setup so that you're not pulling your hair out.
* Vim configurations can be very complex -- and very powerful -- and allow you to really
* make Vim feel like home on your laptop. The configuration you just provided just does
* a few things:
*
* 1. Allow you to use the `DELETE` key in Insert mode, they way you're used to with other
* editors. This is a good idea so that you can get used to using Vim without it
* feeling too different from other things you're used to.
* 2. Set up `TAB` to insert 2 spaces instead. This is generally good practice, and prevents
* you from mixing tabs and spaces in the same file without meaning to.
*
* To make things a little easier, you can run the following command to download the
* configuration file to the right location.
*
* wget -P $HOME https://gist.githubusercontent.com/alexlafroscia/d97ae6b81442ca7b8d9c/raw/.vimrc
*
* This will automatically download the correct file from Github and place it at the right location
* in your file system.
*
* ================================================================================================
*
* To start out, practice moving around the file. Remember the basic movements:
*
* h : left
* l : right
* j : down
* k : up
*
* Try moving around by words, too
*
* w : beginning of next word
* b : beginning of previous word
* e : end of next word
*
* A few more important commands to remember, in case you're getting frustrated:
*
* - If you want to exit "insert" mode, press the `ESC` key
* - If you want to save the current file, press `:w` from Normal mode
* - If you want to exit Vim, press `:qa` from Normal mode
*/
import java.io.*;
public class HelloVim {
/**
* Just to get the hang of editing a file in Vim, try making a new instance of the Person
* class, and printing the full name to the console instead. Remeber that to get into
* Insert mode, you can use the 'i' command, and use 'ESC' to get back to Normal mode
*/
public static void main(String[] args) {
System.out.println("Hello, world!");
}
/**
* Now that we're printing my name, let's print yours! Try using a motion like '2j' to get
* down to where the first name is assigned, and then use the `w` command to move to the front of
* word.
*
* If you want to get fancy, try selecting text to replace it! With your cursor over the "A", press 'v'
* and then 'e' to select "Alex". Next, press the 'c' command to change the text, type your name, and
* press 'ESC' to return to Normal mode. Repeat with the last name, too. Make sure to save the file with
* ':w' when you're done!
*/
private class Person {
String firstName = "";
String lastName = "";
public Person() {
this.firstName = "Alex";
this.lastName = "LaFroscia";
}
/**
* Now, try to add a new method from a copy of the one below. With your cursor on the method
* definition, press 'V' and then 'j' until the whole method is selected. Then, press 'y'. This
* copied the text to Vim's internal clipboard.
*
* Now, position your cursor after the method and press 'p' to paste it into the file. Change the
* method to do something else, and modify the Main method to print something else.
*/
public String fullName() {
return this.firstName + " " + this.lastName;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment