Opinionated minimal implementation of Emacs' narrowing feature.
The NrrwRgn plugin is nice, but tends to have unpredictable behaviour in Neovim, at least for me.
Also at > 1500 lines of Vimscript, it's overkill for my needs.
So I decided to create a lua implementation of the minimal version that's suitable for my workflow.
No mappings by default, create them explicitly:
vim.keymap.set('x', '<Leader><Leader>nr', '<Plug>(minimal-narrow-region-open)')
vim.keymap.set('n', '<Leader><Leader>NR', '<Plug>(minimal-narrow-region-close)')
- Use visual mode to select the text to narrow on.
- Use
<Plug>(minimal-narrow-region-open)
to copy the selected text into a newly opened scratch buffer with the same filetype that is created withvertical botright
in the same tab. - Optionally, use
CTRL-W CTRL-O
orCTRL-W T
if the opened window is too small. - Edit the text.
- Use
<Plug>(minimal-narrow-region-close)
to copy the selected text into the clipboard, close the scratch buffer, and go back to the original buffer and reselect the original visual selection. - Press
p
to paste the text and see the change.
There are basic sanity checks, but it's probably not totally foolproof. In particular, the original buffer is not made read-only.
Except for the mappings no configuration is possible. if the above description almost (but not quite) fits your workflow, consider copying and adapting the code.
Otherwise, consider picking one of the other numerous existing narrow region plugins.
- yode-nvim Ambitious lua-based narrow-region plugin with a focus on multiple narrow regions.
- NrrwRgn Famous narrow-region plugin in Vim-land. I used this before creating this plugin.
Developed and tested on Neovim 0.8.2
.