loading...
Cover image for Taking notes in vim revisited

Taking notes in vim revisited

konstantin profile image Konstantin ・3 min read

In my previous post I talked about a vimwiki plugin for taking notes:

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» 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 Leaderww)
  • 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 enter shortcut that creates new markdown files and opens them with gf(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 –– ge 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 logo pbrisbin / vim-mkdir

Automatically create any non-existent directories before writing the buffer.

Mkdir

Maggie! Don't even ask. Just bring it. Come on.

-- Hot Rod

Installation

Install using your preferred vim plugin management plugin.

Usage

:e this/does/not/exist/file.txt
:w

Smile when you are not presented with an error. Instead, notice that vim has automatically created the non-existent directory for you.




so if you add to your .vimrc or init.vim following plugins:

Plug 'pbrisbin/vim-mkdir'
Plug 'plasticboy/vim-markdown', { 'for': 'markdown' }

provided that you're using vim-plug as a plugin manager, you should be able to type ge 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.

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:

" 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 logo jkramer / vim-checkbox

Vim plugin for toggling checkboxes.

Vim Checkbox

Description

Simple plugin that toggles text checkboxes in Vim. Works great if you're using a markdown file for notes and todo lists.

Installation

Just copy the script into your plugin folder, e.g. ~/.vim/plugin/. If you're using pathogen, just clone this repository in ~/.vim/bundle.

Usage

Press <leader>tt to toggle the (first) checkbox on the current line, if any. That means, [ ] will be replaced with [x] and [x] with [ ]. If you want more or different checkbox states, you can override the contents of g:checkbox_states with an array of characters, which the plugin will cycle through. The default is:

let g:checkbox_states = [' ', 'x']

When there's no checkbox on the current line, <leader>tt will insert one at the pattern defined in g:insert_checkbox. The new checkbox's state will be the first element of g:checkbox_states. The default for g:insert_checkbox is '\<', which…

the shortcut that interests us is Leadertt 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 logo iamcco / markdown-preview.nvim

markdown preview plugin for (neo)vim

Markdown Preview for (Neo)vim

Powered by ❤️

Introduction

It only works on vim >= 8.1 and neovim

Preview markdown on your modern browser with synchronised scrolling and flexible configuration

Main features:

Note it's no need mathjax-support-for-mkdp plugin for typesetting of math

screenshot

install & usage

Install with vim-plug:

" If you don't have nodejs and yarn
" use pre build, add 'vim-plug' to the filetype list so vim-plug can update this plugin
" see: https://github.com/iamcco/markdown-preview.nvim/issues/50
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']}
" If you have nodejs and yarn
Plug 'iamcco/markdown-preview.nvim', { 'do': 

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:

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 logo gko / vimio

🎩 easy to install/use vim settings

Vim Settings

screenshot

An article describing key features of this config.

Prerequisites

In order to get all features you might want to install following packages:

Installation

On unix and windows(with bash which can be installed with git):

curl -L https://raw.github.com/gko/vimio/master/install.sh | bash

macOS

In macOS terminal.app don't forget to check the «Use option as meta key»:

terminal

And «Esc+» option in iterm2:

iterm2

Shortcuts

Some of shortcuts(Leader key is comma):

  • Ctrl + s saves current file
  • Leader + s in both select and normal mode initiates search and replace
  • Alt + Up/Down moves line or selection above or below current line(see upside-down for more info)
  • Alt + Left/Right moves character or selection to left or to the right
  • Leader + n toggles NERDTree
  • Leader + m shows current file in NERDTree
  • when in select mode ', ", ( wraps selection accordingly
  • y

You can also find me on twitter: https://twitter.com/konstantin

Discussion

pic
Editor guide