Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/LZDQ/nvim-autocenter
https://github.com/LZDQ/nvim-autocenter
Last synced: 17 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/LZDQ/nvim-autocenter
- Owner: LZDQ
- Created: 2024-08-23T14:58:43.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-09-15T08:13:36.000Z (4 months ago)
- Last Synced: 2024-09-15T11:01:53.945Z (4 months ago)
- Language: Lua
- Size: 1.06 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- my-neovim-pluginlist - LZDQ/nvim-autocenter - autocenter) ![](https://img.shields.io/github/last-commit/LZDQ/nvim-autocenter) ![](https://img.shields.io/github/commit-activity/y/LZDQ/nvim-autocenter) (View / Screen position)
README
# nvim-autocenter
Auto zz when inserting.
## Demo
https://github.com/user-attachments/assets/df50d1b3-4504-4f16-b0c7-e7eb3551e7a3
## Requirements
Tested only on latest release, but will work on other versions as well.
## Installation
vim-plug
```
Plug 'LZDQ/nvim-autocenter'
```## Usage
Auto center the current line when inserting.
By default, only center the current line when the current line is whitespaces and the cursor is within [1/3, 2/3] of the screen height.
To disable the check of whitespaces and always center when inserting outside the range, change the `when` parameter in the setup to "always".
To disable auto centering when inserting text, change `when` to "never". In this case, you should enable plugin support for nvim-autopairs (auto centering when pressing enter in a pair of curly brackets), or this plugin is completely functionless.
## Setup
Default setup. Leave it empty if you don't want to change it.
```lua
require("nvim-autocenter").setup{
-- auto center only when the cursor is not within this range vertically
ratio_top = 1 / 3,
ratio_bot = 2 / 3,
-- When to call `autozz`. Choose between 'always', 'empty', and 'never'.
-- 'always' means to always do autozz when buffer text changes.
-- 'empty' means to do autozz only when the current line contains whitespaces.
-- 'never' means do not autozz. If you choose never, you should enable autopairs.
when = 'empty',
-- plugin support
plugins = {
-- auto center when pressing enter inside specific brackets
autopairs = {
enabled = true,
-- These are rules to auto center when pressing enter after it.
-- Each item is the lhs of the rule.
rules_with_cr = {
"{",
"'''",
'"""',
}
}
},
filetypes = {
-- Enable or disable filetypes. Use REGEX!!
-- Wildcard * doesn't work, use .* plz.
-- disabled rules beats enabled rules when contradicting.
enabled = { ".*" },
disabled = { "json" },
}
}
```## Features
Caching the last line number to avoid recursion and improve performance.
## Plugins supported
[windwp/nvim-autopairs](https://github.com/windwp/nvim-autopairs)
Automatically center when inserting newline inside curly brackets.
## TODO
1. - [x] Add more support for nvim-autopairs