added neovim config

This commit is contained in:
Jef Roosens 2025-01-28 11:05:04 +01:00
commit 84afb34cee
Signed by: Jef Roosens
GPG key ID: 21FD3D77D56BAF49
21 changed files with 3105 additions and 0 deletions

View file

@ -0,0 +1,74 @@
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.
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end,
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end)
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
-- { name = 'vsnip' }, -- For vsnip users.
{ name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = 'buffer' },
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git).
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})

View file

@ -0,0 +1,28 @@
local g = vim.g
g.coq_settings = {
auto_start = "shut-up",
keymap = { recommended = false }
}
vim.api.nvim_set_keymap("i", "<Tab>", 'pumvisible() ? "\\<C-n>" : "\\<Tab>"', {
expr = true
})
vim.api.nvim_set_keymap("i", "<S-Tab>", 'pumvisible() ? "\\<C-p>" : "\\<S-Tab>"', {
expr = true
})
--Set completeopt to have a better completion experience
vim.o.completeopt = "menuone,noinsert,noselect"
--Avoid showing message extra message when using completion
vim.o.shortmess = vim.o.shortmess .. "c"
vim.g.completion_chain_complete_list = {
default = {
{ complete_items = { 'lsp', "buffer", "buffers" } },
{ mode = { '<c-p>' } },
{ mode = { '<c-n>' } }
},
}

View file

@ -0,0 +1,15 @@
local g = vim.g
g.ctrlp_map = "<leader>t"
-- g.ctrlp_use_caching = 1
-- g.ctrlp_clear_cache_on_exit = 0
-- g.ctrlp_cache_dir = "./.vim/cache/ctrlp"
g.ctrlp_user_command = {
'.git', 'git --git-dir=%s/.git ls-files -oc --exclude-standard'
}
--Limit max number of files
--This prevents me from indexing my entire HOME by accident
g.ctrlp_max_files = 1000
--Also limit recursion depth
g.ctrlp_max_depth = 10

View file

@ -0,0 +1,7 @@
-- tpope/vim-fugitive
nmap("<leader>gg", ":Git<CR>")
nmap("<leader>gc", ":Git commit<CR>")
nmap("<leader>gp", ":Git push<CR>")
nmap("<leader>gd", ":Gdiffsplit!<CR>")
nmap("<leader>gm", ":Git mergetool<CR>")
nmap("<leader>gb", ":Git blame<CR>")

View file

@ -0,0 +1,3 @@
local g = vim.g
g.gitgutter_map_keys = 0

View file

@ -0,0 +1,75 @@
-- neovim/neovim-lspconfig
local function on_attach(client, bufnr)
local opts = {
silent = true,
noremap = true,
}
local function buf_nmap(mapping, cmd) vim.api.nvim_buf_set_keymap(bufnr, "n", mapping, cmd, opts) end
-- Jump to definition
buf_nmap("gd", "<Cmd>lua vim.lsp.buf.definition()<CR>")
-- Format current buffer on write
vim.api.nvim_command([[autocmd BufWritePre <buffer> lua vim.lsp.buf.format()]])
-- Show diagnostics for current line
buf_nmap("<leader>dd", "<Cmd>lua vim.diagnostic.open_float()<CR>")
-- Jump between diagnostic messages
buf_nmap("<leader>dj", "<Cmd>lua vim.diagnostic.goto_next()<CR>")
buf_nmap("<leader>dk", "<Cmd>lua vim.diagnostic.goto_prev()<CR>")
-- Rename symbol under cursor
buf_nmap("<leader>dr", "<Cmd>lua vim.lsp.buf.rename()<CR>")
-- Show hover info
buf_nmap("<leader>df", "<Cmd>lua vim.lsp.buf.hover()<CR>")
buf_nmap("<leader>du", "<Cmd>lua vim.lsp.buf.references()<CR>")
buf_nmap("<leader>da", "<Cmd>lua vim.lsp.buf.code_action()<CR>")
end
-- For cmp autocomplete
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- Comes with clang
require'lspconfig'.clangd.setup{on_attach = on_attach, capabilities = capabilities}
-- NPM: dockerfile-language-server-nodejs
require'lspconfig'.dockerls.setup{capabilities = capabilities}
-- Pacman: haskell-language-server
-- AUR: haskell-language-server-bin
-- GH: https://github.com/haskell/haskell-language-server
require'lspconfig'.hls.setup{
on_attach = on_attach,
settings = {
haskell = {
formattingProvider = "stylish-haskell"
}
},
capabilities = capabilities
}
-- Pacman: vieter-vls (requires my Vieter repository)
-- GH: https://github.com/vlang/vls
-- require'lspconfig'.vls.setup{
-- cmd = {'vls'},
-- filetypes = {'v'},
-- on_attach = on_attach
-- }
-- Pacman: rust-analyzer
-- GH: https://github.com/rust-analyzer/rust-analyzer
require'lspconfig'.rust_analyzer.setup{on_attach = on_attach, capabilities = capabilities}
-- Installed using R shell:
-- `install.packages('languageserver')`
-- GH: https://github.com/REditorSupport/languageserver
require'lspconfig'.r_language_server.setup{capabilities = capabilities}
-- Installed using Go CLI:
-- go install github.com/nametake/golangci-lint-langserver@latest
-- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
require'lspconfig'.gopls.setup{on_attach = on_attach, capabilities = capabilities}
require'lspconfig'.texlab.setup{on_attach = on_attach, capabilities = capabilities}
-- Fix that stops rust-analyzer interrupting typing when a request is cancelled
for _, method in ipairs({ 'textDocument/diagnostic', 'workspace/diagnostic' }) do
local default_diagnostic_handler = vim.lsp.handlers[method]
vim.lsp.handlers[method] = function(err, result, context, config)
if err ~= nil and err.code == -32802 then
return
end
return default_diagnostic_handler(err, result, context, config)
end
end

View file

@ -0,0 +1,30 @@
local g = vim.g
g.NERDTreeIgnore = {
'^\\.vim$[[dir]]',
'^\\.vscode$[[dir]]', '.*\\.code-workspace$[[file]]', '^\\.idea$[[dir]]',
'^__pycache__$[[dir]]', '^\\.pytest_cache$[[dir]]', '^venv$[[dir]]',
'\\.egg-info$[[dir]]', '^dist$[[dir]]',
'^\\.eggs$[[dir]]',
'^out$[[dir]]',
'^\\.git$[[dir]]',
'^\\.stack-work$[[dir]]', '\\.lock$',
'^CMakeFiles$[[dir]]', '^CMakeCache.txt$[[file]]',
'.pdf$[[file]]',
'^node_modules$[[dir]]',
'\\.o$'
}
g.NERDTreeShowHidden = 1
g.NERDTreeMinimalUI = 1
g.NERDTreeDirArrows = 1
g.NERDTreeQuitOnOpen = 1
g.NERDTreeChDirMode = 0
g.NERDTreeNaturalSort = 1
g.NERDTreeShowFiles = 1
g.NERDTreeShowLineNumbers = 0
g.NERDTreeWinPos = 'left'
g.NERDTreeMinimalMenu = 1
g.NERDTreeAutoDeleteBuffer = 1
nmap("tt", ":NERDTreeFind<CR>")

View file

@ -0,0 +1,12 @@
local g = vim.g
g.tagbar_map_nexttag = "J"
g.tagbar_map_prevtag = "K"
g.tagbar_map_showproto = "u"
g.tagbar_sort = 0
g.tagbar_compact = 1
g.tagbar_autoshowtag = 1
g.no_status_line = 1
g.tagbar_autoclose = 1
nmap("tr", ":TagbarToggle<CR>")

View file

@ -0,0 +1,25 @@
vim.o.hidden = true
require("toggleterm").setup {
-- open_mapping = "<leader>r",
direction = "float",
insert_mappings = false,
start_in_insert = false
}
local Terminal = require('toggleterm.terminal').Terminal
local always_visible = Terminal:new{
direction = "horizontal",
count = 6
}
function _always_visible_toggle()
always_visible:toggle()
end
nmap("<leader>rr", ":1ToggleTerm<CR>")
nmap("<leader>ry", ":2ToggleTerm<CR>")
nmap("<leader>ru", ":3ToggleTerm<CR>")
nmap("<leader>ri", ":4ToggleTerm<CR>")
nmap("<leader>ro", ":5ToggleTerm<CR>")
nmap("<leader>rp", "<cmd>lua _always_visible_toggle()<CR>")

View file

@ -0,0 +1,5 @@
require"nvim-treesitter.configs".setup {
highlight = { enable = true }
}
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.v = {}

View file

@ -0,0 +1,60 @@
imap("jk", "<Esc>")
vim.api.nvim_exec("inoremap <Esc> <nop>", false)
-- Navigate splits
nmap("<leader>h", ":wincmd h<CR>")
nmap("<leader>j", ":wincmd j<CR>")
nmap("<leader>k", ":wincmd k<CR>")
nmap("<leader>l", ":wincmd l<CR>")
-- Just some laziness
nmap("<leader>w", ":w<CR>")
nmap("<leader>q", ":q<CR>")
-- As I don't use arrow keys for navigation, I use them for resizing
nmap("<Up>", ":resize +5<CR>")
nmap("<Down>", ":resize -5<CR>")
nmap("<Right>", ":vertical resize +5<CR>")
nmap("<Left>", ":vertical resize -5<CR>")
nmap("<S-Up>", ":resize +1<CR>")
nmap("<S-Down>", ":resize -1<CR>")
nmap("<S-Right>", ":vertical resize +1<CR>")
nmap("<S-Left>", ":vertical resize -1<CR>")
-- Disable arrow keys in editing & visual mode, as I have no need for them
imap("<Up>", "<nop>")
imap("<Down>", "<nop>")
imap("<Left>", "<nop>")
imap("<Right>", "<nop>")
vmap("<Up>", "<nop>")
vmap("<Down>", "<nop>")
vmap("<Left>", "<nop>")
vmap("<Right>", "<nop>")
-- These bindings I use for managing tabs
nmap("<leader>ee", ":$tabnew<CR>")
nmap("<leader>eL", ":tabnew<CR>")
nmap("<leader>eH", ":-tabnew<CR>")
nmap("<leader>ed", ":tabclose<CR>")
nmap("<leader>el", ":tabnext<CR>")
nmap("<leader>eh", ":tabprevious<CR>")
nmap("<leader>er", ":tabnew<CR>:e term://$SHELL<CR>i")
-- TODO add config editing keybinds
nmap("<leader>a", "<C-^>")
tmap("jk", "<C-\\><C-n>")
-- nmap("<leader>rr", ":e term://$SHELL<CR>")
-- nmap("<leader>rh", ":vsp<CR>:wincmd h<CR>:e term://$SHELL<CR>")
-- nmap("<leader>rl", ":vsp<CR>:e term://$SHELL<CR>")
-- nmap("<leader>rk", ":sp<CR>:wincmd k<CR>:e term://$SHELL<CR>")
-- nmap("<leader>rj", ":sp<CR>:e term://$SHELL<CR>")
nmap("<leader>fh", ":vsp<CR>:wincmd h<CR>")
nmap("<leader>fj", ":sp<CR>")
nmap("<leader>fk", ":sp<CR>:wincmd k<CR>")
nmap("<leader>fl", ":vsp<CR>")
vim.api.nvim_set_keymap("n", "gb", "<C-o>", {})

View file

@ -0,0 +1,212 @@
local function bootstrap_pckr()
local pckr_path = vim.fn.stdpath("data") .. "/pckr/pckr.nvim"
if not vim.uv.fs_stat(pckr_path) then
vim.fn.system({
'git',
'clone',
"--filter=blob:none",
'https://github.com/lewis6991/pckr.nvim',
pckr_path
})
end
vim.opt.rtp:prepend(pckr_path)
end
bootstrap_pckr()
require('pckr').add{
{
"tpope/vim-fugitive",
config = function()
require('config.fugitive')
end
},
{
"ctrlpvim/ctrlp.vim",
config_pre = function()
require('config.ctrlp')
end
},
"tpope/vim-commentary",
{
"preservim/nerdtree",
config = function()
require('config.nerdtree')
end
},
"jiangmiao/auto-pairs",
"editorconfig/editorconfig-vim",
{
"marko-cerovac/material.nvim",
config = function()
vim.cmd("colorscheme material")
-- color material
nmap("<leader>c", [[<Cmd>lua require('material.functions').toggle_style()<CR>]])
end
},
{
'hrsh7th/nvim-cmp',
config = function()
require('config.cmp')
end
},
{
'hrsh7th/cmp-nvim-lsp',
requires = 'hrsh7th/nvim-cmp'
},
{
'hrsh7th/cmp-buffer',
requires = 'hrsh7th/nvim-cmp'
},
{
'hrsh7th/cmp-path',
requires = 'hrsh7th/nvim-cmp'
},
{
'hrsh7th/cmp-cmdline',
requires = 'hrsh7th/nvim-cmp'
},
{
"neovim/nvim-lspconfig",
requires = 'hrsh7th/cmp-nvim-lsp',
config = function()
require('config.lspconfig')
end
},
{
"nvim-treesitter/nvim-treesitter",
run = ":TSUpdate",
config = function()
require("config.treesitter")
end
},
-- Toggleable terminals
{
"akinsho/toggleterm.nvim",
config = function()
require('config.toggleterm')
end
},
-- {
-- "ms-jpq/coq_nvim",
-- config = "config.coq"
-- },
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
"godlygeek/tabular"
}
-- require('pckr').add({
-- use "wbthomason/packer.nvim"
-- -- Improves boot times
-- -- use {"lewis6991/impatient.nvim", rocks = 'mpack'}
--
-- -- Fuzzy search engine
-- use {
-- "ctrlpvim/ctrlp.vim",
-- setup = [[require('config.ctrlp')]]
-- }
--
-- -- Git client
-- use {
-- "tpope/vim-fugitive",
-- config = [[require('config.fugitive')]]
-- }
--
-- -- Shortcuts for commenting out code
-- use "tpope/vim-commentary"
--
-- -- Shortcuts for surrounding pieces of text
-- use "tpope/vim-surround"
--
-- -- Shows ctags in a sidebar
-- use {
-- "majutsushi/tagbar",
-- config = [[require('config.tagbar')]]
-- }
--
-- -- Shows git diff markers
-- use {
-- "airblade/vim-gitgutter",
-- config = [[require('config.gitgutter')]]
-- }
--
-- use "hynek/vim-python-pep8-indent"
-- use "michaeljsmith/vim-indent-object"
--
-- -- File explorer
-- use {
-- "preservim/nerdtree",
-- config = [[require('config.nerdtree')]]
-- }
--
-- use "jiangmiao/auto-pairs"
--
-- -- Align text
-- use "godlygeek/tabular"
--
-- -- Automatically load a .editorconfig file if found
-- use "editorconfig/editorconfig-vim"
--
-- -- Pre-configured LSP stuff
-- use {
-- "neovim/nvim-lspconfig",
-- config = [[require('config.lspconfig')]]
-- }
--
-- -- Beautiful treesitter-compatible theme
-- use {
-- "marko-cerovac/material.nvim",
-- config = function()
-- vim.cmd("colorscheme material")
-- -- color material
-- nmap("<leader>c", [[<Cmd>lua require('material.functions').toggle_style()<CR>]])
-- end
-- }
--
-- use 'hrsh7th/cmp-nvim-lsp'
-- use 'hrsh7th/cmp-buffer'
-- use 'hrsh7th/cmp-path'
-- use 'hrsh7th/cmp-cmdline'
-- use {
-- 'hrsh7th/nvim-cmp',
-- config = [[require('config.cmp')]]
-- }
--
-- use 'L3MON4D3/LuaSnip'
-- use 'saadparwaiz1/cmp_luasnip'
--
--
-- -- Autocomplete engine
-- -- use {
-- -- "ms-jpq/coq_nvim",
-- -- branch = "coq",
-- -- config = [[require('config.coq')]]
-- -- }
--
-- -- Better syntax highlighting
-- use {
-- "nvim-treesitter/nvim-treesitter",
-- run = ":TSUpdate",
-- config = [[require('config.treesitter')]]
-- }
--
-- -- Toggleable terminals
-- use {
-- "akinsho/toggleterm.nvim",
-- config = [[require('config.toggleterm')]]
-- }
--
-- -- LaTeX editing
-- use "lervag/vimtex"
--
-- -- Coq stuff for uni
-- use "whonore/Coqtail"
--
-- if packer_bootstrap then
-- require('packer').sync()
-- end
-- end)

View file

@ -0,0 +1,59 @@
local o = vim.o
local g = vim.g
g.mapleader = " "
g.maplocalleader = "\\<tab>"
-- I often use non-standard shells that don't play nicely wiht certain features
-- o.shell = "/bin/bash"
-- Centers your cursor whenever possible
-- 999 is just a really large number (I think it's amount of lines or something)
o.scrolloff = 999
-- Forces Neovim to assume a 256-color terminal; required for certain colorschemes
o.termguicolors = true
-- Set the colorscheme
-- g.colors_name = "flattened_dark"
-- This combo shows the absolute line number on the current line & the relative one on all the others
o.number = true
o.relativenumber = true
-- Opens new files to the bottom, right resp. of the current buffer
o.splitbelow = true
o.splitright = true
-- Converts tabs to 4 spaces
o.expandtab = true
o.tabstop = 4
o.shiftwidth = 4
-- Show search matches as I'm typing
o.incsearch = true
-- Makes search case-sensitive only when using caps
o.smartcase = true
-- Don't highlight search results after search is finished
o.hlsearch = false
local swap_dir = vim.fn.stdpath('data') .. '/swap'
local undo_dir = vim.fn.stdpath('data') .. '/undo'
-- Create swap files
o.swapfile = true
-- Where to store the swap files; I store mine in the current directory
o.directory = swap_dir
o.backup = false
o.undofile = true
o.undodir = undo_dir
o.updatetime = 250
o.shelltemp = false
-- o.completeopt = "menuone,noselect"
vim.cmd([[autocmd BufRead,BufNewFile *.v,*.vsh setlocal filetype=v]])
-- vim.cmd([[autocmd BufWritePre *.go,*.rs lua vim.lsp.buf.format()]])

View file

@ -0,0 +1,11 @@
function map(mode, keys, command)
vim.api.nvim_set_keymap(mode, keys, command, {
silent = true,
noremap = true
})
end
nmap = function(keys, command) map("n", keys, command) end
imap = function(keys, command) map("i", keys, command) end
vmap = function(keys, command) map("v", keys, command) end
tmap = function(keys, command) map("t", keys, command) end