GithubHelp home page GithubHelp logo

s1n7ax / nvim-window-picker Goto Github PK

View Code? Open in Web Editor NEW
285.0 5.0 24.0 108 KB

This plugins prompts the user to pick a window and returns the window id of the picked window

License: MIT License

Lua 99.90% Vim Script 0.10%
neovim neovim-plugin neovim-plugins neovim-lua neovim-lua-plugin

nvim-window-picker's Introduction

nvim-window-picker

hint = 'floating-big-letter'

window-picker-float-demo.mp4

hint = 'statusline-winbar'

window-picker-winbar-demo.mp4

This plugins prompts the user to pick a window and returns the window id of the picked window.

Install

lazy

{
    's1n7ax/nvim-window-picker',
    name = 'window-picker',
    event = 'VeryLazy',
    version = '2.*',
    config = function()
        require'window-picker'.setup()
    end,
}

packer

use {
    's1n7ax/nvim-window-picker',
    tag = 'v2.*',
    config = function()
        require'window-picker'.setup()
    end,
}

How to use

local picked_window_id = require('window-picker').pick_window()

You can put the picked window id to good use

Configuration

If you want to have custom properties just for one time, you can pass any of following directly to pick_window() function itself to override the default behaviour.

require 'window-picker'.setup({
    -- type of hints you want to get
    -- following types are supported
    -- 'statusline-winbar' | 'floating-big-letter'
    -- 'statusline-winbar' draw on 'statusline' if possible, if not 'winbar' will be
    -- 'floating-big-letter' draw big letter on a floating window
    -- used
    hint = 'statusline-winbar',

    -- when you go to window selection mode, status bar will show one of
    -- following letters on them so you can use that letter to select the window
    selection_chars = 'FJDKSLA;CMRUEIWOQP',

    -- This section contains picker specific configurations
    picker_config = {
        statusline_winbar_picker = {
            -- You can change the display string in status bar.
            -- It supports '%' printf style. Such as `return char .. ': %f'` to display
            -- buffer file path. See :h 'stl' for details.
            selection_display = function(char, windowid)
                return '%=' .. char .. '%='
            end,

            -- whether you want to use winbar instead of the statusline
            -- "always" means to always use winbar,
            -- "never" means to never use winbar
            -- "smart" means to use winbar if cmdheight=0 and statusline if cmdheight > 0
            use_winbar = 'never', -- "always" | "never" | "smart"
        },

        floating_big_letter = {
            -- window picker plugin provides bunch of big letter fonts
            -- fonts will be lazy loaded as they are being requested
            -- additionally, user can pass in a table of fonts in to font
            -- property to use instead

            font = 'ansi-shadow', -- ansi-shadow |
        },
    },

    -- whether to show 'Pick window:' prompt
    show_prompt = true,

    -- prompt message to show to get the user input
    prompt_message = 'Pick window: ',

    -- if you want to manually filter out the windows, pass in a function that
    -- takes two parameters. You should return window ids that should be
    -- included in the selection
    -- EX:-
    -- function(window_ids, filters)
    --    -- folder the window_ids
    --    -- return only the ones you want to include
    --    return {1000, 1001}
    -- end
    filter_func = nil,

    -- following filters are only applied when you are using the default filter
    -- defined by this plugin. If you pass in a function to "filter_func"
    -- property, you are on your own
    filter_rules = {
        -- when there is only one window available to pick from, use that window
        -- without prompting the user to select
        autoselect_one = true,

        -- whether you want to include the window you are currently on to window
        -- selection or not
        include_current_win = false,

        -- filter using buffer options
        bo = {
            -- if the file type is one of following, the window will be ignored
            filetype = { 'NvimTree', 'neo-tree', 'notify' },

            -- if the file type is one of following, the window will be ignored
            buftype = { 'terminal' },
        },

        -- filter using window options
        wo = {},

        -- if the file path contains one of following names, the window
        -- will be ignored
        file_path_contains = {},

        -- if the file name contains one of following names, the window will be
        -- ignored
        file_name_contains = {},
    },

    -- You can pass in the highlight name or a table of content to set as
    -- highlight
    highlights = {
        statusline = {
            focused = {
                fg = '#ededed',
                bg = '#e35e4f',
                bold = true,
            },
            unfocused = {
                fg = '#ededed',
                bg = '#44cc41',
                bold = true,
            },
        },
        winbar = {
            focused = {
                fg = '#ededed',
                bg = '#e35e4f',
                bold = true,
            },
            unfocused = {
                fg = '#ededed',
                bg = '#44cc41',
                bold = true,
            },
        },
    },
})
require('window-picker').pick_window({
    hint = 'floating-big-letter'
})

