Taking notes in vim revisited
Tags: neovim, vim, notes, vimwiki
Published: 2019-09-12 20:38:46

---
title: Taking notes in vim revisited
published: true
description: taking another look at note-taking process in vim
tags: neovim, vim, notes, vimwiki
series: taking notes in vim
cover_image: https://thepracticaldev.s3.amazonaws.com/i/l3u3bitq3ed5es9ebksm.png
---

In my previous post I talked about a `vimwiki` plugin for taking notes:
{% link https://dev.to/konstantin/taking-notes-with-vim-3619 %}

I was still unsatisfied with the results, such as redefining markdown behavior and losing some of the essential shortcuts. Then I stumbled across an article «[You (probably) don’t need Vimwiki](http://joereynoldsaudio.com/2018/07/07/you-dont-need-vimwiki.html)» by Joe Reynolds.

## Replacing `vimwiki`

So to replace `vimwiki` we need to configure following features:
 - open/create new file under cursor.
 - open notes from any location(with <kbd>Leader</kbd><kbd>w</kbd><kbd>w</kbd>)
 - shortcut for toggling checkboxes to make TODO lists
 - align tables in markdown
 - previewing html

### Create new file under cursor.

The article that I mentioned above did say that you can replace the `vimwiki's` <kbd>enter</kbd> shortcut that creates new markdown files and opens them with <kbd>gf</kbd>(open file under cursor). Unfortunately, it works only when the file actually exists. We want to be able to quickly create and open a new note once we typed its name. However, there is an alternative shortcut in [markdown plugin by plasticboy](https://github.com/plasticboy/vim-markdown) –– <kbd>ge</kbd> that allows you to open file under cursor(if it is a markdown link) even if it doesn’t exist... unless it's in a subfolder(s) that doesn't exist. Lucky for us, there is a plugin that creates all subfolders in the path of the file(`mkdir -p` for vim):

{% github pbrisbin/vim-mkdir %}

so if you add to your `.vimrc` or `init.vim` following plugins:
```vimscript
Plug 'pbrisbin/vim-mkdir'
Plug 'plasticboy/vim-markdown', { 'for': 'markdown' }
```

provided that you're using [vim-plug](https://github.com/junegunn/vim-plug) as a plugin manager, you should be able to type <kbd>ge</kbd> in `md` file(on a markdown link) and vim would create the file under cursor, as well as all subfolders and open this file for editing. 

You can find more information about markdown plugin mappings in [README] (https://github.com/plasticboy/vim-markdown#mappings).

### Open notes from any location

I store all my notes in `~/Documents/notes` folder(and in MacOS all files are automatically synced with `iCloud`).

Our shortcut should essentially open the `~/Documents/notes/index.md` file:
```vimscript
" open ~/Documents/notes/index.md
nnoremap <Leader>ww :e ~/Documents/notes/index.md<cr>
```

since we've configured plugin that creates subfolders it should automatically create `notes` folder as well.

### Toggling checkboxes to make TODO lists

For this I found a nice plugin:
{% github jkramer/vim-checkbox %}

the shortcut that interests us is <kbd>Leader</kbd><kbd>tt</kbd> that searches and toggles the checkbox on the cursor line. In visual mode it will toggle all checkboxes on selected lines.

### Align tables in markdown

The previously mentioned markdown plugin already contains this feature in form of a command: `:TableFormat`. It will align a table under cursor.

### Previewing html

To preview markdown in a browser I'm using this amazing plugin:

{% github iamcco/markdown-preview.nvim %}

to start a preview you simply need to type `:MarkdownPreview` and it will open up a browser and sync all your modifications. To stop the preview you can type `:MarkdownPreviewStop`.

So in the end your `.vimrc` file should look something like this:
```vimscript
call plug#begin('~/.vim/plugged')

Plug 'pbrisbin/vim-mkdir'

Plug 'jkramer/vim-checkbox', { 'for': 'markdown' }
Plug 'plasticboy/vim-markdown', { 'for': 'markdown' }

if executable('npm')
	Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & npm install' }
endif

" Initialize plugin system
call plug#begin('~/.vim/plugged')

" open ~/Documents/notes/index.md
nnoremap <Leader>ww :e ~/Documents/notes/index.md<cr>
```

You can find these configs and more in my vim config repo:
{% github gko/vimio %}

You can also find me on twitter: [https://twitter.com/konstantin](https://twitter.com/konstantin)