Skip to content

Commit 63f9087

Browse files
MN-nagyoriori1703
authored andcommitted
Added blink.cmp buffer completions for markdown/text + some useful options/autocommands
1 parent 7e60b75 commit 63f9087

1 file changed

Lines changed: 60 additions & 2 deletions

File tree

init.lua

Lines changed: 60 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

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

209+
-- Close current buffer
210+
vim.keymap.set('n', '<leader>Q', ':bd<CR>', { desc = 'Close current buffer' })
211+
200212
-- TIP: Disable arrow keys in normal mode
201213
-- vim.keymap.set('n', '<left>', '<cmd>echo "Use h to move!!"<CR>')
202214
-- vim.keymap.set('n', '<right>', '<cmd>echo "Use l to move!!"<CR>')
@@ -227,9 +239,41 @@ vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper win
227239
vim.api.nvim_create_autocmd('TextYankPost', {
228240
desc = 'Highlight when yanking (copying) text',
229241
group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
230-
callback = function() vim.hl.on_yank() end,
242+
callback = function() vim.hl.on_yank { timeout = 200 } end,
243+
})
244+
245+
-- Restore cursor position on file open
246+
vim.api.nvim_create_autocmd('BufReadPost', {
247+
desc = 'Restore cursor position on file open',
248+
group = vim.api.nvim_create_augroup('kickstart-restore-cursor', { clear = true }),
249+
pattern = '*',
250+
callback = function()
251+
local line = vim.fn.line '\'"'
252+
if line > 1 and line <= vim.fn.line '$' then vim.cmd 'normal! g\'"' end
253+
end,
231254
})
232255

256+
-- auto-create missing dirs when saving a file
257+
vim.api.nvim_create_autocmd('BufWritePre', {
258+
desc = 'Auto-create missing dirs when saving a file',
259+
group = vim.api.nvim_create_augroup('kickstart-auto-create-dir', { clear = true }),
260+
pattern = '*',
261+
callback = function()
262+
local dir = vim.fn.expand '<afile>:p:h'
263+
if vim.fn.isdirectory(dir) == 0 then vim.fn.mkdir(dir, 'p') end
264+
end,
265+
})
266+
267+
-- disable automatic comment on newline
268+
-- vim.api.nvim_create_autocmd('FileType', {
269+
-- desc = 'Disable automatic comment on newline',
270+
-- group = vim.api.nvim_create_augroup('kickstart-disable-auto-comment', { clear = true }),
271+
-- pattern = '*',
272+
-- callback = function()
273+
-- vim.opt_local.formatoptions:remove { 'c', 'r', 'o' }
274+
-- end,
275+
-- })
276+
233277
-- [[ Install `lazy.nvim` plugin manager ]]
234278
-- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
235279
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
@@ -838,7 +882,21 @@ require('lazy').setup({
838882
},
839883

840884
sources = {
841-
default = { 'lsp', 'path', 'snippets' },
885+
default = { 'lsp', 'path', 'snippets', 'buffer' },
886+
providers = {
887+
buffer = {
888+
score_offset = -1,
889+
filter = function(buffer)
890+
-- Filetypes for which buffer completions are enabled; add filetypes to extend
891+
local enabled_filetypes = {
892+
'markdown',
893+
'text',
894+
}
895+
local filetype = vim.bo[buffer].filetype
896+
return vim.tbl_contains(enabled_filetypes, filetype)
897+
end,
898+
},
899+
},
842900
},
843901

844902
snippets = { preset = 'luasnip' },

0 commit comments

Comments
 (0)