Theming

If you just want to define the colors using Neovim Highlights, then it's totally possible. You can set following highlights manually.

  • WindowPickerStatusLine (currently focused window statusline highlights)
  • WindowPickerStatusLineNC (currently unfocused window statusline highlights)
  • WindowPickerWinBar (currently focused window winbar highlights)
  • WindowPickerWinBarNC (currently unfocused window winbar highlights)

Breaking changes in v2.0.0

Before: return value from selection_display will be wrapped by '%=' and '%=' to fill the empty space of status line or winbar.

After: return value of selection_display will be passed directly to the status line or winbar. This allows all the customizations available from statusline syntax. You can check :help statusline for more info.

nvim-window-picker's People

Contributors

adoyle-h avatar botbotty avatar derekthecool avatar etrnal70 avatar github-actions[bot] avatar lamchau avatar lostl1ght avatar mehalter avatar nexmean avatar ofseed avatar s1n7ax avatar ttytm avatar williamboman 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  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  avatar  avatar

nvim-window-picker's Issues

How to change the size of floating-big-letter?

Hello!

Thank you for your work, that's a wonderful plugin, very useful!
I have only one question: how to change the size of floating-big-letter? Can I make it smaller or maybe I can make it size depend on window size?

I use this plugin for closing windows without changing focus to them. Usually I need to close LSP references at the bottom. With floating letter it start to look like this:
image

The letter on the bottom is "D", it got cropped and became unreadable. So with smaller sizes this could be solved

pick_window not showing picker

NVIM v0.10.0-dev
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

command:
:lua print(require("window-picker").pick_window())

prints id of current window but choice of window is never shown

configured without any parameters

`floating-big-letter` breaks with more than 8 splits

Description

If there are exactly 8 or less splits everything works great! However, when there are more than 8 splits, the plugin breaks and the only way to recover is to restart nvim.

If I switch to the default

E5108: Error executing lua: vim/shared.lua:0: s: expected string, got nil
stack traceback:
        [C]: in function 'error'
        vim/shared.lua: in function 'validate'
        vim/shared.lua: in function 'gsplit'
        vim/shared.lua: in function 'split'
        ...ker/lua/window-picker/hints/floating-big-letter-hint.lua:101: in function '_show_letter_in_window'
        ...ker/lua/window-picker/hints/floating-big-letter-hint.lua:128: in function 'draw'
        ...indow-picker/lua/window-picker/pickers/window-picker.lua:63: in function 'pick_window'
        /Users/test/.config/nvim/lua/keybindings.lua:85: in function </Users/test/.config/nvim/lua/keybindings.lua:84>

Screenshots

Works (<= 8 splits)

image

Error (>= 9 splits)

image

Error (< 8 splits; retrigger key)

Reducing the number of splits to try to clear/redraw.
image

Configuration

nvim version

$ nvim --version
NVIM v0.9.4
Build type: Release
LuaJIT 2.1.0-beta3

nvim-window-picker version

~/.config/nvim/plugged/nvim-window-picker  
$ git log | grep commit | head -n1
commit e7b6699

overrides.lua

require('window-picker').setup({
  hint = 'floating-big-letter'
})

vim.keymap.set('n', '<leader>w', function()
  local picked_window_id = require('window-picker').pick_window()
  if picked_window_id ~= nil then
    vim.api.nvim_set_current_win(picked_window_id)
  end
end, { noremap = false, silent = false })

