Skip to content

Enhance Kickstart.nvim UX with Buffer Completions, Options, and Autocommands #1642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ end)
-- Enable break indent
vim.o.breakindent = true

-- Save undo history
-- Enable undo/redo changes even after closing and reopening a file
vim.o.undofile = true

-- Case-insensitive searching UNLESS \C or one or more capital letters in the search term
Expand Down Expand Up @@ -166,6 +166,12 @@ vim.o.scrolloff = 10
-- See `:help 'confirm'`
vim.o.confirm = true

-- Disable line wrapping
vim.o.wrap = false

-- Highlight max chars per line
-- vim.o.colorcolumn = '120'

-- [[ Basic Keymaps ]]
-- See `:help vim.keymap.set()`

Expand All @@ -184,6 +190,9 @@ vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagn
-- or just use <C-\><C-n> to exit terminal mode
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })

-- Close current buffer
vim.keymap.set('n', '<leader>Q', ':bd<CR>', { desc = 'Close current buffer' })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this is not very useful because <C-w>q (which quits the window instead of the buffer) serves the purpose of closing splits, If I need to actually close buffers I usually use <M-d> inside of Telescope's buffers picker.

What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, I agree that <C-w>q and Telescope's buffer picker are good ways to manage windows and buffers in advanced workflows.

However, since Kickstart.nvim is primarily aimed at users new to Neovim, I think keeping the <leader>Q mapping for :bd is a good idea. as for many beginners, "closing a file" intuitively means closing the buffer, not just the window.


-- TIP: Disable arrow keys in normal mode
-- vim.keymap.set('n', '<left>', '<cmd>echo "Use h to move!!"<CR>')
-- vim.keymap.set('n', '<right>', '<cmd>echo "Use l to move!!"<CR>')
Expand Down Expand Up @@ -215,7 +224,33 @@ vim.api.nvim_create_autocmd('TextYankPost', {
desc = 'Highlight when yanking (copying) text',
group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
callback = function()
vim.hl.on_yank()
vim.hl.on_yank { timeout = 200 }
end,
})

-- Restore cursor position on file open
vim.api.nvim_create_autocmd('BufReadPost', {
desc = 'Restore cursor position on file open',
group = vim.api.nvim_create_augroup('kickstart-restore-cursor', { clear = true }),
pattern = '*',
callback = function()
local line = vim.fn.line '\'"'
if line > 1 and line <= vim.fn.line '$' then
vim.cmd 'normal! g\'"'
end
end,
})

-- auto-create missing dirs when saving a file
vim.api.nvim_create_autocmd('BufWritePre', {
desc = 'Auto-create missing dirs when saving a file',
group = vim.api.nvim_create_augroup('kickstart-auto-create-dir', { clear = true }),
pattern = '*',
callback = function()
local dir = vim.fn.expand '<afile>:p:h'
if vim.fn.isdirectory(dir) == 0 then
vim.fn.mkdir(dir, 'p')
end
end,
})

Expand Down Expand Up @@ -854,9 +889,22 @@ require('lazy').setup({
},

sources = {
default = { 'lsp', 'path', 'snippets', 'lazydev' },
default = { 'lsp', 'path', 'snippets', 'lazydev', 'buffer' },
providers = {
lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 },
buffer = {
-- Make buffer compeletions appear at the end.
score_offset = -100,
enabled = function()
-- Filetypes for which buffer completions are enabled; add filetypes to extend:
local enabled_filetypes = {
'markdown',
'text',
}
local filetype = vim.bo.filetype
return vim.tbl_contains(enabled_filetypes, filetype)
end,
},
},
},

Expand Down