396 lines
14 KiB
Lua
396 lines
14 KiB
Lua
---@diagnostic disable: undefined-global
|
|
vim.g.mapleader = ' '
|
|
vim.g.maplocalleader = ' '
|
|
vim.opt.cmdheight = 0
|
|
vim.g.have_nerd_font = true
|
|
-- NOTE: You can change these options as you wish!
|
|
-- For more options, you can see `:help option-list`
|
|
vim.opt.number = true
|
|
vim.opt.relativenumber = true
|
|
vim.opt.mouse = 'a'
|
|
vim.opt.showmode = false
|
|
vim.opt.breakindent = true
|
|
vim.opt.undofile = true
|
|
vim.opt.ignorecase = true
|
|
vim.opt.smartcase = true
|
|
vim.opt.signcolumn = 'yes'
|
|
vim.opt.updatetime = 250
|
|
vim.opt.splitright = true
|
|
vim.opt.splitbelow = true
|
|
vim.opt.list = true
|
|
vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' }
|
|
vim.opt.inccommand = 'split'
|
|
vim.opt.cursorline = true
|
|
vim.opt.scrolloff = 10
|
|
vim.g.python3_host_prog = vim.fn.expand '~/.config/nvim/env/neovim-python/bin/python'
|
|
vim.opt.hlsearch = true
|
|
vim.keymap.set('n', '<C-c>', '<cmd>nohlsearch<CR>')
|
|
vim.keymap.set('n', '-', '<CMD>Oil<CR>', { desc = 'Open parent directory' })
|
|
vim.keymap.set('n', '<leader>c', '"+y', { noremap = true, silent = true })
|
|
vim.keymap.set('v', '<leader>y', '"+y', { noremap = true, silent = true })
|
|
vim.keymap.set('n', '<C-d>', 'dd', { noremap = true, silent = true })
|
|
vim.keymap.set('n', ',d', '<cmd>DiffviewOpen<cr>', { desc = 'Repo diff' })
|
|
vim.keymap.set('n', ',hh', '<cmd>DiffviewFileHistory<cr>', { desc = 'Repo history' })
|
|
vim.keymap.set('n', ',hf', '<cmd>DiffviewFileHistory --follow %<cr>', { desc = 'File history' })
|
|
vim.api.nvim_create_autocmd('BufRead', {
|
|
callback = function(opts)
|
|
vim.api.nvim_create_autocmd('BufWinEnter', {
|
|
once = true,
|
|
buffer = opts.buf,
|
|
callback = function()
|
|
local ft = vim.bo[opts.buf].filetype
|
|
local last_known_line = vim.api.nvim_buf_get_mark(opts.buf, '"')[1]
|
|
if not (ft:match 'commit' and ft:match 'rebase') and last_known_line > 1 and last_known_line <= vim.api.nvim_buf_line_count(opts.buf) then
|
|
vim.api.nvim_feedkeys([[g`"]], 'nx', false)
|
|
end
|
|
end,
|
|
})
|
|
end,
|
|
})
|
|
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' })
|
|
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' })
|
|
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' })
|
|
vim.keymap.set('n', '<C-s>', '<cmd>w<CR>', { desc = 'Save' })
|
|
vim.keymap.set('n', '<leader>q', '<cmd>wqa<CR>', { desc = 'Save and Quit' })
|
|
vim.keymap.set('n', '<C-h>', '<cmd>bp<CR>', { desc = 'Prev Buffer' })
|
|
vim.keymap.set('n', '<C-l>', '<cmd>bn<CR>', { desc = 'Next Buffer' })
|
|
vim.keymap.set('n', '<leader>w', '<cmd>write|bdelete<cr>', { desc = 'Save and close' })
|
|
vim.keymap.set('n', ']n', ':cnext<CR>', { noremap = true, silent = true })
|
|
vim.keymap.set('n', '[n', ':cprev<CR>', { noremap = true, silent = true })
|
|
vim.keymap.set('v', '<C-k>', ":m '<-2<CR>gv=gv", { noremap = true, silent = true })
|
|
vim.keymap.set('v', '<C-j>', ":m '>+1<CR>gv=gv", { noremap = true, silent = true })
|
|
vim.keymap.set('n', '<C-k>', ':m -2<CR>', { noremap = true, silent = true })
|
|
vim.keymap.set('n', '<C-j>', ':m +1<CR>', { noremap = true, silent = true })
|
|
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
|
|
vim.keymap.set('n', '<leader>v', '<cmd>e ~/.config/nvim/init.lua<cr>', { desc = 'open init.lua' })
|
|
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.highlight.on_yank()
|
|
end,
|
|
})
|
|
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
|
|
if not vim.loop.fs_stat(lazypath) then
|
|
local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
|
|
vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath }
|
|
end ---@diagnostic disable-next-line: undefined-field
|
|
vim.opt.rtp:prepend(lazypath)
|
|
-- NOTE: Here is where you install your plugins.
|
|
require('lazy').setup({
|
|
-- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link).
|
|
'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically
|
|
'sindrets/diffview.nvim',
|
|
'github/copilot.vim',
|
|
{
|
|
'stevearc/oil.nvim',
|
|
opts = {},
|
|
dependencies = { 'nvim-tree/nvim-web-devicons' },
|
|
},
|
|
{ 'numToStr/Comment.nvim', opts = {} },
|
|
{ -- Adds git related signs to the gutter, as well as utilities for managing changes
|
|
'lewis6991/gitsigns.nvim',
|
|
opts = {
|
|
signs = {
|
|
add = { text = '+' },
|
|
change = { text = '~' },
|
|
delete = { text = '_' },
|
|
topdelete = { text = '‾' },
|
|
changedelete = { text = '~' },
|
|
},
|
|
},
|
|
},
|
|
{ -- Fuzzy Finder (files, lsp, etc)
|
|
'nvim-telescope/telescope.nvim',
|
|
event = 'VimEnter',
|
|
branch = '0.1.x',
|
|
dependencies = {
|
|
'nvim-lua/plenary.nvim',
|
|
{ -- If encountering errors, see telescope-fzf-native README for installation instructions
|
|
'nvim-telescope/telescope-fzf-native.nvim',
|
|
build = 'make',
|
|
cond = function()
|
|
return vim.fn.executable 'make' == 1
|
|
end,
|
|
},
|
|
{ 'nvim-telescope/telescope-ui-select.nvim' },
|
|
|
|
-- Useful for getting pretty icons, but requires a Nerd Font.
|
|
{ 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font },
|
|
},
|
|
config = function()
|
|
require('telescope').setup {
|
|
extensions = {
|
|
['ui-select'] = {
|
|
require('telescope.themes').get_dropdown(),
|
|
},
|
|
},
|
|
}
|
|
pcall(require('telescope').load_extension, 'fzf')
|
|
pcall(require('telescope').load_extension, 'ui-select')
|
|
local builtin = require 'telescope.builtin'
|
|
vim.keymap.set('n', '<leader>f', builtin.find_files, { desc = '[S]earch [F]iles' })
|
|
vim.keymap.set('n', '<leader>g', builtin.live_grep, { desc = '[S]earch by [G]rep' })
|
|
vim.keymap.set('n', '<leader>d', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' })
|
|
vim.keymap.set('n', '<leader>sr', builtin.resume, { desc = '[S]earch [R]esume' })
|
|
vim.keymap.set('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' })
|
|
end,
|
|
},
|
|
|
|
{
|
|
'neovim/nvim-lspconfig',
|
|
dependencies = {
|
|
{ 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants
|
|
'williamboman/mason-lspconfig.nvim',
|
|
'WhoIsSethDaniel/mason-tool-installer.nvim',
|
|
{ 'j-hui/fidget.nvim', opts = {} },
|
|
{ 'folke/neodev.nvim', opts = {} },
|
|
},
|
|
config = function()
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
|
|
callback = function(event)
|
|
local map = function(keys, func, desc)
|
|
vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
|
|
end
|
|
map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
|
|
map('<leader>r', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
|
|
map('<leader>t', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
|
|
map('<leader>s', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
|
|
map('<leader>n', vim.lsp.buf.rename, 'Re[n]ame')
|
|
map('<leader>a', vim.lsp.buf.code_action, 'Code [A]ction')
|
|
map('K', vim.lsp.buf.hover, 'Hover Documentation')
|
|
local client = vim.lsp.get_client_by_id(event.data.client_id)
|
|
if client and client.server_capabilities.documentHighlightProvider then
|
|
local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false })
|
|
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
|
|
buffer = event.buf,
|
|
group = highlight_augroup,
|
|
callback = vim.lsp.buf.document_highlight,
|
|
})
|
|
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
|
|
buffer = event.buf,
|
|
group = highlight_augroup,
|
|
callback = vim.lsp.buf.clear_references,
|
|
})
|
|
vim.api.nvim_create_autocmd('LspDetach', {
|
|
group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }),
|
|
callback = function(event2)
|
|
vim.lsp.buf.clear_references()
|
|
vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf }
|
|
end,
|
|
})
|
|
end
|
|
if client and client.server_capabilities.inlayHintProvider and vim.lsp.inlay_hint then
|
|
map('<leader>th', function()
|
|
vim.lsp.inlay_hint.enable(false, nil)
|
|
end, '[T]oggle Inlay [H]ints')
|
|
end
|
|
end,
|
|
})
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())
|
|
local servers = {
|
|
pyright = {
|
|
settings = {
|
|
python = {
|
|
analysis = {
|
|
diagnosticSeverityOverrides = {
|
|
reportImplicitStringConcatenation = 'warning',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
ts_ls = {},
|
|
html = {},
|
|
tailwindcss = {},
|
|
css_variables = {},
|
|
lua_ls = {
|
|
settings = {
|
|
Lua = {
|
|
completion = {
|
|
callSnippet = 'Replace',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
require('mason').setup()
|
|
local ensure_installed = vim.tbl_keys(servers or {})
|
|
vim.list_extend(ensure_installed, {
|
|
'stylua', -- Used to format Lua code
|
|
})
|
|
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
|
|
|
|
require('mason-lspconfig').setup {
|
|
handlers = {
|
|
function(server_name)
|
|
local server = servers[server_name] or {}
|
|
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
|
|
require('lspconfig')[server_name].setup(server)
|
|
end,
|
|
},
|
|
}
|
|
end,
|
|
},
|
|
|
|
{ -- Autoformat
|
|
'stevearc/conform.nvim',
|
|
lazy = false,
|
|
opts = {
|
|
notify_on_error = false,
|
|
format_on_save = function(bufnr)
|
|
local disable_filetypes = { c = true, cpp = true, python = true }
|
|
return {
|
|
timeout_ms = 2500,
|
|
lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype],
|
|
}
|
|
end,
|
|
log_level = vim.log.levels.DEBUG,
|
|
formatters = {
|
|
prettier = {
|
|
command = 'prettier',
|
|
args = { '--stdin-filepath', '$FILENAME' },
|
|
stdin = true,
|
|
},
|
|
black = {
|
|
prepend_args = { '--line-length', '120' },
|
|
},
|
|
},
|
|
formatters_by_ft = {
|
|
lua = { 'stylua' },
|
|
javascript = { 'prettierd', 'prettier' },
|
|
typescript = { 'prettierd', 'prettier' },
|
|
typescriptreact = { 'prettierd', 'prettier' },
|
|
python = { 'black' }, -- Add this line for Python formatting
|
|
},
|
|
},
|
|
},
|
|
|
|
{
|
|
'hrsh7th/nvim-cmp',
|
|
event = 'InsertEnter',
|
|
dependencies = {
|
|
{
|
|
'L3MON4D3/LuaSnip',
|
|
build = (function()
|
|
if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then
|
|
return
|
|
end
|
|
return 'make install_jsregexp'
|
|
end)(),
|
|
},
|
|
'saadparwaiz1/cmp_luasnip',
|
|
'hrsh7th/cmp-nvim-lsp',
|
|
'hrsh7th/cmp-path',
|
|
},
|
|
config = function()
|
|
local cmp = require 'cmp'
|
|
local luasnip = require 'luasnip'
|
|
luasnip.config.setup {}
|
|
cmp.setup {
|
|
snippet = {
|
|
expand = function(args)
|
|
luasnip.lsp_expand(args.body)
|
|
end,
|
|
},
|
|
completion = { completeopt = 'menu,menuone,noinsert' },
|
|
mapping = cmp.mapping.preset.insert {
|
|
['<C-n>'] = cmp.mapping.select_next_item(),
|
|
['<C-p>'] = cmp.mapping.select_prev_item(),
|
|
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
|
['<C-y>'] = cmp.mapping.confirm { select = true },
|
|
['<C-Space>'] = cmp.mapping.complete {},
|
|
['<C-l>'] = cmp.mapping(function()
|
|
if luasnip.expand_or_locally_jumpable() then
|
|
luasnip.expand_or_jump()
|
|
end
|
|
end, { 'i', 's' }),
|
|
['<C-h>'] = cmp.mapping(function()
|
|
if luasnip.locally_jumpable(-1) then
|
|
luasnip.jump(-1)
|
|
end
|
|
end, { 'i', 's' }),
|
|
},
|
|
sources = {
|
|
{ name = 'nvim_lsp' },
|
|
{ name = 'luasnip' },
|
|
{ name = 'path' },
|
|
},
|
|
}
|
|
end,
|
|
},
|
|
{
|
|
'catppuccin/nvim',
|
|
priority = 1000,
|
|
init = function()
|
|
vim.cmd.colorscheme 'catppuccin-mocha'
|
|
-- vim.cmd.colorscheme 'catppuccin-latte'
|
|
vim.cmd.hi 'Comment gui=none'
|
|
end,
|
|
},
|
|
{
|
|
'folke/todo-comments.nvim',
|
|
event = 'VimEnter',
|
|
dependencies = { 'nvim-lua/plenary.nvim' },
|
|
opts = { signs = false },
|
|
},
|
|
{
|
|
'echasnovski/mini.nvim',
|
|
config = function()
|
|
require('mini.ai').setup { n_lines = 500 }
|
|
require('mini.surround').setup()
|
|
local statusline = require 'mini.statusline'
|
|
statusline.setup { use_icons = vim.g.have_nerd_font }
|
|
statusline.section_location = function()
|
|
return '%2l:%-2v'
|
|
end
|
|
end,
|
|
},
|
|
{
|
|
'nvim-treesitter/nvim-treesitter',
|
|
build = ':TSUpdate',
|
|
opts = {
|
|
ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'vim', 'vimdoc' },
|
|
auto_install = true,
|
|
highlight = {
|
|
enable = true,
|
|
additional_vim_regex_highlighting = { 'ruby' },
|
|
},
|
|
indent = { enable = true, disable = { 'ruby' } },
|
|
},
|
|
config = function(_, opts)
|
|
require('nvim-treesitter.install').prefer_git = true
|
|
---@diagnostic disable-next-line: missing-fields
|
|
require('nvim-treesitter.configs').setup(opts)
|
|
end,
|
|
},
|
|
}, {
|
|
ui = {
|
|
icons = vim.g.have_nerd_font and {} or {
|
|
cmd = '⌘',
|
|
config = '🛠',
|
|
event = '📅',
|
|
ft = '📂',
|
|
init = '⚙',
|
|
keys = '🗝',
|
|
plugin = '🔌',
|
|
runtime = '💻',
|
|
require = '🌙',
|
|
source = '📄',
|
|
start = '🚀',
|
|
task = '📌',
|
|
lazy = '💤 ',
|
|
},
|
|
},
|
|
})
|
|
|
|
require('oil').setup {
|
|
natural_order = false,
|
|
sort = {
|
|
{ 'ctime', 'desc' },
|
|
},
|
|
}
|