Skip to content

Commit bb095fa

Browse files
committed
feat(options): add comfortable zero cmdheight
Sometimes the output of the commands are desired to be seen for a short period of time, so is during a search. I set the cmdheight to 1 for a short period of time and set it back to zero. This also gives a nicer effect.
1 parent 5738d35 commit bb095fa

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

lua/autocmd.lua

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,75 @@ async_load_plugin = vim.loop.new_async(vim.schedule_wrap(function()
320320
end))
321321
async_load_plugin:send() --}}}
322322

323+
-- CMD height hacks {{{
324+
local cmdheight_hacks_group = vim.api.nvim_create_augroup("CMDHEIGHT_HACKS", { clear = true })
325+
-- cmdline_calls is used to prevent setting cmdheight to 0 on fast command
326+
-- invokations.
327+
local cmdline_calls = -1
328+
329+
vim.api.nvim_create_autocmd("ModeChanged", {
330+
pattern = "*:[vV\\x16]",
331+
group = cmdheight_hacks_group,
332+
callback = function()
333+
cmdline_calls = cmdline_calls + 1
334+
vim.opt.cmdheight = 1
335+
end,
336+
desc = "increase cmdheight when entering visual mode",
337+
})
338+
339+
vim.api.nvim_create_autocmd("ModeChanged", {
340+
group = cmdheight_hacks_group,
341+
pattern = "[vV\\x16]:*",
342+
callback = function()
343+
cmdline_calls = cmdline_calls - 1
344+
vim.opt.cmdheight = 0
345+
end,
346+
desc = "decrease cmdheight when exiting visual mode",
347+
})
348+
349+
vim.api.nvim_create_autocmd("RecordingEnter", {
350+
group = cmdheight_hacks_group,
351+
callback = function()
352+
cmdline_calls = cmdline_calls + 1
353+
vim.opt.cmdheight = 1
354+
end,
355+
desc = "increase cmdheight when entering macro recording",
356+
})
357+
358+
vim.api.nvim_create_autocmd("RecordingLeave", {
359+
group = cmdheight_hacks_group,
360+
callback = function()
361+
cmdline_calls = cmdline_calls - 1
362+
vim.opt.cmdheight = 0
363+
end,
364+
desc = "decrease cmdheight when exiting macro recording",
365+
})
366+
367+
vim.api.nvim_create_autocmd("CmdlineEnter", {
368+
group = cmdheight_hacks_group,
369+
callback = function()
370+
cmdline_calls = cmdline_calls + 1
371+
vim.opt.cmdheight = 1
372+
end,
373+
desc = "increase cmdheight when entering command mode",
374+
})
375+
376+
vim.api.nvim_create_autocmd("CmdlineLeave", {
377+
group = cmdheight_hacks_group,
378+
callback = function()
379+
vim.defer_fn(function()
380+
-- For an unknown reason, it is set to zero. Let's set it to 1 shortly.
381+
vim.opt.cmdheight = 1
382+
end, 5)
383+
vim.defer_fn(function()
384+
cmdline_calls = cmdline_calls - 1
385+
if cmdline_calls == 0 then
386+
vim.opt.cmdheight = 0
387+
end
388+
end, 1000)
389+
end,
390+
desc = "decrease cmdheight when entering command mode after 2 seconds",
391+
})
392+
--}}}
393+
323394
-- vim: fdm=marker fdl=0

lua/options.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ vim.opt.tabstop = 4
99
vim.opt.expandtab = true
1010
vim.opt.wrap = false
1111
vim.opt.pumheight = 20
12+
vim.opt.cmdheight = 0
1213

1314
vim.opt.whichwrap:append("h,l")
1415
vim.opt.linebreak = true -- Wrap lines at convenient points

0 commit comments

Comments
 (0)