diff --git a/init.lua b/init.lua index b98ffc61..28db289d 100644 --- a/init.lua +++ b/init.lua @@ -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 @@ -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()` @@ -184,6 +190,9 @@ vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagn -- or just use to exit terminal mode vim.keymap.set('t', '', '', { desc = 'Exit terminal mode' }) +-- Close current buffer +vim.keymap.set('n', 'Q', ':bd', { desc = 'Close current buffer' }) + -- TIP: Disable arrow keys in normal mode -- vim.keymap.set('n', '', 'echo "Use h to move!!"') -- vim.keymap.set('n', '', 'echo "Use l to move!!"') @@ -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 ':p:h' + if vim.fn.isdirectory(dir) == 0 then + vim.fn.mkdir(dir, 'p') + end end, }) @@ -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, + }, }, },