Skip to the content

Projects

narrowText.vim

Emacs-style narrowing for Vim and Neovim: work on one part of a long file, with the rest safely out of the way.

When you edit a long document, you sometimes want to work on one section without splitting the file and without everything else in the way. narrowText brings Emacs’s narrow and widen to Vim and Neovim.

Select the lines you want and narrow to them: the rest of the file is moved into a hidden backup beside it, and the buffer holds only your selection. Edit freely, add lines or remove them, then widen: your changes are put back in their place in the whole document, and it is saved.

  • Nothing to distract. Only the section you are working on is in the buffer, which also makes it quick to read with a screen reader.
  • Edits stitched back. Lines added while narrowed go into the right place when you widen.
  • Safe after a crash. If Vim stops while a file is narrowed, narrowText finds the hidden backup next time and offers to restore the whole file.
  • Widens on the way out. Quitting widens and saves the full document.

Using it

CommandKeyWhat it does
:NarrowToSelection<leader>-Narrow to the selection, or to the current line
:Widen<leader>+Widen, put the edits back and save

Your own keys:

map  <your-keys> <Plug>(HideTextNarrow)
nmap <your-keys> <Plug>(HideTextWiden)

set statusline+=%{narrowText#Status()} shows in the status line when a buffer is narrowed. :help narrowText has the whole manual.

Installing

With vim-plug:

Plug 'thetextsmith/narrow-text'

With lazy.nvim, { "thetextsmith/narrow-text" }; with packer.nvim, use 'thetextsmith/narrow-text'. Or with Vim’s own packages:

git clone https://github.com/thetextsmith/narrow-text.git ~/.vim/pack/plugins/start/narrow-text

The source is at github.com/thetextsmith/narrow-text, under the Apache License 2.0.