From c3874283b5b441f6af19c1a0f74db6587a3a9aa8 Mon Sep 17 00:00:00 2001 From: xiaojianzheng <1272209235@qq.com> Date: Mon, 8 Jul 2024 11:16:49 +0800 Subject: [PATCH 1/2] Update recipes.md Automatically returns to the dashboard when the buffer is empty --- docs/configuration/recipes.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/configuration/recipes.md b/docs/configuration/recipes.md index 80cceca79..514c00bf7 100644 --- a/docs/configuration/recipes.md +++ b/docs/configuration/recipes.md @@ -160,4 +160,25 @@ Important: make sure not to add prettier to null-ls, otherwise this won't work! } ``` +## Automatically returns to `Dashboard` + +Automatically returns to the dashboard when the buffer is empty. + +Add the below to your `lua/config/autocmds.lua` file + +```lua +vim.api.nvim_create_autocmd("BufDelete", { + group = augroup("dashboard_on_empty", { clear = true }), + callback = function(args) + local deleted_name = vim.api.nvim_buf_get_name(args.buf) + local deleted_ft = vim.api.nvim_get_option_value("filetype", { buf = args.buf }) + local dashboard_on_empty = (deleted_name == "" and deleted_ft == "") + or (vim.api.nvim_buf_get_name(0) == "" and vim.api.nvim_get_option_value("filetype", { buf = 0 }) == "") + if dashboard_on_empty then + vim.cmd("Dashboard") + end + end, +}) +``` + From 8942ce723b68904d23266a190f87061520aae4a4 Mon Sep 17 00:00:00 2001 From: xiaojianzheng <1272209235@qq.com> Date: Mon, 8 Jul 2024 11:19:17 +0800 Subject: [PATCH 2/2] Update recipes.md --- docs/configuration/recipes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration/recipes.md b/docs/configuration/recipes.md index 514c00bf7..faf20761a 100644 --- a/docs/configuration/recipes.md +++ b/docs/configuration/recipes.md @@ -168,7 +168,7 @@ Add the below to your `lua/config/autocmds.lua` file ```lua vim.api.nvim_create_autocmd("BufDelete", { - group = augroup("dashboard_on_empty", { clear = true }), + group = vim.api.nvim_create_augroup("dashboard_on_empty", { clear = true }), callback = function(args) local deleted_name = vim.api.nvim_buf_get_name(args.buf) local deleted_ft = vim.api.nvim_get_option_value("filetype", { buf = args.buf })