`filter_func` function not executing

The function passed in the filter_func configuration option is not being executed.

Config

	config = function()
		local window_picker = require('window-picker')

		window_picker.setup({
			selection_chars = '1234567890ASDFGHJKLÇQWERTYUIOP',
			show_prompt = false,

			picker_config = {
				statusline_winbar_picker = {
					use_winbar = 'smart',
				},
			},

			-- This function is not being executed
			filter_func = function(windows, filters)
				print('ran filter func')

				return filters(windows)
			end,

			filter_rules = {
				autoselect_one = true,
				include_current_win = true,

				bo = {
					filetype = { 'notify', 'noice' },
				},
			},
		})

		map('n', 'gw', function()
			local picked = {require("window-picker").pick_window()}
			vim.fn["win_gotoid"](picked[1])
		end)
	end

Versions

nvim: NVIM v0.10.0-dev-979+g794981d9b
nvim-window-picker: 1b1bb83

Proposal: rename repository to `window-picker.nvim`

Because of the name of the repo being nvim-window-picker, in the lazy package manager we need to do name = "window-picker" to make it play nicely with the automatic setup with the opts table. If we rename the repository to window-picker.nvim then this would be handled automatically.

Totally understand if you don't want to do this, so feel free to close this! One upside with GitHub is it will automatically forward the original repository name/link to the new location as long as a new repository hasn't been made with the original owner/name

Picker "floating-big-letter" not working with LunarVim, NeoTree

Hey, im pretty new to vim, im using for a few weeks, and im struggling with windows picker.

Im using LunarVim as base for my vim configuration.

So, LunarVim already has a "window picker", i'd like to use the floatings-big-letter instead of the normal 'theme' of the windows picker from Lunar, i've tried everything that i found. It doesn't work when selecting from nvimtree, telescope. But when i called from the cmd using :lua print(require("window-picker").pick_window({hint="floating-big-letter"})) it works.

If any could help understand this would be really nice.

I've noticed that maybe i should disable the picker from nvimtree, but i think i have to attach some how "window-picker" to it, but i dont know how.

{
    's1n7ax/nvim-window-picker',
    name = 'window-picker',
    event = 'VeryLazy',
    version = '3.*',
    config = function()
      require 'window-picker'.setup({
        hint = 'floating-big-letter',
        selection_chars = 'FJDKSLA',
        prompt_message = 'Select Window: ',
      })
    end,
  },

How to make it work when using lazy?

I tried to install by

{
    's1n7ax/nvim-window-picker',
    setup = function()
        require('window-picker').setup()
    end,
},

It does install, but when running

lua require('nvim-window').pick()

I get error saiying nvim-window module not found.

[Feature Request] Autoselect, but only when there's two windows.

Here's the basic situation:

  1. I like the behaviour of autoselect_one = true when there's 2 windows (i.e. it automatically goes to the other one), as it takes less keystrokes.
  2. I like the behaviour of include_current_win = true when there's 3+ windows, as the placement of the selections is a lot more predictable, and I can jump without even looking at the label.

Problem: The two don't work together. With include_current_win = true, when there are just 2 windows, autoselect_one = true won't trigger, as there are 2 windows to be selected. So I have to disable it to have autoselect, which is unfortunate.

It'd be nice to have a config (or combinations of configs) that would allow autoselect_one to trigger when there's 2 windows, but include_current_win to work when there's 3+.

Great plugin btw :)

Add an option to use the current window if no suitable window is found

Basically, a problem occurs when using this plugin with neo-tree and opening a folder (e.g. nvim .). Since neo-tree hijacks netrw, the only opened window will be the file tree, which is added to the ignore list/not added in the first place when include_current_win is off. That means that if you have bound your normal open mappings to always use a window picker, you will not be able to open any windows.

I think adding an option that returns the current window ID when no selectable windows were matched would be the easiest solution for this. I would be open to implementing this if you agree with this solution.

Invalid window id

