11# nvim-window-picker
22
3- https://user-images.githubusercontent.com/18459807/161597479-a3d8cf73-3dca-44b1-9eb6-d00b4e6eb842.mp4
3+ ` hint = 'floating-big-letter' `
44
5- This plugins prompts the user to pick a window and returns the window id of the picked window.
6- Part of the code is from [ nvim-tree] ( https://github.com/kyazdani42/nvim-tree.lua ) so shout out to
7- them for coming up with this idea.
5+ ` hint = 'statusline-winbar' `
6+
7+ This plugins prompts the user to pick a window and returns the window id of the
8+ picked window.
89
910## Install
1011
11- #### packer
12+ ### lazy
1213
1314``` lua
14- use {
15+ {
1516 ' s1n7ax/nvim-window-picker' ,
16- tag = ' v1.*' ,
17+ name = ' window-picker' ,
18+ event = ' VeryLazy' ,
19+ version = ' 2.*' ,
1720 config = function ()
1821 require ' window-picker' .setup ()
1922 end ,
2023}
2124```
2225
23- ** Make sure to ` :PackerCompile ` after installing**
24-
25- ## How to use
26+ ### packer
2627
2728``` lua
28- local picked_window_id = require (' window-picker' ).pick_window ()
29+ use {
30+ ' s1n7ax/nvim-window-picker' ,
31+ tag = ' v2.*' ,
32+ config = function ()
33+ require ' window-picker' .setup ()
34+ end ,
35+ }
2936```
3037
31- ** You can put the picked window id to good use** ,
32- for example, set a keymap to switch the current window like this:
38+ ## How to use
3339
3440``` lua
35- vim .keymap .set (" n" , " <leader>w" , function ()
36- local picked_window_id = picker .pick_window () or vim .api .nvim_get_current_win ()
37- vim .api .nvim_set_current_win (picked_window_id )
38- end , { desc = " Pick a window" })
41+ local picked_window_id = require (' window-picker' ).pick_window ()
3942```
4043
44+ You can put the picked window id to good use
45+
4146## Configuration
4247
4348If you want to have custom properties just for one time, you can pass any of
44- following directly to ` pick_window() ` function itself.
49+ following directly to ` pick_window() ` function itself to override the default
50+ behaviour.
4551
4652``` lua
4753require ' window-picker' .setup ({
48- -- when there is only one window available to pick from, use that window
49- -- without prompting the user to select
50- autoselect_one = true ,
51-
52- -- whether you want to include the window you are currently on to window
53- -- selection or not
54- include_current_win = false ,
54+ -- type of hints you want to get
55+ -- following types are supported
56+ -- 'statusline-winbar' | 'floating-big-letter'
57+ -- 'statusline-winbar' draw on 'statusline' if possible, if not 'winbar' will be
58+ -- 'floating-big-letter' draw big letter on a floating window
59+ -- used
60+ hint = ' statusline-winbar ' ,
5561
5662 -- when you go to window selection mode, status bar will show one of
5763 -- following letters on them so you can use that letter to select the window
5864 selection_chars = ' FJDKSLA;CMRUEIWOQP' ,
5965
60- -- whether you want to use winbar instead of the statusline
61- -- "always" means to always use winbar,
62- -- "never" means to never use winbar
63- -- "smart" means to use winbar if cmdheight=0 and statusline if cmdheight > 0
64- use_winbar = ' never' , -- "always" | "never" | "smart"
66+ -- This section contains picker specific configurations
67+ picker_config = {
68+ statusline_winbar_picker = {
69+ -- You can change the display string in status bar.
70+ -- It supports '%' printf style. Such as `return char .. ': %f'` to display
71+ -- buffer file path. See :h 'stl' for details.
72+ selection_display = function (char , windowid )
73+ return ' %=' .. char .. ' %='
74+ end ,
75+
76+ -- whether you want to use winbar instead of the statusline
77+ -- "always" means to always use winbar,
78+ -- "never" means to never use winbar
79+ -- "smart" means to use winbar if cmdheight=0 and statusline if cmdheight > 0
80+ use_winbar = ' never' , -- "always" | "never" | "smart"
81+ },
82+
83+ floating_big_letter = {
84+ -- window picker plugin provides bunch of big letter fonts
85+ -- fonts will be lazy loaded as they are being requested
86+ -- additionally, user can pass in a table of fonts in to font
87+ -- property to use instead
88+
89+ font = ' ansi-shadow' , -- ansi-shadow |
90+ },
91+ },
6592
6693 -- whether to show 'Pick window:' prompt
6794 show_prompt = true ,
6895
96+ -- prompt message to show to get the user input
97+ prompt_message = ' Pick window: ' ,
98+
6999 -- if you want to manually filter out the windows, pass in a function that
70- -- takes two parameters. you should return window ids that should be
100+ -- takes two parameters. You should return window ids that should be
71101 -- included in the selection
72102 -- EX:-
73103 -- function(window_ids, filters)
74- -- -- filter the window_ids
104+ -- -- folder the window_ids
75105 -- -- return only the ones you want to include
76106 -- return {1000, 1001}
77107 -- end
78108 filter_func = nil ,
79109
80110 -- following filters are only applied when you are using the default filter
81- -- defined by this plugin. if you pass in a function to "filter_func"
111+ -- defined by this plugin. If you pass in a function to "filter_func"
82112 -- property, you are on your own
83113 filter_rules = {
114+ -- when there is only one window available to pick from, use that window
115+ -- without prompting the user to select
116+ autoselect_one = true ,
117+
118+ -- whether you want to include the window you are currently on to window
119+ -- selection or not
120+ include_current_win = false ,
121+
84122 -- filter using buffer options
85123 bo = {
86124 -- if the file type is one of following, the window will be ignored
87- filetype = { ' NvimTree' , " neo-tree" , " notify" },
125+ filetype = { ' NvimTree' , ' neo-tree' , ' notify' },
88126
89- -- if the buffer type is one of following, the window will be ignored
127+ -- if the file type is one of following, the window will be ignored
90128 buftype = { ' terminal' },
91129 },
92130
@@ -102,32 +140,48 @@ require 'window-picker'.setup({
102140 file_name_contains = {},
103141 },
104142
105- -- the foreground (text) color of the picker
106- fg_color = ' #ededed' ,
107-
108- -- if you have include_current_win == true, then current_win_hl_color will
109- -- be highlighted using this background color
110- current_win_hl_color = ' #e35e4f' ,
111-
112- -- all the windows except the curren window will be highlighted using this
113- -- color
114- other_win_hl_color = ' #44cc41' ,
115-
116- -- You can change the display string in status bar.
117- -- It supports '%' printf style. Such as `return char .. ': %f'` to display
118- -- buffer filepath. See :h 'stl' for details.
119- selection_display = function (char ) return char end ,
143+ -- You can pass in the highlight name or a table of content to set as
144+ -- highlight
145+ highlights = {
146+ statusline = {
147+ focused = {
148+ fg = ' #ededed' ,
149+ bg = ' #e35e4f' ,
150+ bold = true ,
151+ },
152+ unfocused = {
153+ fg = ' #ededed' ,
154+ bg = ' #44cc41' ,
155+ bold = true ,
156+ },
157+ },
158+ winbar = {
159+ focused = {
160+ fg = ' #ededed' ,
161+ bg = ' #e35e4f' ,
162+ bold = true ,
163+ },
164+ unfocused = {
165+ fg = ' #ededed' ,
166+ bg = ' #44cc41' ,
167+ bold = true ,
168+ },
169+ },
170+ },
120171})
121172```
122173
123174``` lua
124- require (package_name ).pick_window ({
125- include_current_win = true ,
126- selection_chars = ' 123345' ,
127- filter_rules = {
128- bo = {
129- filetype = {' markdown' }
130- }
131- },
175+ require (' window-picker' ).pick_window ({
176+ hint = ' floating-big-letter'
132177})
133178```
179+
180+ ## Breaking changes in v2.0.0
181+
182+ _ Before_ : return value from ` selection_display ` will be wrapped by ` '%=' ` and
183+ ` '%=' ` to fill the empty space of status line or winbar.
184+
185+ _ After_ : return value of ` selection_display ` will be passed directly to the
186+ status line or winbar. This allows all the customizations available from
187+ statusline syntax. You can check ` :help statusline ` for more info.
0 commit comments