From be33d17828274d2b60d02e76f8a70b8a7e7330ed Mon Sep 17 00:00:00 2001 From: Amneesh Singh Date: Tue, 28 May 2024 05:09:43 +0530 Subject: [PATCH] neovim: update neovim config after a long time (i still use emacs Signed-off-by: Amneesh Singh --- .envrc | 1 + flake.nix | 3 +- hosts/default.nix | 2 +- hosts/nix.nix | 5 +- hosts/nvim.nix | 7 + hosts/nvim/default.nix | 49 --- hosts/nvim/init.lua | 410 -------------------- pkgs/default.nix | 6 - pkgs/nattovim/default.nix | 59 +++ {hosts/nvim => pkgs/nattovim}/gruvbox.patch | 0 pkgs/nattovim/init.lua | 368 ++++++++++++++++++ pkgs/packages.nix | 1 + 12 files changed, 443 insertions(+), 468 deletions(-) create mode 100644 .envrc create mode 100644 hosts/nvim.nix delete mode 100644 hosts/nvim/default.nix delete mode 100644 hosts/nvim/init.lua create mode 100644 pkgs/nattovim/default.nix rename {hosts/nvim => pkgs/nattovim}/gruvbox.patch (100%) create mode 100644 pkgs/nattovim/init.lua diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/flake.nix b/flake.nix index 444e758..a30f53a 100644 --- a/flake.nix +++ b/flake.nix @@ -55,11 +55,12 @@ ]; perSystem = { system, pkgs, ... }: - { + rec { formatter = pkgs.nixpkgs-fmt; devShells.default = with pkgs; mkShell { packages = [ nixd + formatter ]; }; }; diff --git a/hosts/default.nix b/hosts/default.nix index 324f4a9..ca40da0 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -3,7 +3,7 @@ let inherit (inputs) nixpkgs; commonModules = [ - ./nvim + ./nvim.nix globalArgs ]; desktopModules = [ diff --git a/hosts/nix.nix b/hosts/nix.nix index d4aa31d..db6694e 100644 --- a/hosts/nix.nix +++ b/hosts/nix.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: +{ config, pkgs, self, ... }: { nixpkgs = { config = { @@ -6,6 +6,9 @@ allowBroken = true; allowInsecure = true; }; + overlays = [ + self.overlays.default + ]; }; nix = { diff --git a/hosts/nvim.nix b/hosts/nvim.nix new file mode 100644 index 0000000..e078943 --- /dev/null +++ b/hosts/nvim.nix @@ -0,0 +1,7 @@ +{ inputs, pkgs, ... }: + +{ + environment.systemPackages = with pkgs; [ + (nattovim.override { nvimPackage = inputs.nvim-overlay.packages.${pkgs.system}.neovim; }) + ]; +} diff --git a/hosts/nvim/default.nix b/hosts/nvim/default.nix deleted file mode 100644 index 7a9c8eb..0000000 --- a/hosts/nvim/default.nix +++ /dev/null @@ -1,49 +0,0 @@ -{ inputs, config, pkgs, ... }: - -{ - environment.sessionVariables = { - EDITOR = "nvim"; - }; - programs.neovim = { - enable = true; - package = inputs.nvim-overlay.packages.${pkgs.system}.neovim; - defaultEditor = false; - configure = { - customRC = '' - lua << EOF - ${builtins.readFile ./init.lua} - EOF - ''; - packages.myVimPackage = with pkgs.vimPlugins; { - start = [ - nvim-colorizer-lua - bracey-vim - auto-pairs - vim-floaterm - vim-closetag - nerdcommenter - nvim-cmp - luasnip - friendly-snippets - cmp_luasnip - cmp-nvim-lsp - cmp-path - cmp-calc - cmp-emoji - # cmp-look - cmp-buffer - nvim-lspconfig - barbar-nvim - presence-nvim - nvim-web-devicons - nvim-tree-lua - nvim-treesitter - vim-latex-live-preview - lspkind-nvim - catppuccin-nvim - yuck-vim - ]; - }; - }; - }; -} diff --git a/hosts/nvim/init.lua b/hosts/nvim/init.lua deleted file mode 100644 index dfdcced..0000000 --- a/hosts/nvim/init.lua +++ /dev/null @@ -1,410 +0,0 @@ ---i do not really maintain this anymore since emacs is my main editor now - -vim.api.nvim_set_option("termguicolors", true) -local bind = vim.keymap.set - ---SETTINGS -vim.o.cmdheight = 1 -vim.o.modifiable = true -vim.o.cursorline = true -vim.o.hidden = true -vim.o.encoding= "utf-8" -vim.o.pumheight = 10 -vim.o.fileencoding = "utf-8" -vim.o.ruler = true -vim.o.cmdheight = 1 -vim.o.mouse = "a" -vim.o.splitbelow = true -vim.o.splitright = true -vim.o.conceallevel = 0 -vim.o.tabstop = 2 -vim.o.shiftwidth = 2 -vim.o.smarttab = true -vim.o.expandtab = true -vim.o.smartindent = true -vim.o.autoindent = true -vim.o.number = true -vim.o.relativenumber = true -vim.o.showtabline = 2 -vim.o.updatetime = 300 -vim.o.lazyredraw = true -vim.o.timeoutlen = 100 -vim.o.clipboard = "unnamedplus" -vim.o.completeopt = "menuone,noselect" -vim.o.cursorcolumn = true - ---KEYBINDS - ---[[ -A relic of the past ---Colemak-DH bind fuction for hjkl [mnei]) -local function cdhbind(a, b) - bind('', a:lower(), b:lower()) - bind('', a:upper(), b:upper()) -end - -cdhbind('m', 'h') -cdhbind('n', 'j') -cdhbind('e', 'k') -cdhbind('i', 'l') -cdhbind('u', 'i') -cdhbind('l', 'u') -cdhbind('k', 'n') -cdhbind('f', 'e') -cdhbind('t', 'f') -cdhbind('j', 't') - -bind('n', "", ":resize -2") -bind('n', "", ":resize +2") -bind('n', "", ":vertical resize -2") -bind('n', "", ":vertical resize +2") -bind('v', '<', "', ">gv") -bind('n', "", "q") -bind('n', "", "h") -bind('n', "", "j") -bind('n', "", "k") -bind('n', "", "l") -bind('n', "", ":vsplit") -bind('n', "", ":split") -]]-- - ---RUN AND REPL (using vim-floaterm) - -function _G.CompileRun() - local file = vim.fn.expand('%:p') - local noext = vim.fn.expand('%:p:r') - local commandMap = { - ['java'] = 'java ' .. file, - ['lisp'] = 'clisp ' .. file, - ['python'] = 'python3 ' .. file, - ['c'] = 'gcc ' .. file .. ' -o ' .. noext .. ' -Wno-unused-result ' .. ' && ' .. noext .. ' && rm ' .. noext, - ['rust'] = 'rustc ' .. file .. ' -o ' .. noext .. ' && ' .. noext .. ' && rm ' .. noext, - ['cpp'] = 'g++ -std=c++17 ' .. file .. ' -o ' .. noext .. ' -Wno-unused-result ' .. ' && ' .. noext .. ' && rm ' .. noext, - ['haskell'] = 'runhaskell ' .. file, - ['sh'] = 'sh ' .. file, - ['javascript']= 'node ' .. file, - ['typescript']= 'tsc ' .. file .. ' && node ' .. noext .. '.js && rm ' .. noext .. '.js' - } - filetype = vim.api.nvim_buf_get_option(0, "filetype") - if commandMap[filetype] ~= nil then vim.cmd("FloatermNew --autoclose=0 " .. commandMap[filetype]) end -end - -function _G.Repl() - local file = vim.fn.expand('%:p') - local commandMap = { - ['lisp'] = 'clisp', - ['python'] = 'python3', - ['haskell'] = 'ghci ' .. file, - ['sh'] = 'sh', - ['javascript']= 'node', - ['typescript']= 'ts-node', - ['nix'] = 'nix repl', - ['lua'] = 'lua' - } - filetype = vim.api.nvim_buf_get_option(0, "filetype") - if commandMap[filetype] ~= nil then vim.cmd("FloatermNew " .. commandMap[filetype]) end -end -bind('n', "", ":call v:lua.CompileRun()") -bind('n', "", ":call v:lua.Repl()") - - - ---PLUGINS CONFIG - ---nvim-tree.lua -require'nvim-tree'.setup { - diagnostics = { - enable = true, - }, - update_focused_file = { - enable = true, - update_root = true, - }, - renderer = { - highlight_opened_files = "all", - highlight_git = true - }, - git = { - enable = true, - ignore = true, - show_on_dirs = true, - }, - actions = { - open_file = { - quit_on_open = true, - resize_window = true, - window_picker = { - enable = true, - exclude = { - filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" }, - buftype = { "nofile", "terminal", "help" }, - }, - }, - }, - }, - view = { - adaptive_size = true, - mappings = { - list = { - { key = "e", action = "" }, - { key = "m", action = "" }, - { key = "f", action = "rename_basename" } - }, - }, - }, -} - -bind('n', "", ":NvimTreeToggle") -bind('n', "r", ":NvimTreeRefresh") -bind('n', "f", ":NvimTreeFindFile") -bind('n', "f", ":NvimTreeFindFile") - - ---floaterm -vim.g.floaterm_keymap_toggle = '' -vim.g.floaterm_keymap_next = '' -vim.g.floaterm_keymap_prev = '' -vim.g.floaterm_keymap_new = '' -vim.g.floaterm_gitcommit='floaterm' -vim.g.floaterm_autoinsert=1 -vim.g.floaterm_position="bottom" -vim.g.floaterm_width=0.99 -vim.g.floaterm_height=0.6 - ---closetag -vim.g.closetag_filenames = "*.html,*.xhtml,*.phtml,*.js,*.erb,*.jsx" -vim.g.closetag_xhtml_filenames = "*.xhtml,*.jsx,*.js,*.erb" -vim.g.closetag_emptyTags_caseSensitive = 1 -vim.g.closetag_shortcut = '>' - ---nerdcommenter -bind('n',"","NERDCommenterToggle") -bind('n',"","NERDCommenterSexy") - ---barbar -bind('n', "", ":BufferPrevious") -bind('n', "", ":BufferNext") -bind('n', "", ":BufferMovePrevious") -bind('n', ">", ":BufferMoveNext") -bind('n', "", ":BufferClose") -for i = 1,8,1 -do - bind('n', string.format("", i), string.format(":BufferGoto %d", i)) -end - ---presence.nvim -vim.g.presence_neovim_image_text = "Ballin" -vim.g.presence_main_image = "file" - ---treesitter-nvim -require'nvim-treesitter.configs'.setup { - ensure_install = "all", - highlight = { - enable = true, - additional_vim_regex_highlighting = true, - }, - indent = { - enable = true - } -} - ---vim-latex-live-preview -vim.g.livepreview_previewer = "zathura" - -require'colorizer'.setup() - -local on_attach = function(client, bufnr) - local bufopts = { noremap=true, silent=true, buffer=bufnr } - - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') - vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) - vim.keymap.set('n', '', vim.lsp.buf.hover, bufopts) - vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) - vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) - vim.keymap.set('n', "", function() vim.lsp.buf.format { async = true } end, bufopts) -end - -local servers = { "clangd", "rust_analyzer", "tsserver", "hls", "pylsp", "texlab", "rnix", "terraform_lsp", "html", "cssls", "jsonls", "svelte", "gopls" } -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities.textDocument.completion.completionItem.snippetSupport = true -capabilities.textDocument.completion.completionItem.resolveSupport = { - properties = { - 'documentation', - 'detail', - 'additionalTextEdits', - } -} - -local nvimlsp = require('lspconfig') -for _, lsp in ipairs(servers) do - nvimlsp[lsp].setup { capabilities = capabilities, on_attach = on_attach } -end - - ---luasnip -local luasnip = require 'luasnip' -luasnip.snippets = { - html = {} -} -luasnip.snippets.javascript = luasnip.snippets.html -luasnip.snippets.javascriptreact = luasnip.snippets.html -require("luasnip/loaders/from_vscode").lazy_load() - -local cmp = require 'cmp' -cmp.setup { - snippet = { - expand = function(args) - require('luasnip').lsp_expand(args.body) - end, - }, - mapping = { - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.close(), - [''] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }, - [''] = function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, - [''] = function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end - }, - sources = { - { name = 'nvim_lsp'}, - { name = 'path'}, - { name = 'nvim_lua'}, - { name = 'luasnip'}, - { name = 'calc'}, - { name = 'emoji'}, - { name = 'buffer'}, - { name = 'look'}, - }, - formatting = { - format = require('lspkind').cmp_format({ - with_text = true, - menu = ({ - buffer = "[Buffer]", - nvim_lsp = "[LSP]", - luasnip = "[LuaSnip]", - nvim_lua = "[Lua]", - latex_symbols = "[Latex]", - }) - }), - }, -} - -vim.cmd("set shortmess+=c") - ---STATUSLINE -vim.cmd("set noruler") -vim.o.laststatus = 2 -local function mode() - local mode_map = { - ['n'] = 'normal ', - ['v'] = 'visual ', - ['V'] = 'v·line ', - [''] = 'v·block ', - ['s'] = 'select ', - ['S'] = 's·line ', - [''] = 's·block ', - ['i'] = 'insert ', - ['Rv'] = 'v·replace ', - ['c'] = 'command ', - ['!'] = 'shell ', - ['t'] = 'terminal ' - } - local m = vim.api.nvim_get_mode().mode - if mode_map[m] == nil then return m end - return mode_map[m] -end - ---theming -local dark = true - -require("catppuccin").setup({ - flavour = "mocha", - background = { - light = "latte", - dark = "mocha", - }, -}) - -vim.cmd("colorscheme catppuccin") - -function hi(hi_var, hi_value) - vim.cmd("hi " .. hi_var .. " " .. hi_value) -end - -local colors = require("catppuccin.palettes").get_palette "latte" -hi("Light", "guibg=" .. colors.text .. " guifg=" .. colors.crust) -hi("Misc", "guibg=" .. colors.pink .. " guifg=" .. colors.base) -hi("Dark", "guibg=" .. colors.crust .. " guifg=" .. colors.text) - -local function git() - local branch = io.popen([[git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n']]):read("*a") - return string.len(branch) > 0 and ' '.. branch or '' -end - - -local statusline = { - '%#Light# ', - mode():upper() .. ' ', - '%#Misc#', - string.len(git()) > 0 and ' ' .. git() .. ' ' or '', - '%#Dark# ', - '%f ', - '%#Light#', - '%=', - '%#Dark# ', - '%y ', - '%#Light# ', - '%p%% ', - ' ', - '%l/%L ', - ' ', - '%c ' -} -vim.o.statusline = table.concat(statusline) - - -function _G.ToggleTheme() - if dark then - vim.cmd("set background=light") - local colors = require("catppuccin.palettes").get_palette "latte" - hi("Light", "guibg=" .. colors.crust .. " guifg=" .. colors.text) - hi("Misc", "guibg=" .. colors.peach .. " guifg=" .. colors.text) - hi("Dark", "guibg=" .. colors.text .. " guifg=" .. colors.crust) - vim.o.statusline = table.concat(statusline) - else - vim.cmd("set background=dark") - local colors = require("catppuccin.palettes").get_palette "mocha" - hi("Light", "guibg=" .. colors.text .. " guifg=" .. colors.crust) - hi("Misc", "guibg=" .. colors.pink .. " guifg=" .. colors.base) - hi("Dark", "guibg=" .. colors.crust .. " guifg=" .. colors.text) - vim.o.statusline = table.concat(statusline) - end - dark = not dark -end - -bind('n', "", ":call v:lua.ToggleTheme()") -vim.g.tex_flavor = "latex" diff --git a/pkgs/default.nix b/pkgs/default.nix index def0aea..5002530 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,14 +1,8 @@ { self, ... }: { - systems = [ "x86_64-linux" ]; - flake = { overlays = rec { packages = import ./packages.nix; default = packages; }; }; - - perSystem = { pkgs, ... }: { - packages = self.overlays.default null pkgs; - }; } diff --git a/pkgs/nattovim/default.nix b/pkgs/nattovim/default.nix new file mode 100644 index 0000000..bbcf9ac --- /dev/null +++ b/pkgs/nattovim/default.nix @@ -0,0 +1,59 @@ +{ wrapNeovimUnstable, neovimUtils, neovim-unwrapped, nvimPackage ? neovim-unwrapped, vimPlugins, ... }: +let + nvimConfig = neovimUtils.makeNeovimConfig { + plugins = with vimPlugins; [ + nvim-colorizer-lua + autoclose-nvim + toggleterm-nvim + luasnip + nvim-cmp + nvim-lspconfig + cmp-nvim-lsp + cmp-path + cmp-calc + cmp-emoji + cmp-buffer + barbar-nvim + nvim-web-devicons + presence-nvim + nvim-tree-lua + nvim-treesitter + lspkind-nvim + catppuccin-nvim + telescope-nvim + ]; + }; +in +wrapNeovimUnstable nvimPackage (nvimConfig // { + luaRcContent = '' + ${builtins.readFile ./init.lua} + ''; +}) +/* wrapNeovim nvimPackage { + configure = { + customRC = '' + ${builtins.readFile ./init.lua} + ''; + packages.myVimPackage = with vimPlugins; { + start = [ + nvim-colorizer-lua + autoclose-nvim + toggleterm-nvim + nvim-cmp + nvim-lspconfig + cmp-nvim-lsp + cmp-path + cmp-calc + cmp-emoji + cmp-buffer + barbar-nvim + nvim-web-devicons + presence-nvim + nvim-tree-lua + nvim-treesitter + lspkind-nvim + catppuccin-nvim + ]; + }; + }; + }*/ diff --git a/hosts/nvim/gruvbox.patch b/pkgs/nattovim/gruvbox.patch similarity index 100% rename from hosts/nvim/gruvbox.patch rename to pkgs/nattovim/gruvbox.patch diff --git a/pkgs/nattovim/init.lua b/pkgs/nattovim/init.lua new file mode 100644 index 0000000..2899fc5 --- /dev/null +++ b/pkgs/nattovim/init.lua @@ -0,0 +1,368 @@ +-- i do not really maintain this anymore since emacs is my main editor now +vim.api.nvim_set_option("termguicolors", true) +local bind = vim.keymap.set + +-- SETTINGS +vim.o.cmdheight = 1 +vim.o.modifiable = true +vim.o.cursorline = true +vim.o.hidden = true +vim.o.encoding = "utf-8" +vim.o.pumheight = 10 +vim.o.fileencoding = "utf-8" +vim.o.ruler = true +vim.o.cmdheight = 1 +vim.o.mouse = "a" +vim.o.splitbelow = true +vim.o.splitright = true +vim.o.conceallevel = 0 +vim.o.tabstop = 2 +vim.o.shiftwidth = 2 +vim.o.smarttab = true +vim.o.expandtab = true +vim.o.smartindent = true +vim.o.autoindent = true +vim.o.number = true +vim.o.relativenumber = true +vim.o.showtabline = 2 +vim.o.updatetime = 300 +vim.o.lazyredraw = true +vim.o.timeoutlen = 100 +vim.o.clipboard = "unnamedplus" +vim.o.completeopt = "menuone,noselect" +vim.o.cursorcolumn = true + +-- KEYBINDS + +--[[ +A relic of the past +--Colemak-DH bind fuction for hjkl [mnei]) +local function cdhbind(a, b) + bind('', a:lower(), b:lower()) + bind('', a:upper(), b:upper()) +end + +cdhbind('m', 'h') +cdhbind('n', 'j') +cdhbind('e', 'k') +cdhbind('i', 'l') +cdhbind('u', 'i') +cdhbind('l', 'u') +cdhbind('k', 'n') +cdhbind('f', 'e') +cdhbind('t', 'f') +cdhbind('j', 't') + +bind('n', "", ":resize -2") +bind('n', "", ":resize +2") +bind('n', "", ":vertical resize -2") +bind('n', "", ":vertical resize +2") +bind('v', '<', "', ">gv") +bind('n', "", "q") +bind('n', "", "h") +bind('n', "", "j") +bind('n', "", "k") +bind('n', "", "l") +bind('n', "", ":vsplit") +bind('n', "", ":split") +]] -- + +function _G.CompileRun() + local Terminal = require('toggleterm.terminal').Terminal + local file = vim.fn.expand('%:p') + local noext = vim.fn.expand('%:p:r') + local commandMap = { + ['java'] = 'java ' .. file, + ['lisp'] = 'clisp ' .. file, + ['python'] = 'python3 ' .. file, + ['c'] = 'gcc ' .. file .. ' -o ' .. noext .. ' -Wno-unused-result ' .. + ' && ' .. noext .. ' && rm ' .. noext, + ['rust'] = 'rustc ' .. file .. ' -o ' .. noext .. ' && ' .. noext .. + ' && rm ' .. noext, + ['cpp'] = 'g++ ' .. file .. ' -o ' .. noext .. ' -Wno-unused-result ' .. + ' && ' .. noext .. ' && rm ' .. noext, + ['cc'] = 'g++ ' .. file .. ' -o ' .. noext .. ' -Wno-unused-result ' .. + ' && ' .. noext .. ' && rm ' .. noext, + ['haskell'] = 'runhaskell ' .. file, + ['sh'] = 'sh ' .. file, + ['javascript'] = 'node ' .. file, + ['typescript'] = 'tsc ' .. file .. ' && node ' .. noext .. '.js && rm ' .. + noext .. '.js' + } + filetype = vim.api.nvim_buf_get_option(0, "filetype") + if commandMap[filetype] ~= nil then + Terminal:new({cmd = commandMap[filetype], close_on_exit = false}) + :toggle() + end +end + +function _G.Repl() + local Terminal = require('toggleterm.terminal').Terminal + local file = vim.fn.expand('%:p') + local commandMap = { + ['lisp'] = 'clisp', + ['python'] = 'python3', + ['haskell'] = 'ghci ' .. file, + ['sh'] = 'sh', + ['javascript'] = 'node', + ['typescript'] = 'ts-node', + ['nix'] = 'nix repl', + ['lua'] = 'lua' + } + filetype = vim.api.nvim_buf_get_option(0, "filetype") + if commandMap[filetype] ~= nil then + Terminal:new({cmd = commandMap[filetype]}):toggle() + end +end +bind('n', "", ":call v:lua.CompileRun()") +bind('n', "", ":call v:lua.Repl()") + +-- PLUGINS CONFIG + +-- nvim-tree.lua +require'nvim-tree'.setup { + diagnostics = {enable = true}, + update_focused_file = {enable = true, update_root = true}, + renderer = {highlight_opened_files = "all", highlight_git = true}, + git = {enable = true, ignore = true, show_on_dirs = true}, + actions = { + open_file = { + quit_on_open = true, + resize_window = true, + window_picker = { + enable = true, + exclude = { + filetype = { + "notify", "packer", "qf", "diff", "fugitive", + "fugitiveblame" + }, + buftype = {"nofile", "terminal", "help"} + } + } + } + }, + view = {adaptive_size = true} +} + +bind('n', "", ":NvimTreeToggle") +bind('n', "r", ":NvimTreeRefresh") +bind('n', "f", ":NvimTreeFindFile") +bind('n', "f", ":NvimTreeFindFile") + +-- colorizer +require'colorizer'.setup() + +-- toggleterm +require("toggleterm").setup { + size = function(term) + if term.direction == "horizontal" then + return 25 + elseif term.direction == "vertical" then + return vim.o.columns * 0.4 + end + end, + open_mapping = [[]], + autochdir = true +} + +-- autoclose +require("autoclose").setup({ + options = {disabled_filetypes = {"text", "markdown"}} +}) + +-- icons +require'nvim-web-devicons'.setup {default = true} + +-- barbar +bind('n', "", ":BufferPrevious") +bind('n', "", ":BufferNext") +bind('n', "", ":BufferMovePrevious") +bind('n', ">", ":BufferMoveNext") +bind('n', "", ":BufferClose") +for i = 1, 8, 1 do + bind('n', string.format("", i), string.format(":BufferGoto %d", i)) +end + +-- presence.nvim +vim.g.presence_neovim_image_text = "Ballin" +vim.g.presence_main_image = "file" + +-- treesitter-nvim +require'nvim-treesitter.configs'.setup { + ensure_install = "all", + highlight = {enable = true, additional_vim_regex_highlighting = true}, + indent = {enable = true} +} + +local on_attach = function(client, bufnr) + local bufopts = {noremap = true, silent = true, buffer = bufnr} + + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + bind('n', 'gD', vim.lsp.buf.declaration, bufopts) + bind('n', 'gd', vim.lsp.buf.definition, bufopts) + bind('n', '', vim.lsp.buf.hover, bufopts) + bind('n', 'gi', vim.lsp.buf.implementation, bufopts) + bind('n', 'gr', vim.lsp.buf.references, bufopts) + bind('n', "", function() vim.lsp.buf.format {async = true} end, + bufopts) +end + +local servers = { + "clangd", "rust_analyzer", "tsserver", "hls", "pylsp", "texlab", "nixd", + "terraform_lsp", "html", "cssls", "jsonls", "svelte", "gopls" +} +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities.textDocument.completion.completionItem.resolveSupport = { + properties = {'documentation', 'detail', 'additionalTextEdits'} +} + +-- lspconfig + +local nvimlsp = require('lspconfig') +for _, lsp in ipairs(servers) do + nvimlsp[lsp].setup {capabilities = capabilities, on_attach = on_attach} +end + +-- luasnip +local luasnip = require 'luasnip' +luasnip.snippets = {html = {}} +luasnip.snippets.javascript = luasnip.snippets.html +luasnip.snippets.javascriptreact = luasnip.snippets.html +require("luasnip/loaders/from_vscode").lazy_load() + +-- nvim cmp +local cmp = require 'cmp' +cmp.setup { + snippet = { + expand = function(args) require('luasnip').lsp_expand(args.body) end + }, + mapping = { + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true + }, + [''] = function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, + [''] = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end + }, + sources = { + {name = 'nvim_lsp'}, {name = 'path'}, {name = 'nvim_lua'}, + {name = 'luasnip'}, {name = 'calc'}, {name = 'emoji'}, + {name = 'buffer'}, {name = 'look'} + }, + formatting = { + format = require('lspkind').cmp_format({ + with_text = true, + menu = ({ + buffer = "[Buffer]", + nvim_lsp = "[LSP]", + luasnip = "[LuaSnip]", + nvim_lua = "[Lua]", + latex_symbols = "[Latex]" + }) + }) + } +} + +-- telescope +require('telescope').setup() + +vim.cmd("set shortmess+=c") + +-- STATUSLINE +vim.cmd("set noruler") +vim.o.laststatus = 2 +local function mode() + local mode_map = { + ['n'] = 'normal ', + ['v'] = 'visual ', + ['V'] = 'v·line ', + [''] = 'v·block ', + ['s'] = 'select ', + ['S'] = 's·line ', + [''] = 's·block ', + ['i'] = 'insert ', + ['Rv'] = 'v·replace ', + ['c'] = 'command ', + ['!'] = 'shell ', + ['t'] = 'terminal ' + } + local m = vim.api.nvim_get_mode().mode + if mode_map[m] == nil then return m end + return mode_map[m] +end + +-- theming +local dark = true + +require("catppuccin").setup({ + flavour = "mocha", + background = {light = "latte", dark = "mocha"} +}) + +vim.cmd("colorscheme catppuccin") + +function hi(hi_var, hi_value) vim.cmd("hi " .. hi_var .. " " .. hi_value) end + +local colors = require("catppuccin.palettes").get_palette "latte" +hi("Light", "guibg=" .. colors.text .. " guifg=" .. colors.crust) +hi("Misc", "guibg=" .. colors.pink .. " guifg=" .. colors.base) +hi("Dark", "guibg=" .. colors.crust .. " guifg=" .. colors.text) + +local function git() + local branch = io.popen( + [[git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n']]):read( + "*a") + return string.len(branch) > 0 and ' ' .. branch or '' +end + +local statusline = { + '%#Light# ', mode():upper() .. ' ', '%#Misc#', + string.len(git()) > 0 and ' ' .. git() .. ' ' or '', '%#Dark# ', '%f ', + '%#Light#', '%=', '%#Dark# ', '%y ', '%#Light# ', '%p%% ', ' ', '%l/%L ', + ' ', '%c ' +} +vim.o.statusline = table.concat(statusline) + +function _G.ToggleTheme() + if dark then + vim.cmd("set background=light") + local colors = require("catppuccin.palettes").get_palette "latte" + hi("Light", "guibg=" .. colors.crust .. " guifg=" .. colors.text) + hi("Misc", "guibg=" .. colors.peach .. " guifg=" .. colors.text) + hi("Dark", "guibg=" .. colors.text .. " guifg=" .. colors.crust) + vim.o.statusline = table.concat(statusline) + else + vim.cmd("set background=dark") + local colors = require("catppuccin.palettes").get_palette "mocha" + hi("Light", "guibg=" .. colors.text .. " guifg=" .. colors.crust) + hi("Misc", "guibg=" .. colors.pink .. " guifg=" .. colors.base) + hi("Dark", "guibg=" .. colors.crust .. " guifg=" .. colors.text) + vim.o.statusline = table.concat(statusline) + end + dark = not dark +end + +bind('n', "", ":call v:lua.ToggleTheme()") diff --git a/pkgs/packages.nix b/pkgs/packages.nix index c7e4855..e8b2e31 100644 --- a/pkgs/packages.nix +++ b/pkgs/packages.nix @@ -6,4 +6,5 @@ in customscripts = call ./customscripts { }; tlauncher = call ./tlauncher { }; simp1e-cursors = call ./simp1e { }; + nattovim = call ./nattovim { }; }