huge updates

This commit is contained in:
sankalp committed 2024-08-19 03:32:26 +05:45
1 parent ca26b00c27
commit 18bd0cb00b
49 files changed
+4210 -2140

No files matched your search

+76
View File
@@ -0,0 +1,76 @@
-- Header
local function header()
local banner_small = {
' ',
' ',
' ',
' ███╗ ██╗███████╗ ██████╗ ██╗ ██╗██╗███╗ ███╗ ',
' ████╗ ██║██╔════╝██╔═══██╗██║ ██║██║████╗ ████║ ',
' ██╔██╗ ██║█████╗ ██║ ██║██║ ██║██║██╔████╔██║ ',
' ██║╚██╗██║██╔══╝ ██║ ██║╚██╗ ██╔╝██║██║╚██╔╝██║ ',
' ██║ ╚████║███████╗╚██████╔╝ ╚████╔╝ ██║██║ ╚═╝ ██║ ',
' ╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ ',
' ',
' With experience comes perspective ',
}
return banner_small
end
-- Footer
local function footer()
local version = vim.version()
local print_version = 'v' .. version.major .. '.' .. version.minor .. '.' .. version.patch
local stats = require('lazy').stats()
local plugins_count = stats.loaded .. '/' .. stats.count
local ms = math.floor(stats.startuptime + 0.5)
local time = vim.fn.strftime('%H:%M:%S')
local date = vim.fn.strftime('%d.%m.%Y')
local line1 = '' .. plugins_count .. ' plugins loaded in ' .. ms .. 'ms'
local line2 = '󰃭 ' .. date .. '' .. time
local line3 = '' .. print_version
-- Calculate padding for centering lines
local line1_width = vim.fn.strdisplaywidth(line1)
local line2_padding = math.max(0, math.floor((line1_width - vim.fn.strdisplaywidth(line2)) / 2))
local line3_padding = math.max(0, math.floor((line1_width - vim.fn.strdisplaywidth(line3)) / 2))
-- Apply padding to lines
line2 = string.rep(' ', line2_padding) .. line2
line3 = string.rep(' ', line3_padding) .. line3
return {
' ',
line1,
line2,
line3,
}
end
local alpha = require('alpha')
local dashboard = require('alpha.themes.dashboard')
dashboard.section.header.val = header()
dashboard.section.footer.val = footer()
-- Menu
-- TODO: Add projects and Frecency?
dashboard.section.buttons.val = {
dashboard.button('e', ' New file', ':ene <BAR> startinsert<CR>'),
dashboard.button('f', ' Find files', '<cmd>Telescope find_files<CR>'),
dashboard.button('t', '󰊄 Find text', '<cmd>Telescope live_grep<CR>'),
dashboard.button('F', ' File browser', '<cmd>Telescope file_browser<CR>'),
dashboard.button('r', '󰔠 Recent files', '<cmd>Telescope oldfiles<CR>'),
dashboard.button('s', ' Open last session', ':lua require("persistence").load({ last = true })<CR>'),
dashboard.button('c', ' Config', '<cmd>e $MYVIMRC<CR>'),
dashboard.button('l', ' Plugins', '<cmd>Lazy<CR>'),
dashboard.button('q', ' Quit', '<cmd>qa<CR>'),
}
alpha.setup(dashboard.config)
-- Update the footer after all plugins are fully loaded
vim.api.nvim_create_autocmd('User', {
pattern = 'LazyVimStarted',
callback = function()
dashboard.section.footer.val = footer()
pcall(vim.cmd, 'AlphaRedraw')
end,
})
+90
View File
@@ -0,0 +1,90 @@
local cmp = require('cmp')
local luasnip = require('luasnip')
require('luasnip/loaders/from_vscode').lazy_load()
cmp.setup({
completion = {
keyword_length = 1,
completeopt = 'menu,menuone',
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
formatting = {
fields = { 'kind', 'abbr', 'menu' },
format = function(entry, vim_item)
local kind = require('lspkind').cmp_format({ mode = 'symbol_text', maxwidth = 50 })(entry, vim_item)
local strings = vim.split(kind.kind, '%s', { trimempty = true })
kind.kind = ' ' .. (strings[1] or '') .. ' '
kind.menu = ' (' .. (strings[2] or '') .. ')'
return kind
end,
},
snippet = { -- configure how nvim-cmp interacts with snippet engine
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = {
['<C-k>'] = cmp.mapping.select_prev_item(),
['<C-j>'] = cmp.mapping.select_next_item(),
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-1), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(1), { 'i', 'c' }),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<C-u>'] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-y>'] = cmp.config.disable,
['<C-c>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = false,
}),
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expandable() then
luasnip.expand()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
},
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'cmdline' },
},
}),
cmp.setup.cmdline('/', {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' },
},
}),
-- sources for autocompletion
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' }, -- snippets
{ name = 'buffer' }, -- text within current buffer
{ name = 'path' }, -- file system paths
{ name = 'codeium' }, -- AI for autocompletion
-- { name = "nvim_lsp_signature_help" },
-- { name = "calc" }, --for maths calculations
},
})
+172
View File
@@ -0,0 +1,172 @@
local lspconfig = require('lspconfig')
-- import cmp-nvim-lsp plugin
local cmp_nvim_lsp = require('cmp_nvim_lsp')
local keymap = vim.keymap -- for conciseness
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf, silent = true }
-- set keybinds
opts.desc = 'Show LSP references'
keymap.set('n', 'lR', '<cmd>Telescope lsp_references<CR>', opts) -- show definition, references
opts.desc = 'Go to declaration'
keymap.set('n', 'lD', vim.lsp.buf.declaration, opts) -- go to declaration
opts.desc = 'Show LSP definitions'
keymap.set('n', 'ld', '<cmd>Telescope lsp_definitions<CR>', opts) -- show lsp definitions
opts.desc = 'Show LSP implementations'
keymap.set('n', 'li', '<cmd>Telescope lsp_implementations<CR>', opts) -- show lsp implementations
opts.desc = 'Show LSP type definitions'
keymap.set('n', 'lt', '<cmd>Telescope lsp_type_definitions<CR>', opts) -- show lsp type definitions
opts.desc = 'See available code actions'
keymap.set({ 'n', 'v' }, '<leader>la', vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection
opts.desc = 'Smart rename'
keymap.set('n', '<leader>mr', vim.lsp.buf.rename, opts) -- smart rename
opts.desc = 'Show buffer diagnostics'
keymap.set('n', '<leader>lD', '<cmd>Telescope diagnostics bufnr=0<CR>', opts) -- show diagnostics for file
opts.desc = 'Show line diagnostics'
keymap.set('n', '<leader>ld', vim.diagnostic.open_float, opts) -- show diagnostics for line
opts.desc = 'Show documentation for what is under cursor'
keymap.set('n', 'K', vim.lsp.buf.hover, opts) -- show documentation for what is under cursor
opts.desc = 'Restart LSP'
keymap.set('n', '<leader>ls', ':LspRestart<CR>', opts) -- mapping to restart lsp if necessary
end,
})
-- used to enable autocompletion (assign to every lsp server config)
local capabilities = cmp_nvim_lsp.default_capabilities()
-- configure matlab server
lspconfig['clangd'].setup({
capabilities = capabilities,
on_attach = on_attach,
})
-- configure bash server
lspconfig['bashls'].setup({
capabilities = capabilities,
on_attach = on_attach,
})
-- configure html server
lspconfig['html'].setup({
capabilities = capabilities,
on_attach = on_attach,
})
-- configure typescript server with plugin
lspconfig['tsserver'].setup({
capabilities = capabilities,
on_attach = on_attach,
})
-- configure css server
lspconfig['cssls'].setup({
capabilities = capabilities,
on_attach = on_attach,
})
-- configure tailwindcss server
lspconfig['tailwindcss'].setup({
capabilities = capabilities,
on_attach = on_attach,
})
-- configure svelte server
lspconfig['svelte'].setup({
capabilities = capabilities,
on_attach = function(client, bufnr)
on_attach(client, bufnr)
vim.api.nvim_create_autocmd('BufWritePost', {
pattern = { '*.js', '*.ts' },
callback = function(ctx)
if client.name == 'svelte' then
client.notify('$/onDidChangeTsOrJsFile', { uri = ctx.file })
end
end,
})
end,
})
-- configure prisma orm server
lspconfig['prismals'].setup({
capabilities = capabilities,
on_attach = on_attach,
})
-- configure emmet language server
lspconfig['emmet_ls'].setup({
capabilities = capabilities,
on_attach = on_attach,
filetypes = { 'html', 'typescriptreact', 'javascriptreact', 'css', 'sass', 'scss', 'less', 'svelte' },
})
-- configure python server
lspconfig['pyright'].setup({
capabilities = capabilities,
on_attach = on_attach,
})
-- configure lua server (with special settings)
lspconfig['lua_ls'].setup({
capabilities = capabilities,
on_attach = on_attach,
settings = { -- custom settings for lua
Lua = {
-- make the language server recognize "vim" global
diagnostics = {
globals = { 'vim' },
},
workspace = {
-- make language server aware of runtime files
library = {
[vim.fn.expand('$VIMRUNTIME/lua')] = true,
[vim.fn.stdpath('config') .. '/lua'] = true,
},
},
},
},
})
local x = vim.diagnostic.severity
local config = {
-- Enable virtual text
virtual_text = { -- or false for disable
prefix = '', -- ■  󰊠
suffix = '',
format = function(diagnostic)
local prefix = '󰊠 '
local suffix = ' '
-- return full message with custom prefix & suffix
return prefix .. diagnostic.message .. suffix
end,
},
update_in_insert = true,
signs = { text = { [x.ERROR] = '', [x.WARN] = '', [x.HINT] = '󰌵', [x.INFO] = '' } },
underline = false,
severity_sort = true,
float = {
focusable = false,
style = 'minimal',
border = 'rounded',
source = 'always',
header = '',
prefix = '',
},
}
vim.diagnostic.config(config)
-- add borders to lsp info window
require('lspconfig.ui.windows').default_options.border = 'single'
+198
View File
@@ -0,0 +1,198 @@
local lualine = require('lualine')
-- Color table for highlights
-- stylua: ignore
local colors = {
bg = 'none',
fg = '#bbc2cf',
yellow = '#ECBE7B',
cyan = '#008080',
darkblue = '#081633',
green = '#98be65',
orange = '#FF8800',
violet = '#a9a1e1',
magenta = '#c678dd',
blue = '#51afef',
red = '#ec5f67',
}
local conditions = {
buffer_not_empty = function()
return vim.fn.empty(vim.fn.expand('%:t')) ~= 1
end,
hide_in_width = function()
return vim.fn.winwidth(0) > 80
end,
check_git_workspace = function()
local filepath = vim.fn.expand('%:p:h')
local gitdir = vim.fn.finddir('.git', filepath .. ';')
return gitdir and #gitdir > 0 and #gitdir < #filepath
end,
}
-- Config
local config = {
options = {
-- Disable sections and component separators
component_separators = '',
section_separators = '',
disabled_filetypes = {
'NeoTree',
'NvimTree',
'Outline',
'alpha',
},
theme = {
-- We are going to use lualine_c an lualine_x as left and
-- right section. Both are highlighted by c theme . So we
-- are just setting default looks o statusline
normal = { c = { fg = colors.fg, bg = colors.bg } },
inactive = { c = { fg = colors.fg, bg = colors.bg } },
},
},
sections = {
-- these are to remove the defaults
lualine_a = {},
lualine_b = {},
lualine_y = {},
lualine_z = {},
-- These will be filled later
lualine_c = {},
lualine_x = {},
},
inactive_sections = {
-- these are to remove the defaults
lualine_a = {},
lualine_b = {},
lualine_y = {},
lualine_z = {},
lualine_c = {},
lualine_x = {},
},
}
-- Inserts a component in lualine_c at left section
local function ins_left(component)
table.insert(config.sections.lualine_c, component)
end
-- Inserts a component in lualine_x at right section
local function ins_right(component)
table.insert(config.sections.lualine_x, component)
end
ins_left({
function()
return '▊'
end,
color = { fg = colors.blue }, -- Sets highlighting of component
padding = { left = 0, right = 1 }, -- We don't need space before this
})
ins_left({
-- mode component
function()
return ''
end,
color = function()
-- auto change color according to neovims mode
local mode_color = {
n = colors.red,
i = colors.green,
v = colors.blue,
['␖'] = colors.blue,
V = colors.blue,
c = colors.magenta,
no = colors.red,
s = colors.orange,
S = colors.orange,
['␓'] = colors.orange,
ic = colors.yellow,
R = colors.violet,
Rv = colors.violet,
cv = colors.red,
ce = colors.red,
r = colors.cyan,
rm = colors.cyan,
['r?'] = colors.cyan,
['!'] = colors.red,
t = colors.red,
}
return { fg = mode_color[vim.fn.mode()] }
end,
padding = { right = 1 },
})
ins_left({
'filename',
cond = conditions.buffer_not_empty,
color = { fg = colors.magenta, gui = 'bold' },
})
ins_left({
'diagnostics',
sources = { 'nvim_diagnostic' },
symbols = { error = '', warn = '', info = '' },
diagnostics_color = {
error = { fg = colors.red },
warn = { fg = colors.yellow },
info = { fg = colors.cyan },
},
})
-- Insert mid section. You can make any number of sections in neovim :)
-- for lualine it's any number greater then 2
ins_left({
function()
return '%='
end,
})
ins_left({
-- Lsp server name .
function()
local msg = 'No Active Lsp'
local clients = vim.lsp.get_clients()
if next(clients) == nil then
return msg
end
for _, client in ipairs(clients) do
local filetypes = client.config.filetypes
if filetypes and vim.fn.index(filetypes) ~= -1 then
return client.name
end
end
return msg
end,
icon = ' LSP:',
color = { fg = '#ffffff', gui = 'bold' },
})
ins_right({
'diff',
-- Is it me or the symbol for modified us really weird
symbols = { added = '', modified = '', removed = '' },
diff_color = {
added = { fg = colors.green },
modified = { fg = colors.orange },
removed = { fg = colors.red },
},
cond = conditions.hide_in_width,
})
ins_right({
'branch',
icon = '',
color = { fg = colors.violet, gui = 'bold' },
})
ins_right({
function()
return '▊'
end,
color = { fg = colors.blue },
padding = { left = 1 },
})
-- Now don't forget to initialize lualine
lualine.setup(config)
+47
View File
@@ -0,0 +1,47 @@
local mason = require('mason')
local mason_lspconfig = require('mason-lspconfig')
local mason_tool_installer = require('mason-tool-installer')
-- enable mason and configure icons
mason.setup({
ui = {
border = 'rounded',
icons = {
package_installed = '✓',
package_pending = '➜',
package_uninstalled = '✗',
},
},
})
mason_lspconfig.setup({
-- list of servers for mason to install
ensure_installed = {
'tsserver',
'html',
'cssls',
'tailwindcss',
'svelte',
'lua_ls',
'pyright',
'jdtls',
'bashls',
'jsonls',
'clangd',
'emmet_ls',
'prismals',
},
})
mason_tool_installer.setup({
ensure_installed = {
'prettier', -- prettier formatter
'biome', -- js formatter
'stylua', -- lua formatter
'black', -- python formatter
'isort', -- python formatter
'clang-format', -- c/c++ formatter
'pylint',
'eslint_d',
},
})
+61
View File
@@ -0,0 +1,61 @@
local mason_null_ls = require('mason-null-ls')
local null_ls = require('null-ls')
local null_ls_utils = require('null-ls.utils')
mason_null_ls.setup({
ensure_installed = {
'prettier', -- prettier formatter
'biome', -- js formatter
'clang-format', -- c/c++ formatter
'stylua', -- lua formatter
'black', -- python formatter
'pylint', -- python linter
-- "eslint_d", -- js linter
},
})
-- for conciseness
local formatting = null_ls.builtins.formatting -- to setup formatters
local diagnostics = null_ls.builtins.diagnostics -- to setup linters
-- to setup format on save
local augroup = vim.api.nvim_create_augroup('LspFormatting', {})
-- configure null_ls
null_ls.setup({
root_dir = null_ls_utils.root_pattern('.null-ls-root', 'Makefile', '.git', 'package.json'),
sources = {
formatting.prettier, -- js/ts formatter
formatting.stylua, -- lua formatter
formatting.isort,
formatting.black,
formatting.clang_format,
diagnostics.pylint,
-- diagnostics.eslint_d.with({ -- js/ts linter
-- condition = function(utils)
-- return utils.root_has_file({ ".eslintrc.js", ".eslintrc.cjs" }) -- only enable if root has .eslintrc.js or .eslintrc.cjs
-- end,
-- }),
},
-- configure format on save
on_attach = function(current_client, bufnr)
if current_client.supports_method('textDocument/formatting') then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd('BufWritePre', {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({
filter = function(client)
-- only use null-ls for formatting instead of lsp server
return client.name == 'null-ls'
end,
bufnr = bufnr,
})
end,
})
end
end,
})
+68
View File
@@ -0,0 +1,68 @@
local telescope = require('telescope')
local fb_actions = require('telescope').extensions.file_browser.actions
telescope.setup({
file_ignore_patterns = { '%.git/.' },
defaults = {
preview = {
treesitter = false,
},
},
extensions = {
fzf = {
fuzzy = true, -- false will only do exact matching
override_generic_sorter = true, -- override the generic sorter
override_file_sorter = true, -- override the file sorter
case_mode = 'smart_case', -- or "ignore_case" or "respect_case"
},
file_browser = {
theme = 'ivy',
hijack_netrw = true,
mapping = {
['i'] = {
['<A-c>'] = fb_actions.create,
['<A-r>'] = fb_actions.rename,
['<A-d>'] = fb_actions.remove,
['<A-h>'] = fb_actions.toggle_hidden,
},
['n'] = {
['<A-c>'] = fb_actions.create,
['<A-r'] = fb_actions.rename,
['<A-d'] = fb_actions.remove,
['<A-h'] = fb_actions.toggle_hidden,
},
},
},
undo = {
use_delta = true,
use_custom_command = nil,
side_by_side = true,
vim_diff_opts = {
ctxlen = vim.o.scrolloff * 2,
},
entry_format = 'state #$ID, $STAT, $TIME',
-- time_format = '%d %b %H:%M',
saved_only = false,
layout_strategy = 'vertical',
layout_config = {
preview_height = 0.7,
},
mapping = {
i = {
['<S-cr>'] = require('telescope-undo.actions').yank_additions,
['<C-cr>'] = require('telescope-undo.actions').yank_deletions,
['<cr>'] = require('telescope-undo.actions').restore,
},
},
},
},
borderchars = {
prompt = { '─', '│', '─', '│', '╭', '╮', '╯', '╰' },
results = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
},
})
telescope.load_extension('ui-select')
telescope.load_extension('file_browser')
-- telescope.load_extension("refactoring")
telescope.load_extension('notify')
telescope.load_extension('undo')
+23
View File
@@ -0,0 +1,23 @@
require('toggleterm').setup({
size = 10,
open_mapping = [[<c-\>]],
hide_numbers = true,
shade_filetypes = {},
shade_terminals = true,
shading_factor = '2',
start_in_insert = true,
insert_mappings = true,
terminal_mappings = true,
persist_size = true,
direction = 'float', -- Use 'float' for floating terminal windows
close_on_exit = true,
shell = vim.o.shell,
float_opts = {
border = 'curved', -- or 'single', 'double', 'shadow', etc.
winblend = 0, -- Set to 0 for full transparency
highlights = {
border = 'Normal',
background = 'Normal',
},
},
})