Skip to content

Instantly share code, notes, and snippets.

@giantryansaul
Created December 13, 2016 05:40
Show Gist options
  • Save giantryansaul/c2d3163ae87e6bae76f3aed3fa46197e to your computer and use it in GitHub Desktop.
Save giantryansaul/c2d3163ae87e6bae76f3aed3fa46197e to your computer and use it in GitHub Desktop.
Notebook sync through vimwiki and git

Title: Notebook sync through vimwiki and git

Objective

In this project I'm going to create a local directory and sync it up with a remote machine in my house using git. I'm going to write all of my notes in markdown and use vimwiki as my notetaking editor of choice.

Setup

You'll need all of these things to get started:

  • Git
  • A dedicated home PC with SSH enabled for your remote machine (git should be installed here as well)
  • A NoIP account
  • Vimwiki (we'll get to how to install this later in the guide)

Setup NoIP on your remote machine

NoIP is a free service that allows you to get around that pesky issue of having a dynamic IP address from your ISP (If you have a static IP then you can skip this step).

  • Create an account and domain at NoIP
  • Install the NoIP client on your remote machine Client Download
  • Login to your router and set your remote machine to a static IP so it doesn't change addresses every time it or the router is restarted.
  • Also forward port 22 (SSH port) to your remote machine's IP.

Getting started

Let's first create a new directory called notebook on your home directory. Create an empty note file that we can use as an example and initialize a git repo:

mkdir ~/notebook 
cd ~/notebook
touch first_note.md
git init
git add first_note.md
git commit -m 'first commit'

Create a bare directory on the remote machine

ssh <remote_machine>
git init --bare notebook.git

Connect your local box to the remote git server

cd ~/notebook
git remote add origin <remote>:~/notebook.git
git push -u origin master

At this point you should have pushed your first commit up to your remote machine. Congrats! But we're not done yet...

Setup vimwiki for awesome notetaking

To setup vimwiki you'll need to make sure you have Pathogen installed first. This is a pretty easy install actually, I'll transcribe the steps here:

mkdir -p ~/.vim/autoload ~/.vim/bundle
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

You can now setup all sorts of vim plugins through a very easy package manager designed for Vim! OK, now install vimwiki:

cd ~/.vim/bundle
git clone https://github.com/vimwiki/vimwiki.git

Vimwiki is now installed! However, there is some additional configuration to get all of vimwiki's features to work properly.

Add the following to ~/.vimrc:

call pathogen#infect()
call pathogen#helptags()
set nocompatible
filetype plugin on
syntax on
let g:vimwiki_list = [{'path': '~/notebook/'}]
let g:vimwiki_list = [{'path': '~/notebook/', 'syntax': 'markdown', 'ext': '.md'}]

Vimwiki is now setup to default to the ~/notebook directory and will use markdown files instead of the vimwiki default type.

Create your first notes!

Now that you have vimwiki installed, open vim to get started.

  • Type <Leader>ww to create index.md.
    • <Leader> is typically set to \.
    • You can change default key for <Leader> by adding this line to ~/.vimrc: let mapleader = ",".
  • Add first_note to the index.
  • Hover your cursor over first_note and press Enter.
  • You should now be on ~/notebook/first_note.md which you created earlier!
  • Press Backspace to return to the index.

That's it! There are more options in vimwiki you can use, but I'll leave that discovery up to you. Happy notetaking!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment