Skip to content

Commit a830a13

Browse files
MN-nagyoriori1703
authored andcommitted
Added blink.cmp buffer completions for markdown/text + some useful options/autocommands
1 parent 8475ce9 commit a830a13

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

init.lua

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ vim.o.scrolloff = 10
164164
-- See `:help 'confirm'`
165165
vim.o.confirm = true
166166

167+
-- Enable undo/redo changes even after closing and reopening a file
168+
vim.opt.undofile = true
169+
170+
-- Enable smooth scrolling
171+
vim.opt.smoothscroll = true
172+
173+
-- Highlight max chars per line
174+
-- vim.opt.colorcolumn = '100'
175+
167176
-- [[ Basic Keymaps ]]
168177
-- See `:help vim.keymap.set()`
169178

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

194+
-- Close current buffer
195+
vim.keymap.set('n', '<leader>Q', ':bd<CR>', { desc = 'Close current buffer' })
196+
185197
-- TIP: Disable arrow keys in normal mode
186198
-- vim.keymap.set('n', '<left>', '<cmd>echo "Use h to move!!"<CR>')
187199
-- vim.keymap.set('n', '<right>', '<cmd>echo "Use l to move!!"<CR>')
@@ -212,9 +224,45 @@ vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper win
212224
vim.api.nvim_create_autocmd('TextYankPost', {
213225
desc = 'Highlight when yanking (copying) text',
214226
group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
215-
callback = function() vim.hl.on_yank() end,
227+
callback = function() vim.hl.on_yank { timeout = 200 } end,
228+
})
229+
230+
-- Restore cursor position on file open
231+
vim.api.nvim_create_autocmd('BufReadPost', {
232+
desc = 'Restore cursor position on file open',
233+
group = vim.api.nvim_create_augroup('kickstart-restore-cursor', { clear = true }),
234+
pattern = '*',
235+
callback = function()
236+
local line = vim.fn.line '\'"'
237+
if line > 1 and line <= vim.fn.line '$' then
238+
vim.cmd 'normal! g\'"'
239+
end
240+
end,
241+
})
242+
243+
-- auto-create missing dirs when saving a file
244+
vim.api.nvim_create_autocmd('BufWritePre', {
245+
desc = 'Auto-create missing dirs when saving a file',
246+
group = vim.api.nvim_create_augroup('kickstart-auto-create-dir', { clear = true }),
247+
pattern = '*',
248+
callback = function()
249+
local dir = vim.fn.expand '<afile>:p:h'
250+
if vim.fn.isdirectory(dir) == 0 then
251+
vim.fn.mkdir(dir, 'p')
252+
end
253+
end,
216254
})
217255

256+
-- disable automatic comment on newline
257+
-- vim.api.nvim_create_autocmd('FileType', {
258+
-- desc = 'Disable automatic comment on newline',
259+
-- group = vim.api.nvim_create_augroup('kickstart-disable-auto-comment', { clear = true }),
260+
-- pattern = '*',
261+
-- callback = function()
262+
-- vim.opt_local.formatoptions:remove { 'c', 'r', 'o' }
263+
-- end,
264+
-- })
265+
218266
-- [[ Install `lazy.nvim` plugin manager ]]
219267
-- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
220268
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
@@ -878,9 +926,21 @@ require('lazy').setup({
878926
},
879927

880928
sources = {
881-
default = { 'lsp', 'path', 'snippets', 'lazydev' },
929+
default = { 'lsp', 'path', 'snippets', 'lazydev', 'buffer' },
882930
providers = {
883931
lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 },
932+
buffer = {
933+
score_offset = -1,
934+
filter = function(buffer)
935+
-- Filetypes for which buffer completions are enabled; add filetypes to extend
936+
local enabled_filetypes = {
937+
'markdown',
938+
'text',
939+
}
940+
local filetype = vim.bo[buffer].filetype
941+
return vim.tbl_contains(enabled_filetypes, filetype)
942+
end,
943+
},
884944
-- On WSL2, blink.cmp may cause the editor to freeze due to a known limitation.
885945
-- To address this issue, uncomment the following configuration:
886946
-- cmdline = {

0 commit comments

Comments
 (0)