DEV Community

Cason Adams
Cason Adams

Posted on

Simple vim note setup

I have tried a few techniques in taking, organizing, and searching notes. I found the more notes I took the more difficult it was to find what I wanted, or keep them all organized. I decided to just let it slip and see what happens. I finally hit a point where I needed a fuzzy finder to find what I was looking for. This led me to this simple setup with vim.

Notes and where to keep them

First I needed a place to store my notes. I've tried file syncing software, which is fine but I really didn't want some process always on taking up resources. So I decided to use gitlab wiki. Here is how I got setup:

Create a private repo in gitlab. Then clone that repo's wiki to your local machine. Here is an example of cloning a wiki. I cloned this to $HOME and will set it as an ENV var in the steps to follow.

git clone git@gitlab.com:myawesomeproject/notes.wiki
Enter fullscreen mode Exit fullscreen mode

side note

I don't like using auto command on exit/save to auto-commit the notes but that is an option. For now I do this manually as needed.

Notes and how to find what you are looking for

Setup an ENV var in ~/.bash_profile or ~/.bashrc or where ever your operating system loads in ENV vars. I use this export NOTES="$HOME/notes.wiki" this just needs to be the path that the notes wiki was cloned to.

Add fzf as a vim plugin Installing instructions

Create a helper method in the vimrc file. Then map :Notes to <Leader>n.

"------------------------------------------------
" Note search START
command! -bang -nargs=* Notes
  \ call fzf#vim#grep(
  \   'rg --column --line-number --no-heading --color=always --passthru "" $NOTES'.shellescape(<q-args>), 1,
  \   fzf#vim#with_preview(), <bang>0)

nmap <Leader>n :Notes<CR>
" Note search END
"------------------------------------------------
Enter fullscreen mode Exit fullscreen mode

Reload vim and give it a try :Notes or <Leader>n will bring up all the notes from the defined $NOTES dir, and allow for fuzzy searching.

If you don't want to fuzzy search you can always run :FZF $NOTES inside of vim and search via file name.

Optional FZF settings

Adding these setting will allow to toggle the preview window while invoking fzf in both your shell, or in vim by using ? key.

This will also setup your shell to use fzf commands ctrl + r, and ctrl + t

For optimal performance I have installed (most package mangers have these tools available)

I have these settings in my ~/.bashrc file:

export NOTES="$HOME/notes.wiki"

if [ ! -f "${HOME}/.key-bindings.bash" ]; then
  curl -sSL \
    https://raw.githubusercontent.com/junegunn/fzf/master/shell/key-bindings.bash \
    -o "${HOME}/.key-bindings.bash" \
    ;
fi

source "${HOME}/.key-bindings.bash"

export FZF_DEFAULT_COMMAND="fd"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND --type file"
export FZF_ALT_C_COMMAND="$FZF_DEFAULT_COMMAND --type d"
export FZF_DEFAULT_OPTS="
--layout=reverse
--info=inline
--height=50%
--preview-window=:hidden
--preview '([[ -f {} ]] \
│·&& (bat --style=numbers --color=always {} \
│·|| cat {})) \
│·|| ([[ -d {} ]] && (tree -C {} | less)) \
│·|| echo {} 2> /dev/null | head -200'
--bind '?:toggle-preview'
"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)