I hitting this error:

E5108: Error executing lua ...im/plugged/nvim-window-picker/lua/window-picker/init.lua:202: Invalid window id: 1015
stack traceback:
        [C]: in function 'nvim_win_set_option'
        ...im/plugged/nvim-window-picker/lua/window-picker/init.lua:202: in function 'pick_window'
        [string ":lua"]:1: in main chunk
Press ENTER or type command to continue

My configuration:

require 'window-picker'.setup({
	selection_chars = '123345',
})

feat: 'create or pick' mode

It would be a cool extension to be able to pick an existing window or create a new one. So labels would be added for each existing window, as well as labels along each border of an existing window, which if selected would create a new window there and return the window id of that new window.

Wrong hl

Hello and thanks for your plugin.
Hl is wrong after v 2.0.1 - focused and unfocused are the same

filter rules not working correctly

I am using window-picker with nvim-tree and noice for a nicer UI. the noice notifications stay at the right side of the screen but they interfere with window-picker(specially when there is just one window). I added the filetype and buffertype to the filter_rules but it seems not to work.

Pass function to filter_rules

Problem:

There are far too many different utility windows created now - some examples include nvim-notify, fidget.nvim, alpha-nvim, nvim-tree, neotree, telescope, various scratchpads and many others. It is hard to keep track of all of them and add them to filter_rules of this plugin.

One solution would be to filter out all buffers with buftype=nofile and buflisted=false. However this falls short for the plugin like alpha-nvim, which has both of this set, however it is quite reasonable to want to open file replacing alpha in a window.

Proposed solution:

Allow users to pass a function that will receive bufnr (or winnr?) and will return true or false that will result in inclusion/exclusion of this window in window picking.

winbar support

Add winbar support for window picker. A nice addition would be to auto use the winbar when the cmdheight is 0.

`include_current_win = false` not working

Using it together with neo-tree.
Installed using lazy:

return {
    's1n7ax/nvim-window-picker',
    name = 'window-picker',
    event = 'VeryLazy',
    version = '2.*',
    opts = {
        hint = "floating-big-letter",
        filter_rules = {
            include_current_win = false,
            autoselect_one = true,
            -- filter using buffer options
            bo = {
                -- if the file type is one of following, the window will be ignored
                filetype = { 'neo-tree', "neo-tree-popup", "notify" },
                -- if the buffer type is one of following, the window will be ignored
                buftype = { 'terminal', "quickfix" },
            }
        },
    }
}

When two splits are open, I get three options:
image

NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1692716794

Treesitter-context gets picked up on

When using treesitter-context, the context part gets picked up as possible windows to switch to. Attempting to switch to any of those windows indeed shows there is an ID (thought it changes every time for some reason)

Picking another window from one without any visible treesitter-context:
no-treesitter-context

Illustration of what I mean with treesitter-context:
window-with-treesitter-context

Picking another window from a window that had visible treesitter-context:
trying-to-pick-from-window-with-treesitter-context

I'm not sure how to filter out those picked up windows :) I've tried with disabling treesitter context, and those rogue window does not show up, so I tried incorporating this in my window picker function, which disables treesitter-context before running window-picker. It looks something like this:

function()
vim.cmd("TSContextDisable")
local picked_window_id = require('window-picker').pick_window()
if vim.fn.win_gettype(picked_window_id) == "unknown" then
goto enablecontext
else
vim.api.nvim_set_current_win(picked_window_id)
goto enablecontext
end
::enablecontext::
vim.cmd("TSContextEnable")
end

But this does not work, which is strange because manually disabling treesitter-context before picking a window works.
I think I need some help :)

Bug when same buffer is opened in two different windows

I encounter an error when I have one buffers opened in two different windows and I try to call the pick_window():

