summaryrefslogtreecommitdiff
path: root/home/config/nvim
diff options
context:
space:
mode:
Diffstat (limited to 'home/config/nvim')
-rw-r--r--home/config/nvim/init.lua7
-rw-r--r--home/config/nvim/lua/keybinds.lua22
-rw-r--r--home/config/nvim/lua/lsp.lua94
-rw-r--r--home/config/nvim/lua/lspconfig/prolog_lsp.lua21
-rw-r--r--home/config/nvim/lua/menu.lua233
-rw-r--r--home/config/nvim/lua/plugin.lua45
-rw-r--r--home/config/nvim/lua/theme.lua68
-rw-r--r--home/config/nvim/lua/tree.lua120
-rw-r--r--home/config/nvim/lua/treesitter.lua32
-rw-r--r--home/config/nvim/lua/vimopt.lua32
10 files changed, 674 insertions, 0 deletions
diff --git a/home/config/nvim/init.lua b/home/config/nvim/init.lua
new file mode 100644
index 0000000..fd623bf
--- /dev/null
+++ b/home/config/nvim/init.lua
@@ -0,0 +1,7 @@
+require('plugin')
+require('theme')
+require('vimopt')
+require('tree')
+require('keybinds')
+require('treesitter')
+require('lsp')
diff --git a/home/config/nvim/lua/keybinds.lua b/home/config/nvim/lua/keybinds.lua
new file mode 100644
index 0000000..c5732b5
--- /dev/null
+++ b/home/config/nvim/lua/keybinds.lua
@@ -0,0 +1,22 @@
+local opts = { noremap = true, silent = true }
+local keymap = vim.keymap.set
+local builtin = require('telescope.builtin')
+local Terminal = require('toggleterm.terminal').Terminal
+local term_float = Terminal:new({ direction = 'float', hidden = 'true' })
+
+vim.g.mapleader = ' '
+vim.g.maplocalleader = ' '
+
+keymap('', '<leader>', '<Nop>', opts)
+keymap('n', '<leader>e', vim.cmd.NvimTreeToggle)
+keymap('n', '<leader>m', vim.cmd.Mason)
+keymap('n', '<leader>h', vim.cmd.noh)
+keymap('n', '<leader>p', vim.cmd.PlugUpdate)
+keymap('n', '<leader>ff', builtin.find_files, {})
+keymap('n', '<leader>fg', builtin.live_grep, {})
+keymap('n', '<leader>fb', builtin.buffers, {})
+keymap('n', '<leader>fh', builtin.help_tags, {})
+keymap('n', '<leader>u', vim.cmd.UndotreeToggle)
+keymap('n', '<leader>gs', vim.cmd.Git)
+keymap('n', '<leader>t', function() require('trouble').toggle() end)
+keymap('', '<A-s>', function() term_float:toggle() end)
diff --git a/home/config/nvim/lua/lsp.lua b/home/config/nvim/lua/lsp.lua
new file mode 100644
index 0000000..a548518
--- /dev/null
+++ b/home/config/nvim/lua/lsp.lua
@@ -0,0 +1,94 @@
+local lsp = require('lsp-zero').preset('recommended')
+
+require('mason').setup({})
+require('mason-lspconfig').setup({
+ ensure_installed = {
+ 'tsserver',
+ 'eslint',
+ 'rust_analyzer',
+ 'clangd',
+ 'html',
+ 'cssls',
+ 'pyright',
+ 'vimls',
+ 'yamlls',
+ 'jdtls',
+ 'bashls',
+ 'lua_ls',
+ },
+ handlers = {
+ lsp.default_setup,
+ },
+})
+
+local cmp = require('cmp')
+
+local cmp_select = {behavior = cmp.SelectBehavior.Select}
+local cmp_mappings = cmp.mapping.preset.insert({
+ ['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
+ ['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
+ ['<CR>'] = cmp.mapping.confirm({ select = true }),
+ ["<C-Space>"] = cmp.mapping.complete(),
+})
+
+cmp_mappings['<Tab>'] = nil
+cmp_mappings['<S-Tab>'] = nil
+
+cmp.setup({
+ mapping = cmp_mappings
+})
+
+lsp.set_preferences({
+ suggest_lsp_servers = false,
+ sign_icons = {
+ error = 'E',
+ warn = 'W',
+ hint = 'H',
+ info = 'I'
+ }
+})
+
+lsp.on_attach(function(client, bufnr)
+ local opts = {buffer = bufnr, remap = false}
+ local keymap = vim.keymap.set
+
+ keymap("n", "gd", function() vim.lsp.buf.definition() end, opts)
+ keymap("n", "K", function() vim.lsp.buf.hover() end, opts)
+ keymap("n", "<leader>ls", function() vim.lsp.buf.workspace_symbol() end, opts)
+ keymap("n", "<leader>lf", function() vim.diagnostic.open_float() end, opts)
+ keymap("n", "[d", function() vim.diagnostic.goto_next() end, opts)
+ keymap("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
+ keymap("n", "<leader>la", function() vim.lsp.buf.code_action() end, opts)
+ keymap("n", "<leader>lr", function() vim.lsp.buf.references() end, opts)
+ keymap("n", "<leader>ln", function() vim.lsp.buf.rename() end, opts)
+ keymap("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
+end)
+
+require('lspconfig/prolog_lsp')
+
+require('lspconfig').gleam.setup {}
+
+lsp.configure('prolog_lsp', {force_setup = true})
+lsp.setup()
+
+require('phpactor').setup {
+ install = {
+ branch = "master",
+ bin = "/usr/bin/phpactor",
+ php_bin = "php",
+ composer_bin = "composer",
+ git_bin = "git",
+ check_on_startup = "none",
+ },
+ lspconfig = {
+ enabled = true,
+ options = {},
+ },
+}
+
+vim.diagnostic.config({
+ virtual_text = true
+})
+
+require("neodev").setup()
+require("nvim-surround").setup()
diff --git a/home/config/nvim/lua/lspconfig/prolog_lsp.lua b/home/config/nvim/lua/lspconfig/prolog_lsp.lua
new file mode 100644
index 0000000..85ea353
--- /dev/null
+++ b/home/config/nvim/lua/lspconfig/prolog_lsp.lua
@@ -0,0 +1,21 @@
+local configs = require 'lspconfig.configs'
+local util = require 'lspconfig/util'
+
+configs.prolog_lsp = {
+ default_config = {
+ cmd = {"swipl",
+ "-g", "use_module(library(lsp_server)).",
+ "-g", "lsp_server:main",
+ "-t", "halt",
+ "--", "stdio"};
+ filetypes = {"prolog"};
+ root_dir = util.root_pattern("pack.pl");
+ };
+ docs = {
+ description = [[
+ https://github.com/jamesnvc/prolog_lsp
+
+ Prolog Language Server
+ ]];
+ }
+}
diff --git a/home/config/nvim/lua/menu.lua b/home/config/nvim/lua/menu.lua
new file mode 100644
index 0000000..e3e74bd
--- /dev/null
+++ b/home/config/nvim/lua/menu.lua
@@ -0,0 +1,233 @@
+local path_ok, plenary_path = pcall(require, "plenary.path")
+if not path_ok then
+ return
+end
+
+local dashboard = require("alpha.themes.dashboard")
+local cdir = vim.fn.getcwd()
+local if_nil = vim.F.if_nil
+
+local nvim_web_devicons = {
+ enabled = true,
+ highlight = true,
+}
+
+local function get_extension(fn)
+ local match = fn:match("^.+(%..+)$")
+ local ext = ""
+ if match ~= nil then
+ ext = match:sub(2)
+ end
+ return ext
+end
+
+local function icon(fn)
+ local nwd = require("nvim-web-devicons")
+ local ext = get_extension(fn)
+ return nwd.get_icon(fn, ext, { default = true })
+end
+
+local function file_button(fn, sc, short_fn,autocd)
+ short_fn = short_fn or fn
+ local ico_txt
+ local fb_hl = {}
+
+ if nvim_web_devicons.enabled then
+ local ico, hl = icon(fn)
+ local hl_option_type = type(nvim_web_devicons.highlight)
+ if hl_option_type == "boolean" then
+ if hl and nvim_web_devicons.highlight then
+ table.insert(fb_hl, { hl, 0, #ico })
+ end
+ end
+ if hl_option_type == "string" then
+ table.insert(fb_hl, { nvim_web_devicons.highlight, 0, #ico })
+ end
+ ico_txt = ico .. " "
+ else
+ ico_txt = ""
+ end
+ local cd_cmd = (autocd and " | cd %:p:h" or "")
+ local file_button_el = dashboard.button(sc, ico_txt .. short_fn, "<cmd>e " .. vim.fn.fnameescape(fn) .. cd_cmd .." <CR>")
+ local fn_start = short_fn:match(".*[/\\]")
+ if fn_start ~= nil then
+ table.insert(fb_hl, { "Comment", #ico_txt - 2, #fn_start + #ico_txt })
+ end
+ file_button_el.opts.hl = fb_hl
+ return file_button_el
+end
+
+local default_mru_ignore = { "gitcommit" }
+
+local mru_opts = {
+ ignore = function(path, ext)
+ return (string.find(path, "COMMIT_EDITMSG")) or (vim.tbl_contains(default_mru_ignore, ext))
+ end,
+ autocd = false
+}
+
+--- @param start number
+--- @param cwd string? optional
+--- @param items_number number? optional number of items to generate, default = 10
+local function mru(start, cwd, items_number, opts)
+ opts = opts or mru_opts
+ items_number = if_nil(items_number, 10)
+
+ local oldfiles = {}
+ for _, v in pairs(vim.v.oldfiles) do
+ if #oldfiles == items_number then
+ break
+ end
+ local cwd_cond
+ if not cwd then
+ cwd_cond = true
+ else
+ cwd_cond = vim.startswith(v, cwd)
+ end
+ local ignore = (opts.ignore and opts.ignore(v, get_extension(v))) or false
+ if (vim.fn.filereadable(v) == 1) and cwd_cond and not ignore then
+ oldfiles[#oldfiles + 1] = v
+ end
+ end
+ local target_width = 35
+
+ local tbl = {}
+ for i, fn in ipairs(oldfiles) do
+ local short_fn
+ if cwd then
+ short_fn = vim.fn.fnamemodify(fn, ":.")
+ else
+ short_fn = vim.fn.fnamemodify(fn, ":~")
+ end
+
+ if #short_fn > target_width then
+ short_fn = plenary_path.new(short_fn):shorten(1, { -2, -1 })
+ if #short_fn > target_width then
+ short_fn = plenary_path.new(short_fn):shorten(1, { -1 })
+ end
+ end
+
+ local shortcut = tostring(i + start - 1)
+
+ local file_button_el = file_button(fn, shortcut, short_fn,opts.autocd)
+ tbl[i] = file_button_el
+ end
+ return {
+ type = "group",
+ val = tbl,
+ opts = {},
+ }
+end
+
+local cats = {
+ {
+ [[ ,-. _,---._ __ / \]],
+ [[ / ) .-' `./ / \]],
+ [[( ( ,' `/ /|]],
+ [[ \ `-" \'\ / |]],
+ [[ `. , \ \ / |]],
+ [[ /`. ,'-`----Y |]],
+ [[ ( ; | ']],
+ [[ | ,-. ,-' | /]],
+ [[ | | ( | hjw | /]],
+ [[ ) | \ `.___________|/]],
+ [[ `--' `--']],
+ },
+ {
+ [[ _]],
+ [[ \`*-. ]],
+ [[ ) _`-. ]],
+ [[ . : `. . ]],
+ [[ : _ ' \ ]],
+ [[ ; *` _. `*-._ ]],
+ [[ `-.-' `-. ]],
+ [[ ; ` `. ]],
+ [[ :. . \ ]],
+ [[ . \ . : .-' . ]],
+ [[ ' `+.; ; ' : ]],
+ [[ : ' | ; ;-. ]],
+ [[ ; ' : :`-: _.`* ;]],
+ [[[bug] .*' / .*' ; .*`- +' `*' ]],
+ [[ `*-* `*-* `*-*']],
+ },
+}
+
+math.randomseed(os.time())
+local header = {
+ type = "text",
+ val = cats[math.random(1, #cats)],
+ opts = {
+ position = "center",
+ hl = "Type",
+ },
+}
+
+local section_mru = {
+ type = "group",
+ val = {
+ {
+ type = "text",
+ val = "Recent files",
+ opts = {
+ hl = "SpecialComment",
+ shrink_margin = false,
+ position = "center",
+ },
+ },
+ { type = "padding", val = 1 },
+ {
+ type = "group",
+ val = function()
+ return { mru(0, cdir) }
+ end,
+ opts = { shrink_margin = false },
+ },
+ },
+}
+
+local buttons = {
+ type = "group",
+ val = {
+ { type = "text", val = "Quick links", opts = { hl = "SpecialComment", position = "center" } },
+ { type = "padding", val = 1 },
+ dashboard.button("e", " New file", "<cmd>ene<CR>"),
+ dashboard.button("SPC f f", "󰈞 Find file"),
+ dashboard.button("SPC f g", "󰊄 Live grep"),
+ dashboard.button("SPC p", " Update plugins", "<cmd>PlugUpdate<CR>"),
+ dashboard.button("c", " Configuration", "<cmd>cd ~/.config/nvim/ <CR>"),
+ dashboard.button("q", "󰅚 Quit", "<cmd>qa<CR>"),
+ },
+ position = "center",
+}
+
+local config = {
+ layout = {
+ { type = "padding", val = 2 },
+ header,
+ { type = "padding", val = 2 },
+ section_mru,
+ { type = "padding", val = 2 },
+ buttons,
+ },
+ opts = {
+ margin = 5,
+ setup = function()
+ vim.api.nvim_create_autocmd('DirChanged', {
+ pattern = '*',
+ group = "alpha_temp",
+ callback = function () require('alpha').redraw() end,
+ })
+ end,
+ },
+}
+
+return {
+ header = header,
+ buttons = buttons,
+ mru = mru,
+ config = config,
+ -- theme specific config
+ mru_opts = mru_opts,
+ leader = dashboard.leader,
+ nvim_web_devicons = nvim_web_devicons,
+}
diff --git a/home/config/nvim/lua/plugin.lua b/home/config/nvim/lua/plugin.lua
new file mode 100644
index 0000000..2ad8cdc
--- /dev/null
+++ b/home/config/nvim/lua/plugin.lua
@@ -0,0 +1,45 @@
+local Plug = vim.fn['plug#']
+
+vim.call('plug#begin')
+
+Plug('nvim-tree/nvim-web-devicons')
+Plug('nvim-tree/nvim-tree.lua')
+Plug('nvim-lualine/lualine.nvim')
+Plug('ryanoasis/vim-devicons')
+Plug('SirVer/ultisnips')
+Plug('honza/vim-snippets')
+Plug('preservim/nerdcommenter')
+Plug('neoclide/coc.nvim', { branch = 'release' })
+Plug('nvim-telescope/telescope.nvim', { tag = '0.1.3' })
+Plug('nvim-treesitter/nvim-treesitter', { run = ':TSUpdate' })
+Plug('nvim-lua/plenary.nvim')
+Plug('mbbill/undotree')
+Plug('catppuccin/nvim', { as = 'catppuccin' })
+Plug('tpope/vim-fugitive')
+Plug('neovim/nvim-lspconfig')
+Plug('hrsh7th/nvim-cmp')
+Plug('hrsh7th/cmp-nvim-lsp')
+Plug('L3MON4D3/LuaSnip')
+Plug('williamboman/mason.nvim')
+Plug('williamboman/mason-lspconfig.nvim')
+Plug('VonHeikemen/lsp-zero.nvim', { branch = 'v3.x' })
+Plug('akinsho/bufferline.nvim', { tag = '*' })
+Plug('folke/neodev.nvim')
+Plug('RRethy/vim-illuminate')
+Plug('SmiteshP/nvim-navic')
+Plug('utilyre/barbecue.nvim')
+Plug('j-hui/fidget.nvim', { tag = 'legacy' })
+Plug('rcarriga/nvim-notify')
+Plug('folke/trouble.nvim')
+Plug('kylechui/nvim-surround')
+Plug('akinsho/toggleterm.nvim', {tag = '*'})
+Plug('goolord/alpha-nvim')
+Plug('Darazaki/indent-o-matic')
+Plug('iamcco/markdown-preview.nvim', {["do"] = "cd app && npx --yes yarn install"})
+Plug('skywind3000/asyncrun.vim')
+Plug('folke/todo-comments.nvim')
+Plug('gbprod/phpactor.nvim')
+Plug('gleam-lang/gleam.vim')
+Plug('edluffy/hologram.nvim')
+
+vim.call('plug#end')
diff --git a/home/config/nvim/lua/theme.lua b/home/config/nvim/lua/theme.lua
new file mode 100644
index 0000000..79631c1
--- /dev/null
+++ b/home/config/nvim/lua/theme.lua
@@ -0,0 +1,68 @@
+local catppuccin = require('catppuccin')
+
+catppuccin.setup({
+ transparent_background = true,
+ integrations = {
+ cmp = true,
+ nvimtree = true,
+ treesitter = true,
+ illuminate = {
+ enabled = true,
+ lsp = false
+ },
+ barbecue = {
+ dim_dirname = true, -- directory name is dimmed by default
+ bold_basename = true,
+ dim_context = false,
+ alt_background = false,
+ },
+ coc_nvim = true,
+ fidget = true,
+ markdown = true,
+ notify = true,
+ lsp_trouble = true,
+ },
+})
+
+local colorscheme = "catppuccin"
+local ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme)
+vim.o.background = "dark" -- or "light" for light mode
+if not ok then
+ vim.notify("colorscheme " .. colorscheme .. " not found!")
+ return
+end
+
+require('lualine').setup {
+ options = {
+ theme = colorscheme,
+ icons_enabled = true,
+ globalstatus = true,
+ },
+}
+
+require('todo-comments').setup()
+
+require('indent-o-matic').setup {
+ max_lines = 2048,
+ standard_widths = { 2, 4, 8 },
+ skip_multiline = true,
+}
+
+vim.api.nvim_set_hl(0, "Normal", { bg = "none" })
+vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" })
+vim.api.nvim_set_hl(0, "NvimTreeNormal", { bg = "none" })
+
+vim.opt.termguicolors = true
+require("bufferline").setup {}
+require("fidget").setup {
+ window = {
+ blend = 0,
+ },
+}
+
+local theme = require('menu')
+require('alpha').setup(theme.config)
+
+require('hologram').setup {
+ auto_display = true
+}
diff --git a/home/config/nvim/lua/tree.lua b/home/config/nvim/lua/tree.lua
new file mode 100644
index 0000000..aef5023
--- /dev/null
+++ b/home/config/nvim/lua/tree.lua
@@ -0,0 +1,120 @@
+vim.g.loaded_netrw = 1
+vim.g.loaded_netrwPlugin = 1
+
+local function on_attach(bufnr)
+ local api = require("nvim-tree.api")
+
+ local function opts(desc)
+ return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
+ end
+
+ local function edit_or_open()
+ local node = api.tree.get_node_under_cursor()
+
+ if node.nodes ~= nil then
+ -- expand or collapse folder
+ api.node.open.edit()
+ else
+ -- open file
+ api.node.open.edit()
+ -- Close the tree if file was opened
+ api.tree.close()
+ end
+ end
+
+ api.config.mappings.default_on_attach(bufnr)
+ vim.keymap.set("n", "<CR>", edit_or_open, opts("Open"))
+end
+
+require("nvim-tree").setup({
+ sort_by = "case_sensitive",
+ view = {
+ adaptive_size = false,
+ centralize_selection = true,
+ width = 30,
+ side = "left",
+ preserve_window_proportions = false,
+ number = false,
+ relativenumber = false,
+ signcolumn = "yes",
+ float = {
+ enable = false,
+ quit_on_focus_loss = true,
+ open_win_config = {
+ relative = "editor",
+ border = "rounded",
+ width = 30,
+ height = 30,
+ row = 1,
+ col = 1,
+ },
+ },
+ },
+ renderer = {
+ group_empty = true,
+ },
+ actions = {
+ use_system_clipboard = true,
+ change_dir = {
+ enable = true,
+ global = false,
+ restrict_above_cwd = false,
+ },
+ expand_all = {
+ max_folder_discovery = 300,
+ exclude = {},
+ },
+ file_popup = {
+ open_win_config = {
+ col = 1,
+ row = 1,
+ relative = "cursor",
+ border = "shadow",
+ style = "minimal",
+ },
+ },
+ open_file = {
+ window_picker = {
+ enable = false,
+ picker = "default",
+ chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
+ exclude = {
+ filetype = { "notify", "lazy", "qf", "diff", "fugitive", "fugitiveblame" },
+ buftype = { "nofile", "terminal", "help" },
+ },
+ }
+ },
+ remove_file = {
+ close_window = true,
+ },
+
+ },
+ tab = {
+ sync = {
+ open = false,
+ close = false,
+ ignore = {},
+ },
+ },
+ git = {
+ enable = true,
+ ignore = false,
+ show_on_dirs = true,
+ show_on_open_dirs = true,
+ timeout = 200,
+ },
+ filters = {
+ dotfiles = false,
+ git_clean = false,
+ no_buffer = false,
+ custom = { "node_modules", "\\.cache" },
+ exclude = {},
+ },
+ update_cwd = true,
+ respect_buf_cwd = true,
+ update_focused_file = {
+ enable = true,
+ update_cwd = true
+ },
+ on_attach = on_attach
+})
diff --git a/home/config/nvim/lua/treesitter.lua b/home/config/nvim/lua/treesitter.lua
new file mode 100644
index 0000000..7b578d6
--- /dev/null
+++ b/home/config/nvim/lua/treesitter.lua
@@ -0,0 +1,32 @@
+local lsps = {
+ "c",
+ "lua",
+ "rust",
+ "typescript",
+ "javascript",
+ "python",
+ "vim",
+ "vimdoc",
+ "query"
+};
+
+require('nvim-treesitter.configs').setup {
+ ensure_installed = lsps,
+ sync_install = false,
+ auto_install = true,
+ ignore_install = { "javascript" },
+ highlight = {
+ enable = true,
+ disable = function(lang, buf)
+ local max_filesize = 1000 * 1024 -- 1 MiB
+ local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
+ if ok and stats and stats.size > max_filesize then
+ return true
+ end
+ end,
+ additional_vim_regex_highlighting = false,
+ },
+ indent = {
+ enable = true
+ }
+}
diff --git a/home/config/nvim/lua/vimopt.lua b/home/config/nvim/lua/vimopt.lua
new file mode 100644
index 0000000..d205926
--- /dev/null
+++ b/home/config/nvim/lua/vimopt.lua
@@ -0,0 +1,32 @@
+local set = vim.opt
+set.tabstop = 4
+set.softtabstop = 4
+set.shiftwidth = 4
+--set.noexpandtab = true
+set.mouse = "a"
+set.clipboard = "unnamedplus"
+set.hlsearch = true
+set.autoindent = true
+set.ttyfast = true
+set.number = true
+set.relativenumber = true
+set.rnu = true
+set.swapfile = false
+
+vim.filetype.add({
+ pattern = {
+ ['.*%.pl'] = 'prolog',
+ ['.*%.prolog'] = 'prolog',
+ ['.*%.php.m4'] = 'php',
+ }
+})
+
+vim.api.nvim_create_autocmd({ "BufWritePre" }, {
+ pattern = { "*" },
+ command = [[%s/\s\+$//e]],
+})
+
+vim.api.nvim_create_autocmd({ "BufWritePost" }, {
+ pattern = { "*.md" },
+ command = 'silent !pandoc % --output=/home/freya/.temp.pdf'
+})