outliner

A table-of-contents sidebar for markdown and LaTeX files in Vim.

Written in Vimscript. Needs Vim 8.1 or newer and nothing else.

Vim with a markdown file and the outline on the left. The cursor moves into the outline, Enter jumps to a header, a new header appears in the outline after saving, and a LaTeX file gets the same outline.

Install*outliner-install*

Plug 'cegme/outliner'

With Vim 8 packages and no plugin manager:

git clone https://github.com/cegme/outliner.git \
    ~/.vim/pack/plugins/start/outliner

Open a .md or .tex file. The outline appears on the left and the cursor stays in your text.

Use*outliner-use*

<Leader>ot
Show or hide the outline.
<Leader>of
Move the cursor into the outline, and back to the text.

Inside the outline:

Enter
Jump to the header. A double-click does the same.
r
Refresh the outline.
q
Close it.
?
List the keys in use.

The outline refreshes when you save. It follows the file you are editing and closes when that file is closed. :q in the text window exits Vim instead of leaving the outline alone.

Switching between a LaTeX file and a markdown file changes the outline. Deleting each buffer with :bd shows the outline of the file you land on, and deleting the last file closes the outline.
Switching files and closing them with :bd.

Markdown and LaTeX*outliner-languages*

Markdown headers from # to ###### are listed, and fenced code is skipped. In LaTeX, \part through \subsubsection are listed, and comments and verbatim blocks are skipped. A header is indented under the closest earlier header with a smaller level.

notes.md
# Introduction

## Getting Started

### Prerequisites

### Installation

## Usage

# Other stuff
paper.tex
\section{Introduction}

\subsection{Getting Started}

\subsubsection{Prerequisites}

\subsubsection{Installation}

\subsection{Usage}

\section{Other stuff}

Both give this outline:

Introduction
  Getting Started
    Prerequisites
    Installation
  Usage
Other stuff

LaTeX header commands*outliner-latex*

Class files and slide decks use different sectioning commands. g:outliner_tex_headers maps a command name to a level. Entries merge over the defaults, only the order of the levels matters, and a level of 0 hides a command.

" Beamer slides
let g:outliner_tex_headers = {'frametitle': 4}

" A command from your class file, and run-in paragraph headings
let g:outliner_tex_headers = {'mysection': 3, 'paragraph': 6}

" Hide \part in a book
let g:outliner_tex_headers = {'part': 0}

\paragraph and \subparagraph are off by default. Many papers use them for run-in labels such as "Goal." and "Procedure.", which would crowd the outline.

A LaTeX paper outline. Setting paragraph to level 6 adds the run-in headings, adding mysection at level 3 lists a custom command, and setting subsection to 0 hides the subsections.
Changing g:outliner_tex_headers and refreshing.

Settings*outliner-settings*

Put these in your .vimrc.

g:outliner_width
Sidebar width in columns. Default 20.
g:outliner_position
'left' or 'right'. Default 'left'.
g:outliner_auto_open
Open the outline when a supported file is entered. Default 1.
g:outliner_focus
Put the cursor in the outline when it opens. Default 0, so the cursor stays in the text.
g:outliner_filetypes
Filetypes that get an outline. Default ['markdown', 'tex', 'plaintex'].
g:outliner_tex_headers
LaTeX command names and levels, described above.
g:outliner_mappings
Replace the keys inside the outline, for example {'jump': ['<CR>', 'o']}.
g:outliner_no_mappings
Set to 1 to skip the default <Leader> keys. Map <Plug>(outliner-toggle) and <Plug>(outliner-focus) yourself.
The outline moves to the right side at 30 columns wide. With focus set to 1 the cursor goes into the outline when it opens, and Enter jumps back to the text.
Moving the sidebar and changing where the cursor goes.