Giter VIP home page Giter VIP logo

focus.nvim's Introduction

GitHub stars Requires GitHub contributors GitHub issues GitHub issues-closed PRs Welcome

Breaking Change

You must now run the setup() function to being using focus.

Details below and code snippets are in the readme to get you started.

Auto-resizing Focused Splits/Windows for Neovim

๐Ÿ”‹ Batteries Included. No configuration neccessary

๐Ÿ‘Œ Maximises Current Split/Window Automatically When Cursor Moves Based On Golden Ratio

โš™๏ธ Set Focus Auto-Cursorline/SignColumn/LineNums & Active/Inactive Win-Highlight + Disable

๐Ÿ™Œ Compatible with NvimTree, NerdTree, CHADTree, Telescope, FZF & QuickFix (QF default to 10, rest won't resize)

๐Ÿ‘๏ธ Currently focussed split/window automagically maximised to the perfect viewing size according to golden ratio

๐Ÿƒ Move to existing windows or else create new splits automatically, using single command + can specify a file to open

โฑ Supports lazy loading via packer

Demo

screencast

note: for reference this screencast features dimensions set to 120*40 (W*H)

See a visual demonstration of each focus feature here

Installation

use { "beauwilliams/focus.nvim", config = function() require("focus").setup() end }
-- Or lazy load with `module` option. See further down for info on how to lazy load when using FocusSplit commands
-- Or lazy load this plugin by creating an arbitrary command using the cmd option in packer.nvim
-- use { 'beauwilliams/focus.nvim', cmd = "FocusSplitNicely", module = "focus",
--     config = function()
--         require("focus").setup({hybridnumber = true})
--     end
-- }
Plug 'beauwilliams/focus.nvim'
"You must run setup() to begin using focus
lua require("focus").setup()

Vim Commands

For more information on below commands scroll down to see them each described in more detail

Command Description
:FocusDisable Disable the plugin per session. Splits will be normalised back to defaults and then spaced evenly.
:FocusEnable Enable the plugin per session. Splits will be resized back to your configs or defaults if not set.
:FocusToggle Toggle focus on and off again.
:FocusSplitNicely Split a window based on the golden ratio rule
:FocusSplitLeft Move to existing or create a new split to the left of your current window
:FocusSplitDown Move to existing or create a new split to the bottom of your current window
:FocusSplitUp Move to existing or create a new split to the top of your current window
:FocusSplitRight Move to existing or create a new split to the right of your current window
:FocusEqualise Temporarily equalises the splits so they are all of similar width/height
:FocusMaximise Temporarily maximises the focussed window
:FocusMaxOrEqual Toggles Between having the splits equalised or the focussed window maximised

Splitting Nicely

Focus allows you to split windows to tiled windows nicely and sized according to the golden ratio

+----------------+------------+
|                |    S1      |
|                |            |
|                +------------+
|                |            |
|   MAIN PANE    |    S2      |
|                |            |
|                |            |
|                |            |
+----------------+------------+

To get this view you would press the key combination 2 times.

Split nicely with <C-L>

vim.api.nvim_set_keymap('n', '<c-l>', ':FocusSplitNicely<CR>', { silent = true })
-- Or use lua-style keymap
--vim.api.nvim_set_keymap('n', '<c-l>', ":lua require('focus').split_nicely()<CR>", { silent = true })

Auto Splitting Directionally

Instead of worrying about multiple commands and shortcuts, simply think about splits as to which direction you would like to go.

Calling a focus split command i.e :FocusSplitRight will do one of two things, it will attempt to move across to the window in the specified direction. Otherwise, if no window exists in the specified direction relative to the current window then it will instead create a new blank buffer window in the direction specified, and then move to that window.

Recommended commands, leverage hjkl to move and create your splits directionally with ease

vim.api.nvim_set_keymap('n', '<leader>h', ':FocusSplitLeft<CR>', { silent = true })
vim.api.nvim_set_keymap('n', '<leader>j', ':FocusSplitDown<CR>', { silent = true })
vim.api.nvim_set_keymap('n', '<leader>k', ':FocusSplitUp<CR>', { silent = true })
vim.api.nvim_set_keymap('n', '<leader>l', ':FocusSplitRight<CR>', { silent = true })

If you lazy load this plugin with packer module option, please use lua-style keymap

local focusmap = function(direction)
    vim.api.nvim_set_keymap('n', '<Leader>'..direction, ":lua require'focus'.split_command('"..direction.."')<CR>", { silent = true })
end
-- Use `<Leader>h` to split the screen to the left, same as command FocusSplitLeft etc
focusmap('h')
focusmap('j')
focusmap('k')
focusmap('l')

Opening a file in a new split directionally

This feature allows you to open a file in a split specifying which position you want it to be located

For example :FocusSplitRight somefile.lua will open somefile.lua to the right of your current window.

You can also specify a mapping, or perhaps a function to even add lazy loading.

Configuration

Example Configuration

require("focus").setup({enable = true, cursorline = true, signcolumn = true, hybridnumber = true})

Available Options

Enable/Disable Focus

-- Completely disable this plugin
-- Default: true
require("focus").setup({enable = false})

Set Focus Width

-- Force width for the focused window
-- Default: Calculated based on golden ratio
require("focus").setup({width = 120})

Set Focus Height

-- Force height for the focused window
-- Default: Calculated based on golden ratio
require("focus").setup({height = 40})

Set Focus Tree Width

-- Sets the width of directory tree buffers such as NerdTree, NvimTree and CHADTree
-- Default: vim.g.nvim_tree_width or 30
require("focus").setup({treewidth = 20})

Set Focus Auto Cursorline

-- Displays a cursorline in the focussed window only
-- Not displayed in unfocussed windows
-- Default: true
require("focus").setup({cursorline = false})

Set Focus Auto Sign Column

-- Displays a sign column in the focussed window only
-- Not displayed in unfocussed windows
-- Default: true
require("focus").setup({signcolumn = false})

Set Focus Auto Numbers

-- Displays line numbers in the focussed window only
-- Not displayed in unfocussed windows
-- Default: true
require("focus").setup({number = false})

Set Focus Auto Relative Numbers

-- Displays relative line numbers in the focussed window only
-- Not displayed in unfocussed windows
-- See :h relativenumber
-- Default: false
require("focus").setup({relativenumber = true})

Set Focus Auto Hybrid Numbers

-- Displays hybrid line numbers in the focussed window only
-- Not displayed in unfocussed windows
-- Combination of :h relativenumber, but also displays the line number of the current line only
-- Default: false
require("focus").setup({hybridnumber = true})

Set Focus Window Highlighting

-- Enable auto highlighting for focussed/unfocussed windows
-- Default: false
require("focus").setup({winhighlight = true})

-- By default, the highlight groups are setup as such:
--   hi default link FocusedWindow VertSplit
--   hi default link UnfocusedWindow Normal
-- To change them, you can link them to a different highlight group, see `:h hi-default` for more info.
vim.cmd('hi link UnfocusedWindow CursorLine')
vim.cmd('hi link FocusedWindow VisualNOS')

Planned Improvements ๐Ÿ˜ผ

  • Refactoring
  • Adding more filetype support as we go
  • Adding Auto Line Numbers, options for relative, norelative

FAQ

I have a small display and I am finding splits are resized too much

If for example your screen resolution is 1024x768 --> i.e on the smaller side, you may notice that focus by default can maximise a window too much.

That is, the window will sort of 'crush' some of your other splits due to the limited screen real estate. This is not an issue with focus, but an issue with minimal screen real estate. In this case, you can simply reduce the width/height of focus.

Quickfix window opens in the right split always. Is this caused by focus.lua?

No. This is a documented design decision by core vim, this might be something that can be adjusted upstream.

In the meantime, you can open a quickfix window occupying the the full width of the window with :botright copen

I tried to lazy load focus with :FocusToggle, but I need to toggle it again to get auto-resizing working

Please note if you lazy load with command :FocusToggle, it will load focus, but will toggle it off initially. See #34

This is because focus is toggled on by default when you load focus, so if you load it and then run the command :FocusToggle, it toggles it off again.

Developers Only

Contributing

Please before submitting a PR install stylua here

And run stylua . from your shell in the root folder of focus.nvim

This will format the code according to the guidlines set in stylua.toml

focus.nvim's People

Contributors

beauwilliams avatar cryptomilk avatar levouh avatar sagarc03 avatar

Watchers

 avatar

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.