From a8c4ea36cc49479e3e3acf423271d2df39f27a3c Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Thu, 2 Jan 2025 04:46:02 +0100 Subject: [PATCH] Add neovim configuration --- .config/nvim/ftplugin/typescript.vim | 4 - .config/nvim/init.vim | 371 +++++++++++++++++++++++++++ .config/nvim/lua/lsphelp.lua | 40 +++ .gitignore | 3 +- .profile | 5 + 5 files changed, 418 insertions(+), 5 deletions(-) delete mode 100644 .config/nvim/ftplugin/typescript.vim create mode 100644 .config/nvim/init.vim create mode 100644 .config/nvim/lua/lsphelp.lua diff --git a/.config/nvim/ftplugin/typescript.vim b/.config/nvim/ftplugin/typescript.vim deleted file mode 100644 index 7df8467..0000000 --- a/.config/nvim/ftplugin/typescript.vim +++ /dev/null @@ -1,4 +0,0 @@ -setlocal et -setlocal ts=2 -setlocal sts=2 -setlocal sw=2 diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim new file mode 100644 index 0000000..b22992c --- /dev/null +++ b/.config/nvim/init.vim @@ -0,0 +1,371 @@ +set ts=4 +set sw=4 +set noet +set ignorecase +set smartcase +set ruler +set nobackup +set number +set colorcolumn=120 +set exrc +set secure +set hidden + +"set completeopt=menuone,noinsert,noselect +set completeopt=menu,menuone,noselect +set shortmess+=c +" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable +" delays and poor user experience. +set updatetime=300 +" Always show the signcolumn, otherwise it would shift the text each time +" diagnostics appear/become resolved. +" Recently vim can merge signcolumn and number column into one +set signcolumn=yes +set mouse=a " Enable mouse in all modes. + +lua << EOF +require'lsphelp' + +-- +-- Packer +-- +vim.cmd [[packadd packer.nvim]] + +require('packer').startup(function() + -- Packer can manage itself + use 'wbthomason/packer.nvim' + + use 'mfussenegger/nvim-dap' + use 'airblade/vim-gitgutter' + use 'neovim/nvim-lspconfig' + use 'dense-analysis/ale' + use 'liuchengxu/vista.vim' -- Tag bar. + + -- Git. + use 'tpope/vim-fugitive' + use { + 'sindrets/diffview.nvim', + requires = {'nvim-lua/plenary.nvim'} + } + + -- File browser. + use { + 'kyazdani42/nvim-tree.lua', + requires = {'nvim-tree/nvim-web-devicons'} -- optional, for file icon + } + use { + 'nvim-telescope/telescope.nvim', + requires = {'nvim-lua/plenary.nvim'} + } + use 'nvim-telescope/telescope-ui-select.nvim' + use { + 'kevinhwang91/nvim-ufo', + requires = {'kevinhwang91/promise-async'} + } + + -- Theme. + use 'EdenEast/nightfox.nvim' + + -- Status line. + use { + 'nvim-lualine/lualine.nvim', + requires = {'nvim-tree/nvim-web-devicons'} -- optional, for status line icons + } + + -- Syntax. + use 'leafOfTree/vim-vue-plugin' + use 'mfussenegger/nvim-jdtls' + use 'hhsnopek/vim-sugarss' + use 'dart-lang/dart-vim-plugin' + use { + 'akinsho/flutter-tools.nvim', + requires = { + 'nvim-lua/plenary.nvim' + } + } + + -- nvim-cmp + use 'dcampos/nvim-snippy' + use 'hrsh7th/cmp-nvim-lsp' + use 'hrsh7th/nvim-cmp' + use 'dcampos/cmp-snippy' + use 'hrsh7th/cmp-path' + use 'hrsh7th/cmp-buffer' +end) + +local configuration = read_configuration() + +-- +-- ALE +-- +-- Run linters only on save +vim.g.ale_lint_on_text_changed = 'never' +vim.g.ale_lint_on_insert_leave = 0 + +-- Include the linter name (e.g. 'hack' or 'hhast'), code, and message in errors +vim.g.ale_echo_msg_format = '[%linter%] %s' +vim.g.ale_linters = { + hack = {'hack', 'hhast'}, + haskell = {"hlint"}, + javascript = {'eslint'}, + d = {'dmd'}, + php = {'phpcs', 'phpstan'}, + ruby = {'rubocop'}, + cpp = {}, +} +vim.g.ale_ruby_rubocop_executable = 'bundle' +vim.g.ale_cpp_cc_options = '-std=c++17 -Wall' + +vim.g.ale_open_list = 1 +vim.g.ale_disable_lsp = 1 + +-- +-- nvim-cmp +-- +local cmp = require'cmp' + +cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + require'snippy'.expand_snippet(args.body) + end, + }, + mapping = { + [''] = 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' }), + -- Specify `cmp.config.disable` if you want to remove the default `` mapping. + [''] = cmp.config.disable, + [''] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }), + [''] = cmp.mapping.confirm({ select = false }), + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'snippy' }, + }, { + { name = 'path' }, + }, { + { name = 'buffer' }, + }), + view = { + entries = 'native', + }, +}) + +-- Setup lspconfig. +local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) +capabilities.textDocument.foldingRange = { + dynamicRegistration = false, + lineFoldingOnly = true +} + +-- +-- LSPConfig +-- +local nvim_lsp = require('lspconfig') + +-- Mappings. +-- See `:help vim.diagnostic.*` for documentation on any of the below functions +local opts = { noremap=true, silent=true } +vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) +vim.keymap.set('n', 'q', vim.diagnostic.setloclist, opts) + +nvim_lsp['hls'].setup { + on_attach = default_on_attach, + capabilities = capabilities, + flags = { + debounce_text_changes = 150, + }, + settings = { + haskell = { + plugin = { + stan = { + globalOn = false + } + } + } + } +} +nvim_lsp['intelephense'].setup { + on_attach = default_on_attach, + flags = { + debounce_text_changes = 150, + }, + init_options = { + licenceKey = configuration.intelephenseKey, + storagePath = '/tmp/intelephense', + }, + capabilities = capabilities, + settings = { + intelephense = { + environment = { + phpVersion = '8.2.0' + } + } + } +} +nvim_lsp['clangd'].setup { + on_attach = default_on_attach, + capabilities = capabilities +} +require("flutter-tools").setup { + outline = { + open_cmd = "Vista" + }, + lsp = { + on_attach = default_on_attach, + capabilities = capabilities + } +} +nvim_lsp['twiggy_language_server'].setup { + on_attach = default_on_attach, + capabilities = capabilities, + settings = { + twiggy = { + framework = 'symfony', + phpExecutable = '/usr/bin/php', + symfonyConsolePath = 'bin/console', + diagnostics = { + twigCsFixer = false + } + } + } +} +vim.g.vim_vue_plugin_config = { + syntax = { + template = {'html'}, + script = {'javascript'}, + style = {'css'}, + }, + full_syntax = {}, + initial_indent = {}, + attribute = 0, + keyword = 0, + foldexpr = 0, + debug = 0 +} + +-- +-- Telescope +-- +require('telescope').setup { + extensions = { + ["ui-select"] = { + require("telescope.themes").get_dropdown { + } + } + } +} +require("telescope").load_extension("ui-select") + +vim.api.nvim_set_keymap('n', 'ff', "lua require('telescope.builtin').find_files()", + { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'fg', "lua require('telescope.builtin').live_grep()", + { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'fb', "lua require('telescope.builtin').buffers()", + { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'fh', "lua require('telescope.builtin').help_tags()", + { noremap = true, silent = true }) + +-- +-- NvimTree +-- +require('nvim-tree').setup {} + +vim.api.nvim_set_keymap('n', '', ':NvimTreeToggle', { noremap = true }) +vim.api.nvim_set_keymap('n', 'r', ':NvimTreeRefresh', { noremap = true }) +vim.api.nvim_set_keymap('n', 'n', ':NvimTreeFindFile', { noremap = true }) + +-- +-- Theme +-- +vim.cmd('colorscheme duskfox') +vim.opt.termguicolors = true + +-- +-- Lualine +-- +require('lualine').setup { + options = { + theme = 'codedark' + }, + extensions = {'quickfix', 'nvim-tree', 'fugitive'}, + sections = { + lualine_c = { + 'filename' + } + } +} + +-- +-- Diffview.nvim +-- +require('diffview').setup {} + +-- +-- Vista +-- +vim.g.vista_default_executive = 'nvim_lsp' + +-- +-- nvim-ufo +-- +vim.wo.foldcolumn = '1' +vim.wo.foldlevel = 99 -- feel free to decrease the value +vim.wo.foldenable = true + +require('ufo').setup() + +-- +-- nvim-dap +-- +vim.keymap.set('n', '', function() require('dap').continue() end) +vim.keymap.set('n', '', function() require('dap').step_over() end) +vim.keymap.set('n', '', function() require('dap').step_into() end) +vim.keymap.set('n', '', function() require('dap').step_out() end) +vim.keymap.set('n', 'b', function() require('dap').toggle_breakpoint() end) +vim.keymap.set('n', 'B', function() require('dap').set_breakpoint() end) +vim.keymap.set('n', 'lp', function() require('dap').set_breakpoint(nil, nil, vim.fn.input('Log point message: ')) end) +vim.keymap.set('n', 'dr', function() require('dap').repl.open() end) +vim.keymap.set('n', 'dl', function() require('dap').run_last() end) +vim.keymap.set({'n', 'v'}, 'dh', function() + require('dap.ui.widgets').hover() +end) +vim.keymap.set({'n', 'v'}, 'dp', function() + require('dap.ui.widgets').preview() +end) +vim.keymap.set('n', 'df', function() + local widgets = require('dap.ui.widgets') + widgets.centered_float(widgets.frames) +end) +vim.keymap.set('n', 'ds', function() + local widgets = require('dap.ui.widgets') + widgets.centered_float(widgets.scopes) +end) + +local dap = require("dap") +dap.adapters.gdb = { + type = "executable", + command = "gdb", + args = { "-i", "dap" } +} +dap.configurations.cpp = { + { + name = "Launch", + type = "gdb", + request = "launch", + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') + end, + cwd = "${workspaceFolder}", + stopAtBeginningOfMainSubprogram = false, + }, +} + +EOF diff --git a/.config/nvim/lua/lsphelp.lua b/.config/nvim/lua/lsphelp.lua new file mode 100644 index 0000000..77cd586 --- /dev/null +++ b/.config/nvim/lua/lsphelp.lua @@ -0,0 +1,40 @@ +-- Helper function for creating keymaps. +function nnoremap(rhs, lhs, desc) + local bufopts = { noremap=true, silent=true, buffer=bufnr, desc = desc } + + vim.keymap.set("n", rhs, lhs, bufopts) +end + +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +function default_on_attach(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 + nnoremap('gD', vim.lsp.buf.declaration, "Go to declaration") + nnoremap('gd', vim.lsp.buf.definition, "Go to definition") + nnoremap('K', vim.lsp.buf.hover, "Hover text") + nnoremap('gi', vim.lsp.buf.implementation, "Go to implementation") + nnoremap('', vim.lsp.buf.signature_help, "Show signature") + nnoremap('wa', vim.lsp.buf.add_workspace_folder, "Add workspace folder") + nnoremap('wr', vim.lsp.buf.remove_workspace_folder, "Remove workspace folder") + nnoremap('wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, "List workspace folders") + nnoremap('D', vim.lsp.buf.type_definition, "Go to type definition") + nnoremap('rn', vim.lsp.buf.rename, "Rename") + nnoremap('ca', vim.lsp.buf.code_action, "Code actions") + nnoremap('gr', vim.lsp.buf.references, "Find references") + nnoremap('f', function() vim.lsp.buf.format { async = true } end, "Format file") +end + +function read_configuration() + local configuration = {} + local chunk, err = loadfile(os.getenv('HOME') .. '/.config/nvim/config', 't', configuration) + if chunk then + chunk() + end + return configuration +end diff --git a/.gitignore b/.gitignore index c2658d7..2422663 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules/ +.config/nvim/config +.config/nvim/plugin/ diff --git a/.profile b/.profile index b2164c6..3f06335 100755 --- a/.profile +++ b/.profile @@ -14,6 +14,11 @@ else export SSH_AUTH_SOCK=/run/user/1000/keyring/ssh fi +if [ -d /opt/homebrew/opt/php@8.3 ] +then + PATH="/opt/homebrew/opt/php@8.3/bin:/opt/homebrew/opt/php@8.3/sbin:$PATH" +fi + if [ -d "$HOME/Android/Sdk" ] then export ANDROID_HOME="$HOME/Android/Sdk"