Skip to content

Instantly share code, notes, and snippets.

@MrJadaml
Created February 21, 2017 16:36
Show Gist options
  • Save MrJadaml/2416bbaafa5fc4f7d2650589c80dabaf to your computer and use it in GitHub Desktop.
Save MrJadaml/2416bbaafa5fc4f7d2650589c80dabaf to your computer and use it in GitHub Desktop.
Hello Vim

Steps

Part 1: Setup

  • create new dir basic-vim and cd into it: take basic-vim
  • create new file touch foo.js
  • initilize a git repo git init
  • add some code to the foo file
const hello = (name) => {
  const greet = `Well hello there, ${name}`;

  console.log(greet);
}

hello('Bob');

Part 2: Commit to Git

  • check the status git status
  • add the foo.js file in your working directory to the staging area: git add foo.js
  • check that your staging area is up to date with your working dir: git status
  • commit your changes to your local git repo: git commit -m 'hello bob'- commit your changes to your local git repo: git commit -m 'hello bob'
  • check you commit history for your new changes: git log

Part 3: Update hello function

  • Update your foo.js file so that we log out Bob's last name too.
const hello = (name) => {
  const greet = `Well hello there, ${name}`;

  console.log(greet);
}

hello('Bob Wiley'); \\ 👈
  • check the status of your chnages: git status
  • add these changes to the staging area: git add foo.js
  • double chekck your stagin area is up-to-date with your working dir: git status

Part 4: Rewriting History & Vim!

  • add these new changes to last commit: git commit --amend
  • You should now be in Vim world!
  • You start off in Normal mode when you enter Vim. (says which mode you are in at the bottom)
  • Try out the commands h j k l
  • Try out G and gg
  • Move the cursor to the end of the first line.
  • press a to be put in Insert mode, look at the bottom of the screen to verify this.
  • you can now add text.
  • Change your commit to say "hello Bob Wiley"
  • press esc to exit Insert mode and go back to Normal mode.
  • We have just updated the commit message of our previous commit, now we just need to save this change.
  • press : and you will see your cursor jump to the status bar at the bottom.
  • next press w, which stands for "write", and then hit return to save your changes.
  • Your cursor should jump back to the file at this point.
  • At this point we are all done and want to quit out of vim.
  • press : to go back to the status bar again, followed by q and then hit return to quit.
  • if done correctly you will be back in your shell.
  • run git log to check your commit history and see that your commit message has been updated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment