Add neovim configuration
This commit is contained in:
parent
ca857be064
commit
1444677e9c
0
dot_config/nvim/.keep
Normal file
0
dot_config/nvim/.keep
Normal file
0
dot_config/nvim/ftdetect/.keep
Normal file
0
dot_config/nvim/ftdetect/.keep
Normal file
3
dot_config/nvim/ftdetect/zinc.vim
Normal file
3
dot_config/nvim/ftdetect/zinc.vim
Normal file
@ -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
|
79
dot_config/nvim/init.lua
Normal file
79
dot_config/nvim/init.lua
Normal file
@ -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'
|
0
dot_config/nvim/lua/.keep
Normal file
0
dot_config/nvim/lua/.keep
Normal file
0
dot_config/nvim/lua/lang/.keep
Normal file
0
dot_config/nvim/lua/lang/.keep
Normal file
7
dot_config/nvim/lua/lang/c++.lua
Normal file
7
dot_config/nvim/lua/lang/c++.lua
Normal file
@ -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,
|
||||
}
|
9
dot_config/nvim/lua/lang/go.lua
Normal file
9
dot_config/nvim/lua/lang/go.lua
Normal file
@ -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')
|
9
dot_config/nvim/lua/lang/python.lua
Normal file
9
dot_config/nvim/lua/lang/python.lua
Normal file
@ -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')
|
9
dot_config/nvim/lua/lang/rust.lua
Normal file
9
dot_config/nvim/lua/lang/rust.lua
Normal file
@ -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')
|
7
dot_config/nvim/lua/lang/tex.lua
Normal file
7
dot_config/nvim/lua/lang/tex.lua
Normal file
@ -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,
|
||||
}
|
13
dot_config/nvim/lua/lang/zinc.lua
Normal file
13
dot_config/nvim/lua/lang/zinc.lua
Normal file
@ -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')
|
97
dot_config/nvim/lua/options.lua
Normal file
97
dot_config/nvim/lua/options.lua
Normal file
@ -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', '<F10>', '<cmd>lua ToggleMouse()<cr>', { 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 <buffer> <Esc> <c-\><c-n>
|
||||
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 % ]])
|
0
dot_config/nvim/lua/plugins/.keep
Normal file
0
dot_config/nvim/lua/plugins/.keep
Normal file
47
dot_config/nvim/lua/plugins/appearance.lua
Normal file
47
dot_config/nvim/lua/plugins/appearance.lua
Normal file
@ -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,
|
||||
}
|
23
dot_config/nvim/lua/plugins/completion.lua
Normal file
23
dot_config/nvim/lua/plugins/completion.lua
Normal file
@ -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 = {
|
||||
['<C-y>'] = cmp.mapping.confirm({ select = true }),
|
||||
},
|
||||
sources = {
|
||||
{ name = 'buffer' },
|
||||
{ name = 'crates' },
|
||||
{ name = 'nvim_lua' },
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'path' },
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
return { conf_cmp = conf_cmp }
|
55
dot_config/nvim/lua/plugins/keymap.lua
Normal file
55
dot_config/nvim/lua/plugins/keymap.lua
Normal file
@ -0,0 +1,55 @@
|
||||
-- Remap space as leader key
|
||||
vim.api.nvim_set_keymap('', '<Space>', '<Nop>', { 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', '<M-q>', [[gwip]], { noremap = false })
|
||||
|
||||
-- Windows
|
||||
vim.api.nvim_set_keymap('n', '<leader>w', [[<C-w>]], { noremap = true })
|
||||
|
||||
-- Define leader mappings (using which-key)
|
||||
local whichkey = require("which-key")
|
||||
whichkey.setup{}
|
||||
local mappings = {
|
||||
["<tab>"] = { "<C-^>", "Reopen Last Buffer" },
|
||||
-- Buffer
|
||||
b = {
|
||||
name = "buffer",
|
||||
b = { "<cmd>lua require('telescope.builtin').buffers()<cr>", "Find Buffer" },
|
||||
d = { "<cmd>bd<cr>", "Delete Buffer" },
|
||||
m = { "<cmd>%bd|e#<cr>", "Delete Other Buffers" },
|
||||
y = { "ggyG<C-o>", "Copy Buffer" },
|
||||
},
|
||||
-- File
|
||||
f = {
|
||||
name = "File",
|
||||
f = { "<cmd>lua require('telescope.builtin').file_browser()<cr>", "Find File" },
|
||||
s = { "<cmd>write<cr>", "Store File" },
|
||||
S = { "<cmd>wa<cr>", "Store All Files" },
|
||||
},
|
||||
-- Search
|
||||
s = {
|
||||
name = "Search",
|
||||
p = { "<cmd>lua require('telescope.builtin').live_grep()<cr>", "Search Project" },
|
||||
b = { "<cmd>lua require('telescope.builtin').treesitter()<cr>", "Search Buffer Symbols" },
|
||||
},
|
||||
-- Project
|
||||
p = {
|
||||
f = { "<cmd>lua require('telescope.builtin').find_files()<cr>", "Search Project" },
|
||||
},
|
||||
|
||||
-- Window
|
||||
q = {
|
||||
name = "Quit",
|
||||
q = { "<cmd>qa<cr>", "Quit"},
|
||||
},
|
||||
w = "Window",
|
||||
}
|
||||
whichkey.register(mappings, { prefix = "<leader>" })
|
17
dot_config/nvim/lua/plugins/search.lua
Normal file
17
dot_config/nvim/lua/plugins/search.lua
Normal file
@ -0,0 +1,17 @@
|
||||
-- Telescope
|
||||
local conf_telescope = function()
|
||||
require('telescope').setup {
|
||||
defaults = {
|
||||
mappings = {
|
||||
i = {
|
||||
["<C-u>"] = false,
|
||||
["<C-d>"] = false,
|
||||
},
|
||||
},
|
||||
generic_sorter = require'telescope.sorters'.get_fzy_sorter,
|
||||
file_sorter = require'telescope.sorters'.get_fzy_sorter,
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
return { conf_telescope = conf_telescope }
|
0
dot_config/nvim/lua/support/.keep
Normal file
0
dot_config/nvim/lua/support/.keep
Normal file
34
dot_config/nvim/lua/support/lsp.lua
Normal file
34
dot_config/nvim/lua/support/lsp.lua
Normal file
@ -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', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>pa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>pr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>pl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', 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 }
|
Loading…
x
Reference in New Issue
Block a user