125 lines
4.8 KiB
Lua
125 lines
4.8 KiB
Lua
-- SECTION: Options
|
|
vim.o.number = true -- Show line numbers
|
|
vim.o.wrap = true -- Soft-wrap lines
|
|
vim.o.tabstop = 2 -- 2 space tab width
|
|
vim.o.shiftwidth = 2 -- 2 space tab width
|
|
vim.o.swapfile = false -- Disable swap files (annoying)
|
|
vim.o.undofile = true -- Enable undo between sessions
|
|
vim.o.mouse = 'a' -- Enable mouse support
|
|
vim.o.showmode = false -- Don't show mode in status bar
|
|
vim.o.inccommand = 'split' -- Preview replace commands inline
|
|
vim.o.scrolloff = 20 -- Scroll if cursor is X lines to edge
|
|
vim.o.confirm = true -- Add confirmation on some destructive actions
|
|
vim.o.ignorecase = true -- Case insensitive search
|
|
vim.o.smartcase = true -- Case sensitive when caps is used
|
|
vim.o.cursorline = true -- Highlight current line
|
|
vim.opt.signcolumn =
|
|
'yes' -- TEST: Prohibit layout shifting by always showing the sign column (left of line numbers), you should see an icon there on this row.
|
|
|
|
-- SECTION: Globals
|
|
vim.g.mapleader = ' ' -- Mapping leader to space.
|
|
vim.g.maplocalleader = ' ' -- Mapping leader to space.
|
|
vim.g.have_nerd_font = true -- Enable nerd font
|
|
|
|
-- SECTION: Lazy settings
|
|
-- INFO: Lines in this function will be executed after main event loop is free, prohibiting startup lag.
|
|
vim.schedule(function()
|
|
vim.opt.clipboard = 'unnamedplus' -- Share clipboard with system, comment if you want to keep it separate.
|
|
end)
|
|
|
|
-- SECTION: Keybinds
|
|
|
|
-- Source current file, helpful when editing this file.
|
|
vim.keymap.set('n', '<leader>o', ':update<CR> :source<CR>')
|
|
|
|
-- Restart vim completely, you can then press CTRL + o to go back to the last file you had open.
|
|
vim.keymap.set('n', '<leader>r', ':restart<CR>')
|
|
|
|
-- Lets you use ESC to stop highlighting text that you have searched with '/'
|
|
vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
|
|
|
|
-- Lets you move focus from the current window to another.
|
|
vim.keymap.set('n', '<C-h>', '<C-w><C-h>', { desc = 'Move focus to the left window' })
|
|
vim.keymap.set('n', '<C-l>', '<C-w><C-l>', { desc = 'Move focus to the right window' })
|
|
vim.keymap.set('n', '<C-j>', '<C-w><C-j>', { desc = 'Move focus to the lower window' })
|
|
vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper window' })
|
|
|
|
-- Format the current buffer using the active lsp
|
|
vim.keymap.set('n', '<leader>f', vim.lsp.buf.format, { desc = "Format buffer" })
|
|
|
|
-- Start the file picker in different modes
|
|
vim.keymap.set('n', '<leader>sf', ":Pick files<CR>", { desc = "Search files" })
|
|
vim.keymap.set('n', '<leader>sg', ":Pick grep_live<CR>", { desc = "Search files" })
|
|
|
|
-- SECTION: Install packages
|
|
vim.pack.add({
|
|
'https://github.com/catppuccin/nvim', -- color scheme
|
|
'https://github.com/nvim-mini/mini.pick', -- File picker, grep
|
|
'https://github.com/nvim-mini/mini.pairs', -- Auto create {}, (), [] - pairs etc.
|
|
'https://github.com/nvim-mini/mini.notify', -- Popup notifications
|
|
'https://github.com/neovim/nvim-lspconfig', -- Language servers
|
|
'https://github.com/mason-org/mason.nvim', -- LSP deps installer
|
|
'https://github.com/folke/lazydev.nvim', -- Automatically resolve vim api paths.
|
|
'https://github.com/folke/which-key.nvim', -- Shortcut hints (bar at the bottom when pressing space)
|
|
'https://github.com/nvim-lua/plenary.nvim', -- Helper lua functions, dep of todo-comments.
|
|
'https://github.com/folke/todo-comments.nvim' -- Helper lua functions, dep of todo-comments.
|
|
})
|
|
|
|
-- SECTION: Colorscheme
|
|
vim.cmd("colorscheme catppuccin-mocha")
|
|
|
|
-- SECTION: General plugin setup
|
|
|
|
-- Folke
|
|
require("lazydev").setup()
|
|
require('which-key').setup()
|
|
require('todo-comments').setup({
|
|
keywords = {
|
|
SECTION = {
|
|
icon = " ",
|
|
color = "hint",
|
|
}
|
|
}
|
|
})
|
|
|
|
-- Mini
|
|
require('mini.pick').setup()
|
|
require('mini.pairs').setup()
|
|
require('mini.notify').setup()
|
|
|
|
-- LSP Language Server
|
|
require("mason").setup({
|
|
ensure_installed = {
|
|
'lua-language-server',
|
|
}
|
|
})
|
|
vim.lsp.config('lua_ls', {})
|
|
vim.lsp.enable('lua_ls')
|
|
|
|
-- SECTION: Autocommands
|
|
vim.api.nvim_create_autocmd('TextYankPost', {
|
|
desc = 'Highlight when yanking (copying) text',
|
|
group = vim.api.nvim_create_augroup('highlight-yank', { clear = true }),
|
|
callback = function()
|
|
vim.highlight.on_yank()
|
|
end,
|
|
})
|
|
|
|
-- Autoformat on save
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
group = vim.api.nvim_create_augroup('my.lsp', {}),
|
|
callback = function(ev)
|
|
local client = assert(vim.lsp.get_client_by_id(ev.data.client_id))
|
|
if not client:supports_method('textDocument/willSaveWaitUntil')
|
|
and client:supports_method('textDocument/formatting') then
|
|
vim.api.nvim_create_autocmd('BufWritePre', {
|
|
group = vim.api.nvim_create_augroup('my.lsp', { clear = false }),
|
|
buffer = ev.buf,
|
|
callback = function()
|
|
vim.lsp.buf.format({ bufnr = ev.buf, id = client.id, timeout_ms = 1000 })
|
|
end,
|
|
})
|
|
end
|
|
end,
|
|
})
|