Skip to content

chrisgrieser/nvim-origami

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nvim-origami

badge

Features

  • Use h at the first non-blank character of a line (or before) to fold. Use l anywhere on a folded line to unfold it.1 This allows you to ditch zc, zo, and za – you can just use h and l to work with folds. (h still moves left if not at the beginning of a line, and l still moves right when on an unfolded line – this plugin basically "overloads" those keys.)
  • Pause folds while searching, restore folds when done with searching. (Normally, folds are opened when you search for some text inside a fold, and stay open afterward.)
  • Remember folds across sessions (and as a side effect, also the cursor position).

Note

This plugin only opens and closes folds. It does not provide a foldmethod. You need to define a foldmethod either yourself or through a folding provider like nvim-ufo for this plugin to work.

Installation

-- lazy.nvim
{
	"chrisgrieser/nvim-origami",
	event = "BufReadPost", -- later or on keypress would prevent saving folds
	opts = true, -- needed even when using default config
},

-- packer
use {
	"chrisgrieser/nvim-origami",
	config = function () 
		require("origami").setup ({}) -- setup call needed
	end,
}

The .setup() call or lazy's opts is required. Otherwise, the plugin works out of the box without any necessary further configuration.

Configuration

-- default values
require("origami").setup {
	keepFoldsAcrossSessions = true,
	pauseFoldsOnSearch = true,
	setupFoldKeymaps = true,
}

Recommendation: By setting 'startofline' to true, bigger movements move you to the start of the line, which works well with this plugin's h key.

If you use other keys than h and l for vertical movement, set setupFoldKeymaps to false and map the keys yourself:

require("origami").h()
require("origami").l()

Limitations

Many formatting plugins open all your folds and unfortunately, there is nothing this plugin can do about it. The only two tools that are able to preserve folds are the efm-language-server and conform.nvim.

Other Folding Plugins

About the developer

In my day job, I am a sociologist studying the social mechanisms underlying the digital economy. For my PhD project, I investigate the governance of the app economy and how software ecosystems manage the tension between innovation and compatibility. If you are interested in this subject, feel free to get in touch.

I also occasionally blog about vim: Nano Tips for Vim

Buy Me a Coffee at ko-fi.com

Footnotes

  1. Technically, unfolding with l is already a built-in vim feature when foldopen includes hor. However, this plugin still sets up a l key replicating that behavior, since the built-in version still moves you to one character to the side, which can be considered a bit counterintuitive.

About

Fold with relentless elegance.

Resources

License

Stars

Watchers

Forks

Languages