diff --git a/dot_config/nvim/.keep b/dot_config/nvim/.keep new file mode 100644 index 0000000..e69de29 diff --git a/dot_config/nvim/ftdetect/.keep b/dot_config/nvim/ftdetect/.keep new file mode 100644 index 0000000..e69de29 diff --git a/dot_config/nvim/ftdetect/zinc.vim b/dot_config/nvim/ftdetect/zinc.vim new file mode 100644 index 0000000..b714396 --- /dev/null +++ b/dot_config/nvim/ftdetect/zinc.vim @@ -0,0 +1,3 @@ +autocmd BufNewFile,BufRead *.mzn set filetype=zinc +autocmd BufNewFile,BufRead *.fzn set filetype=zinc +autocmd BufNewFile,BufRead *.dzn set filetype=zinc diff --git a/dot_config/nvim/init.lua b/dot_config/nvim/init.lua new file mode 100644 index 0000000..3737f2b --- /dev/null +++ b/dot_config/nvim/init.lua @@ -0,0 +1,79 @@ +local install_path = vim.fn.stdpath('data')..'/site/pack/packer/opt/packer.nvim' + +if vim.fn.empty(vim.fn.glob(install_path)) > 0 then + vim.fn.system({'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path}) + vim.api.nvim_command('packadd packer.nvim') +end + +require('packer').startup(function() + local use = require('packer').use + -- Package manager (Self update) + use 'wbthomason/packer.nvim' + -- General Editing + use 'b3nj5m1n/kommentary' -- 'gc' to comment visual regions/lines + use { + 'Konfekt/vim-sentence-chopper', -- 'gw' to split using sentences + config = function() vim.g.latexindent = false end, -- "gw" should not use latexindent + } + use 'beauwilliams/focus.nvim' -- Automatically resize based on focused window + -- Appearance + use { + 'cormacrelf/dark-notify', -- Automatic theme switching + requires = { + 'hoob3rt/lualine.nvim', -- Status line + 'rose-pine/neovim', -- Theme + }, + config = require('plugins.appearance').conf_theme, + } + use { + 'lukas-reineke/indent-blankline.nvim', -- Add indentation guides even on blank lines + config = require('plugins.appearance').conf_indent, + } + use { + 'folke/which-key.nvim', -- Show key mappings + config = function() require('plugins.keymap') end, + } +-- -- Language configuration + use { + 'neovim/nvim-lspconfig', -- Configuration of LSP + requires = { + { + 'nvim-treesitter/nvim-treesitter', + run = ':TSUpdate', + config = require('plugins.appearance').conf_treesitter, + }, + }, + config = function() + require('lang.c++') + require('lang.go') + require('lang.python') + require('lang.rust') + require('lang.tex') + require('lang.zinc') + end, + } + -- Auto-completion + use { + 'hrsh7th/nvim-cmp', + requires = { + -- Sources + 'Saecki/crates.nvim', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-nvim-lua', + 'hrsh7th/vim-vsnip', + -- Further Requirements + 'nvim-lua/plenary.nvim' + }, + config = require('plugins.completion').conf_cmp, + } + -- Component: Popup Navigation/Search + use { + 'nvim-telescope/telescope.nvim', + requires = {'nvim-lua/popup.nvim', 'nvim-lua/plenary.nvim', }, + config = require('plugins.search').conf_telescope, + } +end) + +---- Set general neovim options ---- +require 'options' diff --git a/dot_config/nvim/lua/.keep b/dot_config/nvim/lua/.keep new file mode 100644 index 0000000..e69de29 diff --git a/dot_config/nvim/lua/lang/.keep b/dot_config/nvim/lua/lang/.keep new file mode 100644 index 0000000..e69de29 diff --git a/dot_config/nvim/lua/lang/c++.lua b/dot_config/nvim/lua/lang/c++.lua new file mode 100644 index 0000000..f113e7b --- /dev/null +++ b/dot_config/nvim/lua/lang/c++.lua @@ -0,0 +1,7 @@ +local lsp_settings = require('support.lsp') +local nvim_lsp = require('lspconfig') + +nvim_lsp.clangd.setup { + on_attach = lsp_settings.on_attach, + capabilities = lsp_settings.capabilites, +} diff --git a/dot_config/nvim/lua/lang/go.lua b/dot_config/nvim/lua/lang/go.lua new file mode 100644 index 0000000..58954d7 --- /dev/null +++ b/dot_config/nvim/lua/lang/go.lua @@ -0,0 +1,9 @@ +local lsp_settings = require('support.lsp') +local nvim_lsp = require('lspconfig') + +nvim_lsp.gopls.setup { + on_attach = lsp_settings.on_attach, + capabilities = lsp_settings.capabilites, +} + +vim.cmd('autocmd Filetype go setlocal tabstop=4 shiftwidth=4') diff --git a/dot_config/nvim/lua/lang/python.lua b/dot_config/nvim/lua/lang/python.lua new file mode 100644 index 0000000..2e09f83 --- /dev/null +++ b/dot_config/nvim/lua/lang/python.lua @@ -0,0 +1,9 @@ +local lsp_settings = require('support.lsp') +local nvim_lsp = require('lspconfig') + +nvim_lsp.pylsp.setup { + on_attach = lsp_settings.on_attach, + capabilities = lsp_settings.capabilites, +} + +vim.cmd('autocmd Filetype python setlocal tabstop=4 shiftwidth=4 expandtab') diff --git a/dot_config/nvim/lua/lang/rust.lua b/dot_config/nvim/lua/lang/rust.lua new file mode 100644 index 0000000..ccee824 --- /dev/null +++ b/dot_config/nvim/lua/lang/rust.lua @@ -0,0 +1,9 @@ +local lsp_settings = require('support.lsp') +local nvim_lsp = require('lspconfig') + +nvim_lsp.rust_analyzer.setup { + on_attach = lsp_settings.on_attach, + capabilities = lsp_settings.capabilites, +} + +vim.cmd('autocmd Filetype rust setlocal tabstop=4 shiftwidth=4 expandtab') diff --git a/dot_config/nvim/lua/lang/tex.lua b/dot_config/nvim/lua/lang/tex.lua new file mode 100644 index 0000000..53ccca1 --- /dev/null +++ b/dot_config/nvim/lua/lang/tex.lua @@ -0,0 +1,7 @@ +local lsp_settings = require('support.lsp') +local nvim_lsp = require('lspconfig') + +nvim_lsp.texlab.setup { + on_attach = lsp_settings.on_attach, + capabilities = lsp_settings.capabilites, +} diff --git a/dot_config/nvim/lua/lang/zinc.lua b/dot_config/nvim/lua/lang/zinc.lua new file mode 100644 index 0000000..ea9ab3f --- /dev/null +++ b/dot_config/nvim/lua/lang/zinc.lua @@ -0,0 +1,13 @@ +local treesitter = require('nvim-treesitter.parsers') +local parser_config = treesitter.get_parser_configs() +parser_config.minizinc = { + install_info = { + url = "https://github.com/Dekker1/tree-sitter-minizinc", + branch = "develop", + files = {"src/parser.c"} + }, + filetype = "zinc", + used_by = {"mzn", "fzn", "dzn"} +} + +vim.cmd('autocmd Filetype zinc setlocal commentstring=\\%\\ %s') diff --git a/dot_config/nvim/lua/options.lua b/dot_config/nvim/lua/options.lua new file mode 100644 index 0000000..0ed4f6d --- /dev/null +++ b/dot_config/nvim/lua/options.lua @@ -0,0 +1,97 @@ +-- Incremental live completion +vim.opt.inccommand = "nosplit" + +-- Do not save when switching buffers +vim.opt.hidden = true + +-- Enable mouse mode +vim.opt.mouse = "a" + +-- Use system clipboard +vim.opt.clipboard:prepend {"unnamedplus"} + +-- Toggle to disable mouse mode and indentlines for easier paste +ToggleMouse = function() + if vim.opt.mouse == 'a' then + vim.cmd[[IndentBlanklineDisable]] + vim.opt.signcolumn='no' + vim.opt.mouse = 'v' + vim.opt.number = false + print("Mouse disabled") + else + vim.cmd[[IndentBlanklineEnable]] + vim.opt.signcolumn='yes' + vim.opt.mouse = 'a' + vim.opt.number = true + print("Mouse enabled") + end +end + +vim.api.nvim_set_keymap('n', '', 'lua ToggleMouse()', { noremap = true }) + +-- Save undo history +vim.cmd[[set undofile]] + +-- Decrease update time +vim.opt.updatetime = 250 +vim.opt.signcolumn="yes" + +-- Remap escape to leave terminal mode +vim.api.nvim_exec([[ + augroup Terminal + autocmd! + au TermOpen * tnoremap + au TermOpen * set nonu + augroup end +]], false) + +-- Enable spellcheck +-- vim.opt.spell = true +vim.opt.spelllang = "en_au,nl" + +--Make line numbers default +vim.opt.number = true +vim.opt.relativenumber = true + +-- Softwrap settings +vim.opt.breakindent = true +vim.opt.showbreak = "↪ " +vim.opt.linebreak = true + +-- Change preview window location +vim.g.splitbelow = true + +-- Highlight on yank +vim.api.nvim_exec([[ + augroup YankHighlight + autocmd! + autocmd TextYankPost * silent! lua vim.highlight.on_yank() + augroup end +]], false) + +-- Start search when you start typing +vim.opt.incsearch = true + +-- Case insensitive searching UNLESS /C or capital in search +vim.opt.ignorecase = true +vim.opt.smartcase = true + +-- Default indentation +vim.opt.shiftwidth = 2 +vim.opt.tabstop = 2 +vim.opt.smartindent = true +vim.opt.expandtab = false + +-- Save when lost focus +vim.cmd('au FocusLost * silent! wa') + +-- Map :Format to vim.lsp.buf.formatting() +vim.cmd([[ command! Format execute 'lua vim.lsp.buf.formatting()' ]]) +vim.cmd([[ + augroup format + autocmd! + autocmd BufWritePre * :Format + augroup END +]]) + +vim.cmd([[ autocmd BufWritePost ~/.local/share/chezmoi/* ! chezmoi apply --source-path % ]]) \ No newline at end of file diff --git a/dot_config/nvim/lua/plugins/.keep b/dot_config/nvim/lua/plugins/.keep new file mode 100644 index 0000000..e69de29 diff --git a/dot_config/nvim/lua/plugins/appearance.lua b/dot_config/nvim/lua/plugins/appearance.lua new file mode 100644 index 0000000..1f70bc2 --- /dev/null +++ b/dot_config/nvim/lua/plugins/appearance.lua @@ -0,0 +1,47 @@ +-- Colour Scheme configuration +local conf_theme = function() + local dn = require('dark_notify') + dn.run({ + schemes = { + dark = "rose-pine", + light = "rose-pine", + }, + onchange = function(mode) + --Set statusbar + if mode == "dark" then + require('rose-pine.functions').select_variant('moon') + else + require('rose-pine.functions').select_variant('dawn') + end + require("plenary.reload").reload_module("lualine", true) + require('lualine').setup { + options = { + icons_enabled = 0, + theme = 'rose-pine' + } + } + end, + }) +end + +local conf_indent = function() + vim.g.indent_blankline_char = "┊" -- │ is another good option + vim.g.indent_blankline_filetype_exclude = { 'help', 'packer' } + vim.g.indent_blankline_buftype_exclude = { 'terminal', 'nofile'} + vim.g.indent_blankline_char_highlight = 'LineNr' +end + +local conf_treesitter = function() + require'nvim-treesitter.configs'.setup { + ensure_installed = "maintained", + highlight = { + enable = true, -- false will disable the whole extension + }, + } +end + +return { + conf_theme = conf_theme, + conf_indent = conf_indent, + conf_treesitter = conf_treesitter, +} diff --git a/dot_config/nvim/lua/plugins/completion.lua b/dot_config/nvim/lua/plugins/completion.lua new file mode 100644 index 0000000..a8322b1 --- /dev/null +++ b/dot_config/nvim/lua/plugins/completion.lua @@ -0,0 +1,23 @@ +-- Configure nvim-cmp +local conf_cmp = function() + local cmp = require('cmp') + cmp.setup({ + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + mapping = { + [''] = cmp.mapping.confirm({ select = true }), + }, + sources = { + { name = 'buffer' }, + { name = 'crates' }, + { name = 'nvim_lua' }, + { name = 'nvim_lsp' }, + { name = 'path' }, + } + }) +end + +return { conf_cmp = conf_cmp } \ No newline at end of file diff --git a/dot_config/nvim/lua/plugins/keymap.lua b/dot_config/nvim/lua/plugins/keymap.lua new file mode 100644 index 0000000..11d68f7 --- /dev/null +++ b/dot_config/nvim/lua/plugins/keymap.lua @@ -0,0 +1,55 @@ +-- Remap space as leader key +vim.api.nvim_set_keymap('', '', '', { noremap = true, silent=true}) +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' + +-- Remap for dealing with word wrap +vim.api.nvim_set_keymap('n', 'k', "v:count == 0 ? 'gk' : 'k'", { noremap=true, expr = true, silent = true }) +vim.api.nvim_set_keymap('n', 'j', "v:count == 0 ? 'gj' : 'j'", { noremap= true, expr = true, silent = true }) + +-- Editing + -- Wrap current paragraph +vim.api.nvim_set_keymap('n', '', [[gwip]], { noremap = false }) + +-- Windows +vim.api.nvim_set_keymap('n', 'w', [[]], { noremap = true }) + +-- Define leader mappings (using which-key) +local whichkey = require("which-key") +whichkey.setup{} +local mappings = { + [""] = { "", "Reopen Last Buffer" }, + -- Buffer + b = { + name = "buffer", + b = { "lua require('telescope.builtin').buffers()", "Find Buffer" }, + d = { "bd", "Delete Buffer" }, + m = { "%bd|e#", "Delete Other Buffers" }, + y = { "ggyG", "Copy Buffer" }, + }, + -- File + f = { + name = "File", + f = { "lua require('telescope.builtin').file_browser()", "Find File" }, + s = { "write", "Store File" }, + S = { "wa", "Store All Files" }, + }, + -- Search + s = { + name = "Search", + p = { "lua require('telescope.builtin').live_grep()", "Search Project" }, + b = { "lua require('telescope.builtin').treesitter()", "Search Buffer Symbols" }, + }, + -- Project + p = { + f = { "lua require('telescope.builtin').find_files()", "Search Project" }, + }, + + -- Window + q = { + name = "Quit", + q = { "qa", "Quit"}, + }, + w = "Window", +} +whichkey.register(mappings, { prefix = "" }) diff --git a/dot_config/nvim/lua/plugins/search.lua b/dot_config/nvim/lua/plugins/search.lua new file mode 100644 index 0000000..8874904 --- /dev/null +++ b/dot_config/nvim/lua/plugins/search.lua @@ -0,0 +1,17 @@ +-- Telescope +local conf_telescope = function() + require('telescope').setup { + defaults = { + mappings = { + i = { + [""] = false, + [""] = false, + }, + }, + generic_sorter = require'telescope.sorters'.get_fzy_sorter, + file_sorter = require'telescope.sorters'.get_fzy_sorter, + } + } +end + +return { conf_telescope = conf_telescope } \ No newline at end of file diff --git a/dot_config/nvim/lua/support/.keep b/dot_config/nvim/lua/support/.keep new file mode 100644 index 0000000..e69de29 diff --git a/dot_config/nvim/lua/support/lsp.lua b/dot_config/nvim/lua/support/lsp.lua new file mode 100644 index 0000000..6e9529c --- /dev/null +++ b/dot_config/nvim/lua/support/lsp.lua @@ -0,0 +1,34 @@ +-- LSP settings +local on_attach = function(_client, bufnr) + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + local opts = { noremap=true, silent=true } + 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', 'pa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'pr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'pl', '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', 'gr', 'lua vim.lsp.buf.references()', 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', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) +end + +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities.textDocument.completion.completionItem.snippetSupport = true +capabilities.textDocument.completion.completionItem.resolveSupport = { + properties = { + 'documentation', + 'detail', + 'additionalTextEdits', + } +} + +return { on_attach = on_attach, capabilities = capabilities }