E5108: Error executing lua: /home/xxx/.config/nvim/lua/plugins/nvim-window-picker.lua:31: attempt to concatenate local 'char' (a nil value)
stack traceback:
	/home/xxx/.config/nvim/lua/plugins/nvim-window-picker.lua:31: in function 'selection_display'
	...icker/lua/window-picker/hints/statusline-winbar-hint.lua:79: in function 'draw'
	...indow-picker/lua/window-picker/pickers/window-picker.lua:63: in function 'pick_window'
	/home/xxx/.config/nvim/lua/plugins/telescope.lua:27: in function 'get_selection_window'
	...e/nvim/lazy/telescope.nvim/lua/telescope/actions/set.lua:174: in function 'run_replace_or_original'
	...re/nvim/lazy/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'key_func'
	...hare/nvim/lazy/telescope.nvim/lua/telescope/mappings.lua:257: in function <...hare/nvim/lazy/telescope.nvim/lua/telescope/mappings.lua:256>

Question: switching windows

Just to clarify: this plugin only provides the window ID for further processing, it's not meant to make the selected window the active one, right? I use hop extensively and would love to have a window picker to jump between splits without thinking.

Setting `fg_color` has no effect

The following config should set the text colour but does not:

local status, picker = pcall(require, "window-picker")
if (not status) then return end

picker.setup {
    include_current_win = true,
    selection_chars = "1234567890",
    fg_color = "#1e1e28", -- text
    current_win_hl_color = "#f9c096", -- current window colour
    other_win_hl_color = "#a4b9ef", -- all other windows colour
}

vim.keymap.set("n", "<leader>w", function()
    local picked_window_id = picker.pick_window() or vim.api.nvim_get_current_win()
    vim.api.nvim_set_current_win(picked_window_id)
end, { desc = "Pick a window" })

Instead, it is white:
Screenshot 2022-08-13 at 20 34 13

Feature Request: customizable key assignment order

what

a configuration option specifying something like horizontal_order: right_to_left, vertical_order: down_to_up, assignment_order: horizontal_then_vertical

why

Simple answer: to make visual feedback unnecessary more often, to make more actions doable by muscle memory.

I want, when doing a split, for the bottom-most window to keep its shortcut key. I am most frequently visiting bottom-most windows, and upper windows are more supplementary/temporary, so I would prefer for the bottom-most windows to keep the same keys, so that I can visit them by muscle-memory.

Currently, with top-down naming, creating a new split in one column or the other, makes the bottom-most window's shortcut key change.

Additionally, currently, after creating a new split in the leftmost column, the bottom-most column of the right column will be renamed. I would prefer that bottom-most windows not be renamed due to creating upper windows.

more

If it's not too difficult, it would be better, I think, if creating a row in left column did not rename items in right column, and vice-versa. I generally only have a left and right vertical split, and I would prefer if splitting these horizontally didn't really interfere with each other's shortcut assignment.

I never have more than 2 vertical columns (except that some h-split might be further-split vertically - but these are not root-level vertical columns). All of this might differently be described as "give 2 vertical columns their own namespace, with their own designated shortcut keys, and allow for down_to_up naming order".

Incompatible with Neovim <v0.9

It would be a good idea to add compatibility with Neovim <0.9. Currently there is use of vim.api.nvim_get_hl in various places which was introduced in v0.9. It would be a good idea to abstract this to a utility to get the highlight that will use vim.api.nvim_get_hl if it's available and if not, then use the deprecated function vim.api.nvim_get_hl_by_name. Here is a reference function that AstroNvim uses that could help make the addition of this easy: https://github.com/AstroNvim/AstroNvim/blob/main/lua/astronvim/utils/init.lua#L109-L131

I can try to get around to making a PR later this week as well to resolve this.

use_winbar broken after default is set to false

Hey, just a heads up that I'm pretty sure the use_winbar feature was broken when you made the default false. When you do the table merge, if you merge a table with use_winbar = nil that is treated as the value not being set and will not change the default false to nil. As it is now, it is impossible to set use_winbar to nil

Add option to disable the Pick window prompt

I use winbar for barbecue, and don't want to use it for window indicators. And I don't want to change cmdheight for seeing message Pick window:. It would be perfect to have option use_cmd set by default to true, that can override this behavior.

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.