Coder Social home page Coder Social logo

centerpad.nvim's Introduction

centerpad.nvim

Center your single lonely buffer easily!

Are you only working on one file in your current neovim session? Do you have a big monitor and have to look all the way to the left of your screen to see your code? centerpad.nvim is here to help you easily center your code in the middle of your screen!

centerpad in action

Installing

Use your favorite package manager to install, here is how to install with a few of the most popular choices I am aware of:

-- packer.nvim
use { 'smithbm2316/centerpad.nvim' }
-- paq.nvim
paq 'smithbm2316/centerpad.nvim'
" vim-plug
Plug 'smithbm2316/centerpad.nvim'

Why centerpad.nvim?

This is a simple plugin that at the moment takes your current buffer and plops it into the middle of your screen, with two scratch buffers on either side. Nothing more than that! Of course, the width of how big the padding on each side of your screen is easily configurable as well! This plugin is simple by nature, as it is my first attempt at a Lua plugin, and really was just a utility module that I wrote for my own neovim dotfiles, that I figured I could pretty easily turn into a small plugin that a few others might get some use out of.

Usage

All you will have to do is run the command :Centerpad or :lua require'centerpad'.toggle() to toggle centering of your current buffer on/off. The :Centerpad command accepts 1-2 arguments, you can pass it one number to use for both sides of the centered buffer (i.e. :Centerpad 20), or two numbers if you want the left and right scratch buffers to use different sizing (i.e. :Centerpad 10 20).

Configuration

By default, centerpad.nvim will set the left and right padding to 36 columns each. If you want to override this, I'd recommend setting up a keybinding in your vim config similar to what I have in my own config:

In your init.lua

-- using the command
vim.api.nvim_set_keymap('n', '<leader>z', '<cmd>Centerpad<cr>', { silent = true, noremap = true })

-- or using the lua function
vim.api.nvim_set_keymap('n', '<leader>z', "<cmd>lua require'centerpad'.toggle{ leftpad = 20, rightpad = 20 }<cr>", { silent = true, noremap = true })

In your init.vim

" using the command
nnoremap <silent><leader>z <cmd>Centerpad<cr>

" or using the lua function
nnoremap <silent><leader>z <cmd>lua require'centerpad'.toggle { leftpad = 36, rightpad = 36 }<cr>

The leftpad and rightpad options will adjust the padding for the scratch buffers on the left and right side of your main buffer, respectively.

centerpad.nvim's People

Contributors

smithbm2316 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

centerpad.nvim's Issues

Feature request: Allow multiple centerpads

Hello, I've been really enjoying your plugin. It is nice and simple but I feel that a small tweak would make it perfect. Right now there can only be one centerpad. I like using tabs, a lot. And when I want to center a new buffer in that tab it doesn't work.

E5108: Error executing lua .../site/pack/packer/start/centerpad.nvim/lua/centerpad.lua:26: Vim:E95: Buffer with this name already exists

This is the error that I got, would it be possible for you to make it so that there can be multiple centerpads?

"Only one window and buffer open" error when using plugin in LazyVim

I keep getting this error when trying to launch Centerpad makes no sense since I only have one buffer open, im thinking it has something to do with tree-sitter but not really sure since tree-sitter only opens when I execute the command.

issue

this is the example of the file I had open.

Screenshot 2023-06-16 at 2 39 55 p m

not sure what other data I should provide for this issue, I just wanted to start a conversation in case somebody else had the same issue

Alternative Width: Textwidth of centered buffer instead of width of paddings

From a typographical point of view, a line length should no longer be than 75 characters (e.g. R. Bringhurst, The Elements of Typographic Style). Maybe more importantly many coding guidelines suggest a textwidth (typically from 79 to 120).

So IMHO, setting the padding width is not what a user wants but the actual width of the centered window (either following a coding guideline, .editorconfig, modeline, a typographical recommendation, ...).

To achieve a desired buffer window width, the user must know the current total width and calculate the necessary padding to achieve it with :Centerpad <padding width>.

It is easier to give the desired text width (either implicity by the vim setting textwidth, .editorconfig, modeline, ... or explicitly) and the width of the padding is calculated.

I have following suggestions/ideas

  • Add a similar option similar to g:venter_use_textwidth of https://github.com/JMcKiern/vim-venter
  • Add an explicit function, e.g. :CenterWindow <text width>
  • Provide a configuration example for a mapping with a fallback width (if textwidth is not set)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.