commit 9784dfe49828f5b56ea1ab71954a5a4877f27d4e Author: Andre Schaf Date: Thu Jul 13 10:45:16 2023 +0200 initial commit diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..d448e67 --- /dev/null +++ b/init.lua @@ -0,0 +1,7 @@ +vim.g.mapleader = " " + +require('plugins') +require('lsp') +require('set') +require('remap') + diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..9eec4f2 --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,16 @@ +{ + "LuaSnip": { "branch": "master", "commit": "a658ae2906344a1d2b9c507738e585cf68e685c7" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, + "copilot.vim": { "branch": "release", "commit": "a4a6d6b3f9e284e7f5c849619e06cd228cad8abd" }, + "gruvbox": { "branch": "master", "commit": "2b5b1f777f0583ffb39086d6c16f39e6e37459c0" }, + "lazy.nvim": { "branch": "main", "commit": "5af331ea65418dc9361769891921fdee4bcc837a" }, + "lsp-zero.nvim": { "branch": "v2.x", "commit": "7b9627c2cb50906993e194290b2e539c95dfdf47" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "82685fdd0f67a694b244cb058b83761f54664d68" }, + "mason.nvim": { "branch": "main", "commit": "5ad3e113b0c3fde3caba8630599373046f6197e8" }, + "nvim-cmp": { "branch": "main", "commit": "2743dd989e9b932e1b4813a4927d7b84272a14e2" }, + "nvim-lspconfig": { "branch": "master", "commit": "a7ecaff3245ba4b9e5ed784ebefbedba54e7f0ad" }, + "nvim-treesitter": { "branch": "master", "commit": "e1ab5391e5c4820dd1ffc2566d29b01573ab52a9" }, + "plenary.nvim": { "branch": "master", "commit": "102c02903c74b93c705406bf362049383abc87c8" }, + "telescope.nvim": { "branch": "master", "commit": "776b509f80dd49d8205b9b0d94485568236d1192" }, + "vim-startify": { "branch": "master", "commit": "81e36c352a8deea54df5ec1e2f4348685569bed2" } +} \ No newline at end of file diff --git a/lua/.luarc.json b/lua/.luarc.json new file mode 100644 index 0000000..75d131c --- /dev/null +++ b/lua/.luarc.json @@ -0,0 +1,25 @@ +{ + "workspace.library": [ + "/home/arne23/.config/nvim", + "/home/arne23/.local/share/nvim/lazy/lazy.nvim", + "/home/arne23/.local/share/nvim/lazy/gruvbox", + "/home/arne23/.local/share/nvim/lazy/vim-startify", + "/home/arne23/.local/share/nvim/lazy/copilot.vim", + "/home/arne23/.local/share/nvim/lazy/LuaSnip", + "/home/arne23/.local/share/nvim/lazy/cmp-nvim-lsp", + "/home/arne23/.local/share/nvim/lazy/nvim-cmp", + "/home/arne23/.local/share/nvim/lazy/mason-lspconfig.nvim", + "/home/arne23/.local/share/nvim/lazy/mason.nvim", + "/home/arne23/.local/share/nvim/lazy/nvim-lspconfig", + "/home/arne23/.local/share/nvim/lazy/lsp-zero.nvim", + "/home/arne23/.local/share/nvim/lazy/plenary.nvim", + "/home/arne23/.local/share/nvim/lazy/telescope.nvim", + "/home/arne23/.local/share/nvim/lazy/nvim-treesitter", + "/home/linuxbrew/.linuxbrew/Cellar/neovim/0.9.1/share/nvim/runtime", + "/home/linuxbrew/.linuxbrew/Cellar/neovim/0.9.1/share/nvim/runtime/pack/dist/opt/matchit", + "/home/linuxbrew/.linuxbrew/Cellar/neovim/0.9.1/lib/nvim", + "/home/arne23/.local/state/nvim/lazy/readme", + "/home/arne23/.local/share/nvim/lazy/cmp-nvim-lsp/after", + "${3rd}/luassert/library" + ] +} \ No newline at end of file diff --git a/lua/lsp.lua b/lua/lsp.lua new file mode 100644 index 0000000..26ab2bd --- /dev/null +++ b/lua/lsp.lua @@ -0,0 +1,84 @@ +local lsp = require('lsp-zero').preset({}) +local lspconfig = require('lspconfig') +local loaded_configs = require('lspconfig.configs') + +local function get_config() + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities.textDocument.completion.completionItem.snippetSupport = true + + return { + capabilities = capabilities, + } +end + +local function load_custom_configs() + local config_files = vim.split(vim.fn.globpath(vim.fn.stdpath('config') .. '/lua/lspconf', '*.lua', true), '\n') + + for _, f in ipairs(config_files) do + local name = vim.fn.fnamemodify(f, ':t:r') + require('lspconf.' .. name) + end +end + +local function setup_default_configs() + local available_servers = require('mason-lspconfig').get_installed_servers() + for _, server in pairs(available_servers) do + if not loaded_configs[server] then + local config = get_config() + lspconfig[server].setup(config) + end + end +end + +load_custom_configs() +setup_default_configs() + +lsp.on_attach(function(_, bufnr) + local opts = { buffer = bufnr, remap = false, } + -- Global mappings. + -- See `:help vim.diagnostic.*` for documentation on any of the below functions + vim.keymap.set('n', 'e', vim.diagnostic.open_float) + vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) + vim.keymap.set('n', ']d', vim.diagnostic.goto_next) + vim.keymap.set('n', 'q', vim.diagnostic.setloclist) + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, opts) + vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + vim.keymap.set('n', 'f', function() + vim.lsp.buf.format { async = true } + end, opts) +end) + +lsp.setup() + +-- You need to setup `cmp` after lsp-zero +local cmp = require('cmp') +local cmp_action = require('lsp-zero').cmp_action() + +cmp.setup({ + mapping = { + -- `Enter` key to confirm completion + [''] = cmp.mapping.confirm({select = false}), + + -- Ctrl+Space to trigger completion menu + [''] = cmp.mapping.complete(), + + -- Navigate between snippet placeholder + [''] = cmp_action.luasnip_jump_forward(), + [''] = cmp_action.luasnip_jump_backward(), + } +}) + +-- Use LspAttach autocommand to only map the following keys +-- after the language server attaches to the current buffer diff --git a/lua/lspconf/lua.lua b/lua/lspconf/lua.lua new file mode 100644 index 0000000..85b350c --- /dev/null +++ b/lua/lspconf/lua.lua @@ -0,0 +1,29 @@ +local lspconfig = require('lspconfig') + +lspconfig.lua_ls.setup { + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using + -- (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { + 'vim', + 'require', + 'opt', + }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, +} diff --git a/lua/lspconf/php.lua b/lua/lspconf/php.lua new file mode 100644 index 0000000..1b2f294 --- /dev/null +++ b/lua/lspconf/php.lua @@ -0,0 +1,34 @@ +local lspconfig = require 'lspconfig' +local configs = require 'lspconfig.configs' + +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities.textDocument.completion.completionItem.snippetSupport = true + +if not configs.intelephense then + configs.intelephense = { + default_config = { + cmd = { 'intelephense', '--stdio' }; + filetypes = { 'php' }; + root_dir = function(fname) + return vim.loop.cwd() + end; + settings = { + intelephense = { + files = { + maxSize = 1000000; + }; + environment = { + includePaths = { + "/home/serii/Sites/wordpress", + "/home/serii/Sites/advanced-custom-fields-pro", + "/home/serii/Sites/woocommerce" + } + } + } + } + } + } +end + +lspconfig.intelephense.setup { capabilities = capabilities } + diff --git a/lua/plugin/colors.lua b/lua/plugin/colors.lua new file mode 100644 index 0000000..8b67477 --- /dev/null +++ b/lua/plugin/colors.lua @@ -0,0 +1,2 @@ +vim.cmd.colorscheme('gruvbox') + diff --git a/lua/plugin/telescope.lua b/lua/plugin/telescope.lua new file mode 100644 index 0000000..e032b39 --- /dev/null +++ b/lua/plugin/telescope.lua @@ -0,0 +1,6 @@ +local builtin = require('telescope.builtin') + +vim.keymap.set('n', 'ff', builtin.find_files, {}) +vim.keymap.set('n', 'fg', builtin.live_grep, {}) +vim.keymap.set('n', 'jj', builtin.buffers, {}) +vim.keymap.set('n', 'fh', builtin.help_tags, {}) diff --git a/lua/plugin/treesitter.lua b/lua/plugin/treesitter.lua new file mode 100644 index 0000000..b5d4da9 --- /dev/null +++ b/lua/plugin/treesitter.lua @@ -0,0 +1,8 @@ + local configs = require("nvim-treesitter.configs") + + configs.setup({ + ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "elixir", "heex", "javascript", "html" }, + sync_install = false, + highlight = { enable = true }, + indent = { enable = true }, + }) diff --git a/lua/plugins.lua b/lua/plugins.lua new file mode 100644 index 0000000..c2f07fe --- /dev/null +++ b/lua/plugins.lua @@ -0,0 +1,61 @@ +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" + +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end + +vim.opt.rtp:prepend(lazypath) + +require("lazy").setup({ + { + 'nvim-telescope/telescope.nvim', + tag = '0.1.2', + dependencies = { 'nvim-lua/plenary.nvim' } + }, + + { + "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" + }, + { + 'VonHeikemen/lsp-zero.nvim', + branch = 'v2.x', + dependencies = { + -- LSP Support + { 'neovim/nvim-lspconfig' }, -- Required + { -- Optional + 'williamboman/mason.nvim', + build = function() + pcall(vim.cmd, 'MasonUpdate') + end, + }, + { 'williamboman/mason-lspconfig.nvim' }, -- Optional + + -- Autocompletion + { 'hrsh7th/nvim-cmp' }, -- Required + { 'hrsh7th/cmp-nvim-lsp' }, -- Required + { 'L3MON4D3/LuaSnip' }, -- Required + { 'nvim-cmp' }, + { 'github/copilot.vim' }, + { 'mhinz/vim-startify' }, + -- themes + { 'gruvbox-community/gruvbox' }, + } + }, + + +}, opts) + + +local files = vim.split(vim.fn.globpath(vim.fn.stdpath('config') .. '/lua/plugin', '*.lua', true), '\n') + +for _, f in ipairs(files) do + local name = vim.fn.fnamemodify(f, ':t:r') + require('plugin.' .. name) +end diff --git a/lua/remap.lua b/lua/remap.lua new file mode 100644 index 0000000..2269117 --- /dev/null +++ b/lua/remap.lua @@ -0,0 +1,24 @@ +vim.keymap.set("n", ";;", vim.cmd.Ex) + +-- jk to escape +vim.keymap.set("i", "jk", "") + +-- allow moving line / lines in all modes with M-j/k +vim.keymap.set("n", "", ":m .+1==") +vim.keymap.set("n", "", ":m .-2==") +vim.keymap.set("i", "", ":m .+1==gi") +vim.keymap.set("i", "", ":m .-2==gi") +vim.keymap.set("v", "", ":m '>+1gv=gv") +vim.keymap.set("v", "", ":m '<-2gv=gv") + +-- C-x to close buffer +vim.keymap.set("n", "", ":bd") + +-- C-l / C-h to go to nex / previouse buffer +vim.keymap.set("n", "", ":bn") +vim.keymap.set("n", "", ":bp") + +-- leader-t-space 2 to set expandtab, shiftwidth, softtabstop to 2 +vim.keymap.set("n", "t2", ":set expandtab shiftwidth=2 softtabstop=2") +vim.keymap.set("n", "t4", ":set expandtab shiftwidth=4 softtabstop=4") +vim.keymap.set("n", "t", ":set noexpandtab shiftwidth=4 softtabstop=4") diff --git a/lua/set.lua b/lua/set.lua new file mode 100644 index 0000000..2e1c50f --- /dev/null +++ b/lua/set.lua @@ -0,0 +1,33 @@ +vim.opt.guicursor = "" + +vim.opt.nu = true +vim.opt.rnu = true + +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = true + +vim.opt.smartindent = true + +vim.opt.wrap = false +vim.opt.list = true + +vim.opt.swapfile = false + +vim.opt.backup = false +vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir" +vim.opt.undofile = true + +vim.opt.hlsearch = true +vim.opt.incsearch = true + +vim.opt.termguicolors = true + +vim.opt.scrolloff = 8 +vim.opt.signcolumn = "yes" + +vim.opt.updatetime = 50 + +-- use system clipboard +vim.opt.clipboard = "unnamedplus"