Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 187 additions & 45 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ vim.g.mapleader = ' '
vim.g.maplocalleader = ' '

-- Set to true if you have a Nerd Font installed and selected in the terminal
vim.g.have_nerd_font = false
vim.g.have_nerd_font = true

-- [[ Setting options ]]
-- See `:help vim.o`
Expand All @@ -114,7 +114,9 @@ vim.o.showmode = false
-- Schedule the setting after `UiEnter` because it can increase startup-time.
-- Remove this option if you want your OS clipboard to remain independent.
-- See `:help 'clipboard'`
vim.schedule(function() vim.o.clipboard = 'unnamedplus' end)
vim.schedule(function()
-- vim.opt.clipboard = 'unnamedplus'
end)
Comment on lines +117 to +119

-- Enable break indent
vim.o.breakindent = true
Expand Down Expand Up @@ -195,7 +197,7 @@ vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagn
--
-- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping
-- or just use <C-\><C-n> to exit terminal mode
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
-- vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })

-- TIP: Disable arrow keys in normal mode
-- vim.keymap.set('n', '<left>', '<cmd>echo "Use h to move!!"<CR>')
Expand Down Expand Up @@ -387,7 +389,16 @@ require('lazy').setup({
require('telescope').setup {
-- You can put your default mappings / updates / etc. in here
-- All the info you're looking for is in `:help telescope.setup()`
--
defaults = {
file_ignore_patterns = {
'node_modules',
'package-lock.json',
'yarn.lock',
'pnpm-lock.yaml',
'lazy-lock.json',
},
mappings = {},
},
-- defaults = {
-- mappings = {
-- i = { ['<c-enter>'] = 'to_fuzzy_refine' },
Expand Down Expand Up @@ -502,6 +513,9 @@ require('lazy').setup({
{ 'j-hui/fidget.nvim', opts = {} },
},
config = function()
-- Configuration: Set to true to prefer system clangd over Mason
local prefer_system_clangd = true

-- Brief aside: **What is LSP?**
--
-- LSP is an initialism you've probably heard, but might not understand what it is.
Expand Down Expand Up @@ -595,21 +609,47 @@ require('lazy').setup({
end,
})

-- Disable hover capability from Ruff if using with ty
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('lsp_attach_disable_ruff_hover', { clear = true }),
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client == nil then
return
end
if client.name == 'ruff' then
-- Disable hover in favor of ty
client.server_capabilities.hoverProvider = false
end
end,
desc = 'LSP: Disable hover capability from Ruff',
})

-- Enable the following language servers
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
-- See `:help lsp-config` for information about keys and how to configure
---@type table<string, vim.lsp.Config>
local servers = {
-- clangd = {},
-- gopls = {},
-- pyright = {},
-- ty for Python type checking and hover documentation
ty = {
settings = {
ty = {
-- ty language server settings go here
},
},
},
-- rust_analyzer = {},
--
-- Some languages (like typescript) have entire language plugins that can be useful:
-- https://github.com/pmizio/typescript-tools.nvim
--
-- But for many setups, the LSP (`ts_ls`) will work just fine
-- ts_ls = {},
--
-- Ruff LSP for Python linting and formatting
ruff = {},

stylua = {}, -- Used to format Lua code

Expand Down Expand Up @@ -655,17 +695,77 @@ require('lazy').setup({
-- :Mason
--
-- You can press `g?` for help in this menu.
--
-- You can add other tools here that you want Mason to install
-- for you, so that they are available from within Neovim.

-- Detect system capabilities
local is_termux = vim.fn.has 'unix' == 1 and vim.fn.executable 'termux-info' == 1
local has_system_clangd = vim.fn.executable 'clangd' == 1
local use_system_clangd = prefer_system_clangd and has_system_clangd

-- List of tools to install via Mason
local ensure_installed = vim.tbl_keys(servers or {})

-- Extend with common tools
vim.list_extend(ensure_installed, {
-- You can add other tools here that you want Mason to install
'stylua',
'tailwindcss',
'prettierd',
'html',
'intelephense',
'pretty-php',
-- 'pylsp',
'svelte',
'vtsls',
'gofumpt',
'gopls',
'shfmt',
'rust-analyzer',
'ruff',
})

-- Only include clangd if not in Termux and system clangd preference allows it
if not is_termux and not use_system_clangd then
vim.list_extend(ensure_installed, {
'clangd',
'clang-format',
})
elseif not is_termux then
-- Still install clang-format via Mason even when using system clangd
vim.list_extend(ensure_installed, {
'clang-format',
})
end

require('mason-tool-installer').setup { ensure_installed = ensure_installed }

for name, server in pairs(servers) do
vim.lsp.config(name, server)
vim.lsp.enable(name)
end

-- Setup clangd LSP conditionally - prefer system clangd if configured and available
local clangd_cmd = (use_system_clangd or is_termux) and { 'clangd' } or nil

require('lspconfig').clangd.setup {
cmd = clangd_cmd,
}

require('mason-lspconfig').setup {
ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer)
automatic_installation = false,
handlers = {
function(server_name)
local server = servers[server_name] or {}
-- This handles overriding only values explicitly passed
-- by the server configuration above. Useful when disabling
-- certain features of an LSP (for example, turning off formatting for ts_ls)
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
require('lspconfig')[server_name].setup(server)
Comment on lines +762 to +765
end,
},
}
end,
},

Expand All @@ -675,8 +775,8 @@ require('lazy').setup({
cmd = { 'ConformInfo' },
keys = {
{
'<leader>f',
function() require('conform').format { async = true } end,
'<leader>ff',
function() require('conform').format { async = true, lsp_format = 'fallback' } end,
mode = '',
desc = '[F]ormat buffer',
},
Expand All @@ -685,16 +785,19 @@ require('lazy').setup({
---@type conform.setupOpts
opts = {
notify_on_error = false,
format_on_save = function(bufnr)
-- You can specify filetypes to autoformat on save here:
local enabled_filetypes = {
-- lua = true,
-- python = true,
}
if enabled_filetypes[vim.bo[bufnr].filetype] then
return { timeout_ms = 500 }
else
format_after_save = function(bufnr)
-- Disable "format_on_save lsp_fallback" for languages that don't
-- have a well standardized coding style. You can add additional
-- languages here or re-enable it for the disabled ones.
local disable_filetypes = {}
if disable_filetypes[vim.bo[bufnr].filetype] then
return nil
else
return {
async = true,
timeout_ms = 500,
lsp_format = 'fallback',
}
end
end,
default_format_opts = {
Expand All @@ -708,6 +811,29 @@ require('lazy').setup({
--
-- You can use 'stop_after_first' to run the first available formatter from the list
-- javascript = { "prettierd", "prettier", stop_after_first = true },
javascript = { 'prettierd' },
typescript = { 'prettierd' },
javascriptreact = { 'prettierd' },
typescriptreact = { 'prettierd' },
scss = { 'prettierd' },
pandoc = { 'prettierd' },
markdown = { 'prettierd' },
json = { 'prettierd' },
css = { 'prettierd' },
yml = { 'prettierd' },
html = { 'prettierd' },
php = { 'pretty-php' },
cpp = { 'clang_format' },
sh = { 'shfmt' },
go = { 'gofumpt' },
python = {
-- To fix auto-fixable lint errors
'ruff_fix',
-- To run the Ruff formatter
'ruff_format',
-- To organize the imports
'ruff_organize_imports',
},
},
},
},
Expand Down Expand Up @@ -768,6 +894,14 @@ require('lazy').setup({
--
-- See :h blink-cmp-config-keymap for defining your own keymap
preset = 'default',
['<cr>'] = { 'accept', 'fallback' },
['<c-x>'] = {
function(cmp)
cmp.show { providers = { 'lsp' } }
end,
},
['<c-up>'] = { 'fallback' },
['<c-down>'] = { 'fallback' },

-- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
Expand Down Expand Up @@ -805,28 +939,6 @@ require('lazy').setup({
},
},

{ -- You can easily change to a different colorscheme.
-- Change the name of the colorscheme plugin below, and then
-- change the command in the config to whatever the name of that colorscheme is.
--
-- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`.
'folke/tokyonight.nvim',
priority = 1000, -- Make sure to load this before all the other start plugins.
config = function()
---@diagnostic disable-next-line: missing-fields
require('tokyonight').setup {
styles = {
comments = { italic = false }, -- Disable italics in comments
},
}

-- Load the colorscheme here.
-- Like many other themes, this one has different styles, and you could load
-- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'.
vim.cmd.colorscheme 'tokyonight-night'
end,
},

-- Highlight todo, notes, etc in comments
{
'folke/todo-comments.nvim',
Expand Down Expand Up @@ -861,7 +973,17 @@ require('lazy').setup({
-- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren
-- - sd' - [S]urround [D]elete [']quotes
-- - sr)' - [S]urround [R]eplace [)] [']
require('mini.surround').setup()
require('mini.surround').setup {
mappings = {
add = 'ra', -- Add surrounding in Normal and Visual modes
delete = 'rd', -- Delete surrounding
find = 'rf', -- Find surrounding (to the right)
find_left = 'rF', -- Find surrounding (to the left)
highlight = 'rh', -- Highlight surrounding
replace = 'rr', -- Replace surrounding
update_n_lines = 'rn', -- Update `n_lines`
},
}

-- Simple and easy statusline.
-- You could remove this setup call if you don't like it,
Expand All @@ -888,8 +1010,28 @@ require('lazy').setup({
branch = 'main',
-- [[ Configure Treesitter ]] See `:help nvim-treesitter-intro`
config = function()
-- ensure basic parser are installed
local parsers = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }
local parsers = {
'jsx',
'tsx',
'javascript',
'typescript',
'rust',
'zig',
'bash',
'c',
'cpp',
'python',
'vimdoc',
'vim',
'lua',
'php',
'html',
'svelte',
'markdown',
'markdown_inline',
'yaml',
'json',
}
require('nvim-treesitter').install(parsers)

---@param buf integer
Expand Down Expand Up @@ -947,18 +1089,18 @@ require('lazy').setup({
-- Here are some example plugins that I've included in the Kickstart repository.
-- Uncomment any of the lines below to enable them (you will need to restart nvim).
--
-- require 'kickstart.plugins.debug',
require 'kickstart.plugins.debug',
-- require 'kickstart.plugins.indent_line',
-- require 'kickstart.plugins.lint',
-- require 'kickstart.plugins.autopairs',
require 'kickstart.plugins.autopairs',
-- require 'kickstart.plugins.neo-tree',
-- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommended keymaps

-- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
-- This is the easiest way to modularize your config.
--
-- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going.
-- { import = 'custom.plugins' },
{ import = 'custom.plugins' },
--
-- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec`
-- Or use telescope!
Expand Down
Loading
Loading