local fn = vim.fn -- local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' if fn.empty(fn.glob(install_path)) > 0 then packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) end require('packer').startup(function(use) -- Packer can manage itself use "wbthomason/packer.nvim" use "sindrets/diffview.nvim" -- tpope section use "tpope/vim-fugitive" use "tpope/vim-surround" use "tpope/vim-rhubarb" use "tpope/vim-commentary" use "tpope/vim-repeat" -- :Test* commands use "janko-m/vim-test" -- colorscheme use { "catppuccin/nvim", as = "catppuccin" } use "https://git.sr.ht/~p00f/alabaster.nvim" use 'stevearc/oil.nvim' -- highlight color codes use "catgoose/nvim-colorizer.lua" -- language server!! use { 'VonHeikemen/lsp-zero.nvim', requires = { --- Uncomment the two plugins below if you want to manage the language servers from neovim -- {'williamboman/mason.nvim'}, -- {'williamboman/mason-lspconfig.nvim'}, {'neovim/nvim-lspconfig'}, {'hrsh7th/nvim-cmp'}, {'hrsh7th/cmp-nvim-lsp'}, {'L3MON4D3/LuaSnip'}, } } use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' } --Telescope! use { {'nvim-telescope/telescope.nvim', requires = { {'nvim-lua/plenary.nvim'} }}, {'nvim-telescope/telescope-fzf-native.nvim', run = 'make', requires = {{'nvim-telescope/telescope.nvim'}} } } -- Automatically set up your configuration after cloning packer.nvim -- Put this at the end after all plugins if packer_bootstrap then require('packer').sync() end -- -- use 'stevearc/oil.nvim' -- use 'nvim-tree/nvim-web-devicons' -- -- -- some text support -- use 'sheerun/vim-polyglot' -- -- use 'levouh/tint.nvim' -- -- -- language server!! -- use 'neovim/nvim-lspconfig' -- Collection of configurations for the built-in LSP client -- use "lukas-reineke/lsp-format.nvim" -- -- -- use 'norcalli/nvim-colorizer.lua' -- -- use { -- "jose-elias-alvarez/null-ls.nvim", -- requires = { "nvim-lua/plenary.nvim" }, -- } -- use "lewis6991/gitsigns.nvim" use "evanphx/jjsigns.nvim" use 'github/copilot.vim' end) -- vim.o.expandtab = true vim.o.tabstop = 4 vim.o.shiftwidth = 4 vim.o.clipboard = "unnamed" vim.o.showtabline = 2 vim.o.wildmenu = true vim.o.ruler = true vim.o.backspace = "2" vim.o.undofile = true vim.o.completeopt = "menu,menuone,noselect" vim.o.undodir=fn.stdpath("config") .. "/undo" if fn.has("nvim") == 1 then vim.o.mouse = "a" end vim.opt.listchars = { tab = '> ', lead = '·', trail = '·' } vim.opt.list = true vim.g.mapleader = " " vim.api.nvim_set_keymap( "n", "", "v:count == 0 ? 'v' : ':normal! 0'.v:count.''", {noremap=true, silent=true, expr=true} ) vim.api.nvim_set_keymap( "n", "_", "v:count == 0 ? 's' : ':normal! '.v:count.'_'", {noremap=true, silent=true, expr=true} ) vim.api.nvim_set_keymap( "n", "n", "nzz", {noremap=true} ) vim.api.nvim_set_keymap( "n", "N", "Nzz", {noremap=true} ) -- Always spell for specific filetypes vim.cmd[[ autocmd FileType gitcommit setlocal spell autocmd FileType markdown setlocal spell ]] function setup_lsp() local cmp = require('cmp') cmp.setup({ sources = { {name = 'nvim_lsp'}, }, snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) end, }, mapping = cmp.mapping.preset.insert({}), }) -- Reserve a space in the gutter -- This will avoid an annoying layout shift in the screen vim.opt.signcolumn = 'yes' -- Add cmp_nvim_lsp capabilities settings to lspconfig -- This should be executed before you configure any language server local lspconfig_defaults = require('lspconfig').util.default_config lspconfig_defaults.capabilities = vim.tbl_deep_extend( 'force', lspconfig_defaults.capabilities, require('cmp_nvim_lsp').default_capabilities() ) -- This is where you enable features that only work -- if there is a language server active in the file vim.api.nvim_create_autocmd('LspAttach', { callback = function(event) local opts = {buffer = event.buf} vim.keymap.set('n', 'K', function() vim.lsp.buf.hover({ border = 'rounded' }) end, opts) vim.keymap.set('n', 'gs', function() vim.lsp.buf.signature_help({ border = 'rounded' }) end, opts) vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) vim.keymap.set('n', 'go', 'lua vim.lsp.buf.type_definition()', opts) vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) vim.keymap.set('n', '', 'lua vim.lsp.buf.rename()', opts) vim.keymap.set({'n', 'x'}, '', 'lua vim.lsp.buf.format({async = true})', opts) vim.keymap.set('n', '', 'lua vim.lsp.buf.code_action()', opts) vim.keymap.set('n', 'e', 'lua vim.diagnostic.open_float()', opts) end, }) -- These are just examples. Replace them with the language -- servers you have installed in your system require('gitsigns').setup() require('jjsigns').setup() vim.lsp.enable('pyright') vim.lsp.enable('ruby_lsp') vim.lsp.enable('ts_ls') vim.lsp.enable('biome') vim.lsp.enable('rust_analyzer') end -- function setup_lsp() -- -- Needed to appropriately highlight codefences returned from denols -- vim.g.markdown_fenced_languages = { -- "ts=typescript" -- } -- local nvim_lsp = require("lspconfig") -- local null_ls = require("null-ls"); -- local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) -- -- Mappings. -- -- See `:help vim.diagnostic.*` for documentation on any of the below functions -- local opts = { noremap=true, silent=true } -- vim.api.nvim_set_keymap('n', 'e', 'lua vim.diagnostic.open_float()', opts) -- vim.api.nvim_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) -- vim.api.nvim_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) -- vim.api.nvim_set_keymap('n', 'q', 'lua vim.diagnostic.setloclist()', opts) -- -- -- Use an on_attach function to only map the following keys -- -- after the language server attaches to the current buffer -- local on_attach = function(client, bufnr) -- -- Enable completion triggered by -- vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') -- -- -- Mappings. -- -- See `:help vim.lsp.*` for documentation on any of the below functions -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', opts) -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) -- -- if 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({ bufnr = bufnr }) -- end, -- }) -- end -- end -- -- local flags = { -- -- This will be the default in neovim 0.7+ -- debounce_text_changes = 150, -- } -- nvim_lsp.eslint.setup{ -- on_attach = function(client, bufnr) -- client.server_capabilities.document_formatting = true -- on_attach(client, bufnr) -- end -- } -- nvim_lsp.denols.setup({ -- flags = flags, -- root_dir = nvim_lsp.util.root_pattern("deno.json", "deno.jsonc"), -- }) -- nvim_lsp.tsserver.setup({ -- capabilities = capabilities, -- flags = flags, -- on_attach = function(client, bufnr) -- client.server_capabilities.document_formatting = false -- client.server_capabilities.document_range_formatting = false -- on_attach(client, bufnr) -- end -- }) -- nvim_lsp.pyright.setup({ -- capabilities = capabilities, -- flags = flags, -- on_attach = function(client, bufnr) -- client.server_capabilities.document_formatting = false -- client.server_capabilities.document_range_formatting = false -- on_attach(client, bufnr) -- end -- -- }) -- -- null_ls.setup({ -- sources = { -- null_ls.builtins.formatting.prettier, -- null_ls.builtins.diagnostics.ruff, -- null_ls.builtins.diagnostics.write_good, -- null_ls.builtins.code_actions.gitsigns, -- null_ls.builtins.code_actions.eslint, -- null_ls.builtins.completion.spell, -- }, -- on_attach = function(client, bufnr) -- if 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() -- -- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead -- -- on later neovim version, you should use vim.lsp.buf.format({ async = false }) instead -- -- vim.lsp.buf.formatting_sync() -- vim.lsp.buf.format({ bufnr = bufnr }) -- end, -- }) -- end -- end, -- }) -- end -- function setup_treesitter() require'nvim-treesitter.config'.setup { ensure_installed = { "bash", "css", "html", "javascript", "jsdoc", "json", "lua", "prisma", "python", "ruby", "typescript", "vim", "tsx", "thrift", }, sync_install = false, -- install languages synchronously (only applied to `ensure_installed`) indent = { enable = true }, -- EXPERIMENTAL highlight = { enable = true, -- false will disable the whole extension -- Setting this to true will run `:h syntax` and tree-sitter at the same time. -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). -- Using this option may slow down your editor, and you may see some duplicate highlights. -- Instead of true it can also be a list of languages additional_vim_regex_highlighting = false, }, } end -- function setup_telescope() local telescope = require("telescope.builtin"); vim.cmd[[ nnoremap ff Telescope find_files nnoremap fg Telescope live_grep nnoremap fb Telescope buffers nnoremap fh Telescope help_tags ]] require('telescope').load_extension('fzf') end -- function setup_vim_test() vim.cmd[[ let test#strategy= "neovim" " h4 stuff :) " note: h4 == h[onor] " vim-test transformation to run nose tests via `make singletest`. " If a command looks like "nosetests ...", transform it to " "make singletest PYTESTARGS='...'" function! HonorTransform(cmd) abort " Check if we're in a repo that has a singletest target. If it does not, " who knows what's going on. Give vim-test's unmodified command a chance. let output = system("grep singletest: Makefile*") if v:shell_error != 0 return a:cmd endif if a:cmd =~ '.py:' " We're probably running a single single test, and therefore we set " the amount of parallelism to 1, so pdb and other stuff works well. " There might be a better way of detecting if we're inside of " `TestFile`... let l:parallelism="PARALLELISM=1" else let l:parallelism="" endif if a:cmd =~ '^nosetests ' let l:cmd_sans_nosetests = "-s ".substitute(a:cmd, '^nosetests ', '', '') let l:new_cmd = 'make singletest '.l:parallelism.' NOSEARGS='.shellescape(l:cmd_sans_nosetests) elseif a:cmd =~ '^pipenv run pytest ' let l:cmd_sans_nosetests = "-s ".substitute(a:cmd, '^pipenv run pytest ', '', '') let l:new_cmd = 'make singletest '.l:parallelism.' PYTEST_ARGS='.shellescape(l:cmd_sans_nosetests) elseif a:cmd =~ '^poetry run pytest ' let l:cmd_sans_nosetests = "-s ".substitute(a:cmd, '^poetry run pytest ', '', '') let l:new_cmd = 'make singletest '.l:parallelism.' PYTESTARGS='.shellescape(l:cmd_sans_nosetests) else let l:new_cmd = a:cmd endif return l:new_cmd endfunction if executable('nosetests') let test#python#runner = 'nose' else let test#python#runner = 'pytest' endif let g:test#custom_transformations = {'honor': function('HonorTransform')} let g:test#transformation = 'honor' let test#custom_runners = {'HonorJs': ['HonorRunner']} ]] end -- function setup_colors() vim.opt.termguicolors = true -- enable true-color support require("catppuccin").setup({ flavour = "latte" }) vim.cmd.colorscheme "catppuccin" require("colorizer").setup() end -- -- function setup_completion() -- local cmp = require("cmp") -- cmp.setup({ -- snippet = { -- -- REQUIRED - you must specify a snippet engine -- expand = function(args) -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. -- end, -- }, -- mapping = cmp.mapping.preset.insert({ -- [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), -- [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), -- [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), -- [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. -- [''] = cmp.mapping({ -- i = cmp.mapping.abort(), -- c = cmp.mapping.close(), -- }), -- [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. -- }), -- formatting = { -- format = function(entry, vim_item) -- vim_item = require("lspkind").cmp_format()(entry, vim_item) -- if entry.source.name == "nvim_lsp" then -- vim_item.menu = entry.source.source.client.name -- else -- vim_item.menu = entry.source.name -- end -- return vim_item -- end, -- }, -- sources = cmp.config.sources({ -- { name = 'nvim_lsp' }, -- { name = 'vsnip' }, -- }, { -- { name = 'buffer' }, -- }) -- }) -- -- -- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). -- cmp.setup.cmdline('/', { -- sources = { -- { name = 'buffer' } -- } -- }) -- -- -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). -- cmp.setup.cmdline(':', { -- sources = cmp.config.sources({ -- { name = 'path' } -- }, { -- { name = 'cmdline' } -- }) -- }) -- end -- function setup_file_explorer() -- Disable netrw vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 require("oil").setup({ view_options = { -- Show hidden files and directories by default show_hidden = true } }) -- Navigate to the parent directory using - vim.keymap.set("n", "-", require("oil").open, { desc = "Open parent directory" }) end function setup_ai_assistant() end -- -- function setup_folds() -- vim.o.foldcolumn = '0' -- vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value -- vim.o.foldlevelstart = 99 -- vim.o.foldenable = true -- require('ufo').setup({ -- close_fold_kinds_for_ft = {'imports'} -- }) -- end -- -- setup_completion() setup_lsp() setup_telescope() setup_vim_test() setup_colors() setup_file_explorer() setup_ai_assistant() setup_treesitter() -- setup_folds()