Vimliner: The Smallest, Fastest Outliner for VIM

By , 6 March 2016

Vimliner: The Smallest, Fastest Outliner for VIM

I was quite fond of the WorkFlowy outliner until the sync failed and broke my offline access. It was just lucky that I'd made an export of my data not too long before it failed.

But really, I didn't need sync that much. I just needed a fast outliner. And what could faster than Vim? With a bit of investigation into Vim's code folding capabilities, I came up with a single-file script to turn Vim into a fast and simple outliner. It is fully functional, and is only 21 lines of code.

Here is what it looks like. You just use <TAB> to open and close the folds, and navigate through your outline.

To install Vimliner, just copy vimliner.vim to your $HOME/.vim/ftdetect directory and use a .out extension for your outliner files. You can also use :set filetype=vimliner if you prefer not to use the file extension.

Download vimliner.vim

UPDATE: For the latest version, which includes additional productivity features, head on over to github.

Here is the full code of vimliner.vim for the curious.​

Enjoy!

"
" Vimliner is the smallest outliner for vim. It uses vim's existing code 
" folding capabilities with some simple configuration. The result is a fast,
" powerful outliner using your favourite text editor.
"
" Install Vimliner by saving this file to $HOME/.vim/ftdetect/vimliner.vim
" on unix, or $HOME/vimfiles/ftdetect/vimliner.vim on Windows.
"
" Save your outliner files with a .out extension for Vimliner to be 
" autodetected. Otherwise, use :set filetype=vimliner from within vim.
"
" The outliner uses an indentation level of 2 white spaces to create 
" new levels. You can use vim's default code folding shortcuts to move
" throughout your outline, or just use <TAB> to open and close levels.
" 
" The most frequent shortcut keys you will use are:
"
" <TAB> open or close the current fold
"   zx  close all other folds  
"
" Use :help fold-commands in vim for additional shorcuts.
" 
" The fold function consumes blank lines. If you need to separate one
" fold from another, use a string of space characters that match the
" current indent level.
"
" News And Updates:
"
" https://rogerkeays.com/vimliner
" https://www.vim.org/scripts/script.php?script_id=5343
"
" Release Notes:
"
" 20200430_1.2 - renamed to vimliner to avoid confusion with rival project
" 20200424_1.1 - allow lines containing only whitespace
" 20160305_1.0 - initial release
"
" License: https://opensource.org/licenses/Apache-2.0
" Author: Roger Keays
"
autocmd BufRead,BufNewFile *.out set filetype=vimliner
autocmd FileType vimliner set foldmethod=expr foldexpr=VimlinerFold(v:lnum)
autocmd FileType vimliner set foldtext=getline(v:foldstart).'\ ›' fillchars= 
autocmd FileType vimliner set shiftwidth=2 expandtab autoindent
autocmd FileType vimliner set linebreak breakindent showbreak=--------------\ 

autocmd FileType vimliner hi Folded ctermbg=black ctermfg=yellow
autocmd FileType vimliner nnoremap <TAB> za

function! VimlinerFold(lnum)
    if getline(a:lnum) =~? '^$'
        return VimlinerFold(a:lnum - 1)
    endif

    let this_indent = indent(a:lnum) / &shiftwidth
    let next_indent = indent(a:lnum + 1) / &shiftwidth

    if next_indent == this_indent
        return this_indent
    elseif next_indent < this_indent
        return this_indent
    elseif next_indent > this_indent
        return '>' . next_indent
    endif
endfunction
Vimliner: The Smallest, Fastest Outliner for VIM

About Roger Keays

Vimliner: The Smallest, Fastest Outliner for VIM

Roger Keays is an artist, an engineer, and a student of life. He has no fixed address and has left footprints on 40-something different countries around the world. Roger is addicted to surfing. His other interests are music, psychology, languages, the proper use of semicolons, and finding good food.

Leave a Comment

Please visit https://rogerkeays.com/vimliner to add your comments.

Comment posted by: , 1 month ago

Hi Emin, glad you found the script useful. I still use it every day, eight years after I hacked it together. I've recently added some simple features to query your data which is useful if you're using Vimliner for planning. Head on over to github to take a look. You might also be interested in Vimliner's sister project, Vimjournal. If you use Vimliner for planning your future, Vimjournal is the equivalent for recording the past. 

Comment posted by: Emin Tavlayan, 1 month ago

I have downloaded, and immidiately started enjoying

Appriciate the work to make it dead simple

I am a fan of Dynalist after pain in workflowy

learning Vim and Dvorak at the same time

was looking to fold and narrow to replace online tools, but all outliner repos are way to complicated for me

this is the pure form of getting things done

Thank you

Comment posted by: , 4 years ago

Hi George, Glad you like vimflowy. I've uploaded a new version which is smaller, faster and allows you to add white space after the folds. Just thought you might be interested. If you install it, you may find additional whitespace in your existing outlines which you will have to remove manually.

Comment posted by: George Ford, 4 years ago

Ok, I should have played with it more first. Apologies.

1.) I set line 31 as follows: autocmd FileType vimflowy set shiftwidth=4 expandtab autoindent

2.) Since that overrides my :set tabstop=4 in my vimrc file, that explained also why '<' and '>' weren't functioning 'properly'.

3.) Also, no need for backspace to un-indent. Just use '<'. 

Liking it so far. Very simple and easy to use.

Comment posted by: George, 4 years ago

Started using this tool. Can you implement a means in which pressing delete in an indented section automatically goes back 'tabstop'? Also, on my computer, the '>' and '<' for tab indent and outdent no longer work correctly.

Comment posted by: Jeff Wu, 8 years ago

Are you aware of this?  https://github.com/WuTheFWasThat/vimflowy

Comment posted by: otheus, 8 years ago

Very cool.