diff options
Diffstat (limited to '.config/nvim')
| -rw-r--r-- | .config/nvim/init.lua | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua new file mode 100644 index 0000000..289e1cd --- /dev/null +++ b/.config/nvim/init.lua @@ -0,0 +1,157 @@ +------------------------------------------------------------ +-- General settings +------------------------------------------------------------ +vim.opt.number = true +vim.opt.relativenumber = true +vim.opt.title = true +vim.opt.background = "dark" +vim.opt.laststatus = 2 +vim.opt.showmode = true +vim.opt.showcmd = false +vim.opt.ruler = true + +------------------------------------------------------------ +-- Search and highlighting +------------------------------------------------------------ +vim.opt.hlsearch = false +vim.opt.ignorecase = true +vim.opt.smartcase = true +vim.opt.incsearch = true +vim.opt.wildignore = { "*.o", "*.obj", "*.bak", "*.exe" } + +------------------------------------------------------------ +-- Indentation and formatting +------------------------------------------------------------ +vim.opt.autoindent = true +vim.opt.cindent = true +vim.opt.smartindent = true +vim.opt.wrap = false +vim.opt.scrolloff = 5 +vim.opt.completeopt = { "menuone", "noinsert" } + +------------------------------------------------------------ +-- Clipboard and mouse +------------------------------------------------------------ +vim.opt.clipboard:append("unnamedplus") +vim.opt.mouse = "a" + +------------------------------------------------------------ +-- Session and history +------------------------------------------------------------ +vim.opt.shada = "'100,<50,s10,h" +vim.opt.shadafile = vim.fn.expand("~/.local/state/nvim/shada/main.shada") + +------------------------------------------------------------ +-- Miscellaneous +------------------------------------------------------------ +vim.opt.spelllang = { "en", "pl" } +vim.cmd("colorscheme pablo") +vim.cmd("syntax on") + +-- Transparent background +vim.api.nvim_set_hl(0, "Normal", { bg = "none" }) +vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" }) + +------------------------------------------------------------ +-- Autocommands +------------------------------------------------------------ +local augroup = vim.api.nvim_create_augroup("UserAutocmds", { clear = true }) + +-- Reload any .lua file on save +vim.api.nvim_create_autocmd("BufWritePost", { + group = augroup, + pattern = vim.fn.stdpath("config") .. "/**/*.lua", + callback = function() + vim.cmd("source %") + vim.notify("Lua config reloaded", vim.log.levels.INFO) + end, +}) + +-- Remove trailing whitespace & final newlines, keep cursor +vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + pattern = "*", + callback = function() + local pos = vim.fn.getpos(".") + vim.cmd([[%s/\s\+$//e]]) + vim.cmd([[%s/\n\+\%$//e]]) + vim.fn.setpos(".", pos) + end, +}) + +vim.api.nvim_create_autocmd("BufWritePost", { + pattern = "*.tex", + callback = function() + -- Run tex-fmt on the current file + vim.cmd("silent !tex-fmt %") + -- Reload the buffer to reflect formatting changes + vim.cmd("edit!") + end, +}) + +------------------------------------------------------------ +-- Key mappings +------------------------------------------------------------ +local map = vim.keymap.set +local opts = { noremap = true, silent = true } + +vim.g.mapleader = "\\" + +map("n", "<BS>", "dBx", { noremap = true }) +map("n", "s", "o<Esc>kzz", { noremap = true }) +map("n", "S", ":%s//g<Left><Left>", { noremap = true }) +map("n", "Y", "y$", { noremap = true }) +map("n", "-", "ddp", { noremap = true }) +map("n", "_", "ddkP", { noremap = true }) +map("n", "<C-J>", '"+yy', { noremap = true }) +map("n", "<C-C>", '"+yW', { noremap = true }) +map("n", "<C-K>", '"+p', { noremap = true }) +map("n", "<space>", "i <esc>", { noremap = true }) +map("v", "<C-J>", '"+y', { noremap = true }) + +------------------------------------------------------------ +-- Tabs & indentation +------------------------------------------------------------ +vim.opt.tabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = true + +------------------------------------------------------------ +-- Filetype-specific mappings +------------------------------------------------------------ +vim.api.nvim_create_autocmd("FileType", { + group = augroup, + pattern = "python", + command = "map <F5> :w<CR>:!python3 %<CR>", +}) + +------------------------------------------------------------ +-- lazy.nvim +------------------------------------------------------------ +require("config.lazy") + + +------------------------------------------------------------ +-- luasnip +------------------------------------------------------------ +require("luasnip").config.set_config({ -- Setting LuaSnip config + + -- Enable autotriggered snippets + enable_autosnippets = true, + + -- Use Tab (or some other key if you prefer) to trigger visual selection + store_selection_keys = "<Tab>", +}) + +vim.cmd[[ +" Use Tab to expand and jump through snippets +imap <silent><expr> <Tab> luasnip#expand_or_jumpable() ? '<Plug>luasnip-expand-or-jump' : '<Tab>' +smap <silent><expr> <Tab> luasnip#jumpable(1) ? '<Plug>luasnip-jump-next' : '<Tab>' + +" Use Shift-Tab to jump backwards through snippets +imap <silent><expr> <S-Tab> luasnip#jumpable(-1) ? '<Plug>luasnip-jump-prev' : '<S-Tab>' +smap <silent><expr> <S-Tab> luasnip#jumpable(-1) ? '<Plug>luasnip-jump-prev' : '<S-Tab>' +]] + +-- Load snippets from fiadra/chadsnips +require("luasnip.loaders.from_vscode").lazy_load() |
