Skip to content

Instantly share code, notes, and snippets.

@rajivrnair
Last active April 1, 2018 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajivrnair/c1962061b1bda9236ce2be983545e32e to your computer and use it in GitHub Desktop.
Save rajivrnair/c1962061b1bda9236ce2be983545e32e to your computer and use it in GitHub Desktop.
simple journal with vi
# Create a folder and write a simple script to open a file.
$> mkdir /Journal && cd /Journal && touch writer.sh && chmod u+rwx writer.sh`
# Here's `writer.sh`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/zsh
# create a folder with today's date if it does not exist
folder=`date +%Y_%m_%d`
mkdir -p $folder
cd $folder
# start vim in insert mode + create file for today's journal.
vi +star `date +%Y%m%d`".jrnl"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Write an alias into your zshrc or bash_profile so you can get to it from anywhere.
alias journal="cd /Journal;./writer.sh"
# Note: comments in .vimrc start with a " and not a # - this is just for easier markdown.
# Enable spell check and also toggle it.
set spell spelllang=en_gb
cmap <F6> setlocal spell!
# Setup a simple statusline - the focus is on less clutter and just the info I need.
function! WordCount()
let s:old_status = v:statusmsg
let position = getpos(".")
exe ":silent normal g\<c-g>"
let stat = v:statusmsg
let s:word_count = 0
if stat != '--No lines in buffer--'
let s:word_count = str2nr(split(v:statusmsg)[11])
let v:statusmsg = s:old_status
end
call setpos('.', position)
return s:word_count
endfunction
hi User1 ctermbg=black ctermfg=red cterm=BOLD guibg=black guifg=red gui=BOLD
set laststatus=2
set statusline=
set statusline+=%1* # use the highlight specified above.
set statusline+=%<\ # cut at start
set statusline+=%-40t\ # path
set statusline+=%= # left/right separator
set statusline+=%10([%l,%c]%)\ # line and column
set statusline+=(wc:%{WordCount()}) # word count
# Some journalling options
# Every time you open a journal file (create/edit), append the timestamp
autocmd VimEnter *.jrnl $pu=strftime('%n[%a, %d %b %Y %T %z]%n%n')
# Set line number
autocmd VimEnter *.jrnl setl number
# Indicate column 120 - just to get a visual indication of an end margin.
autocmd VimEnter *.jrnl set colorcolumn=120
# Indicate the current line.
autocmd VimEnter *.jrnl set cursorline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment