Skip to content

Commit

Permalink
docs(files): add example for customizing window height and/or title
Browse files Browse the repository at this point in the history
Related to #1140 and #1062.
  • Loading branch information
echasnovski committed Aug 12, 2024
1 parent 15684f0 commit 64a560f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
28 changes: 26 additions & 2 deletions doc/mini-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ Use a combination of |MiniFiles.open()| and |MiniFiles.close()|: >lua
<
# Customize windows ~

Create an autocommand for `MiniFilesWindowOpen` event: >lua
For most of the common customizations using `MiniFilesWindowOpen` event
autocommand is the suggested approach: >lua

vim.api.nvim_create_autocmd('User', {
pattern = 'MiniFilesWindowOpen',
Expand All @@ -386,9 +387,32 @@ Create an autocommand for `MiniFilesWindowOpen` event: >lua
end,
})
<
However, some parts (like window title and height) of window config are later
updated internally. Use `MiniFilesWindowUpdate` event for them: >lua

vim.api.nvim_create_autocmd('User', {
pattern = 'MiniFilesWindowUpdate',
callback = function(args)
local config = vim.api.nvim_win_get_config(args.data.win_id)

-- Ensure fixed height
config.height = 10

-- Ensure title padding
if config.title[#config.title][1] ~= ' ' then
table.insert(config.title, { ' ', 'NormalFloat' })
end
if config.title[1][1] ~= ' ' then
table.insert(config.title, 1, { ' ', 'NormalFloat' })
end

vim.api.nvim_win_set_config(args.data.win_id, config)
end,
})
<
# Customize icons ~

Use different directory icon: >lua
Use different directory icon (if you don't use |mini.icons|): >lua

local my_prefix = function(fs_entry)
if fs_entry.fs_type == 'directory' then
Expand Down
28 changes: 26 additions & 2 deletions lua/mini/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@
--- <
--- # Customize windows ~
---
--- Create an autocommand for `MiniFilesWindowOpen` event: >lua
--- For most of the common customizations using `MiniFilesWindowOpen` event
--- autocommand is the suggested approach: >lua
---
--- vim.api.nvim_create_autocmd('User', {
--- pattern = 'MiniFilesWindowOpen',
Expand All @@ -381,9 +382,32 @@
--- end,
--- })
--- <
--- However, some parts (like window title and height) of window config are later
--- updated internally. Use `MiniFilesWindowUpdate` event for them: >lua
---
--- vim.api.nvim_create_autocmd('User', {
--- pattern = 'MiniFilesWindowUpdate',
--- callback = function(args)
--- local config = vim.api.nvim_win_get_config(args.data.win_id)
---
--- -- Ensure fixed height
--- config.height = 10
---
--- -- Ensure title padding
--- if config.title[#config.title][1] ~= ' ' then
--- table.insert(config.title, { ' ', 'NormalFloat' })
--- end
--- if config.title[1][1] ~= ' ' then
--- table.insert(config.title, 1, { ' ', 'NormalFloat' })
--- end
---
--- vim.api.nvim_win_set_config(args.data.win_id, config)
--- end,
--- })
--- <
--- # Customize icons ~
---
--- Use different directory icon: >lua
--- Use different directory icon (if you don't use |mini.icons|): >lua
---
--- local my_prefix = function(fs_entry)
--- if fs_entry.fs_type == 'directory' then
Expand Down

0 comments on commit 64a560f

Please sign in to comment.