From 8d094b9552bb22e885a9c07492c51871a67c8b3f Mon Sep 17 00:00:00 2001 From: Ricard Illa Date: Wed, 2 Aug 2023 12:15:37 +0200 Subject: [PATCH] feat: modernized neovim plugin management with lazy --- home/neovim/default.nix | 9 +- home/neovim/init.lua | 500 +++--------------- home/neovim/lua/plugins/alpha.lua | 15 + home/neovim/lua/plugins/cmp.lua | 53 ++ home/neovim/lua/plugins/gruvbox.lua | 9 + home/neovim/lua/plugins/indent-blankline.lua | 10 + home/neovim/lua/plugins/init.lua | 12 + home/neovim/lua/plugins/lspconfig.lua | 110 ++++ home/neovim/lua/plugins/lualine.lua | 10 + home/neovim/lua/plugins/neo-tree.lua | 12 + home/neovim/lua/plugins/nerdcommenter.lua | 6 + home/neovim/lua/plugins/slime.lua | 7 + home/neovim/lua/plugins/telekasten.lua | 57 ++ home/neovim/lua/plugins/telescope.lua | 58 ++ home/neovim/lua/plugins/tmux-navigator.lua | 12 + .../neovim/lua/plugins/treesitter-context.lua | 7 + home/neovim/lua/plugins/treesitter.lua | 15 + 17 files changed, 464 insertions(+), 438 deletions(-) create mode 100644 home/neovim/lua/plugins/alpha.lua create mode 100644 home/neovim/lua/plugins/cmp.lua create mode 100644 home/neovim/lua/plugins/gruvbox.lua create mode 100644 home/neovim/lua/plugins/indent-blankline.lua create mode 100644 home/neovim/lua/plugins/init.lua create mode 100644 home/neovim/lua/plugins/lspconfig.lua create mode 100644 home/neovim/lua/plugins/lualine.lua create mode 100644 home/neovim/lua/plugins/neo-tree.lua create mode 100644 home/neovim/lua/plugins/nerdcommenter.lua create mode 100644 home/neovim/lua/plugins/slime.lua create mode 100644 home/neovim/lua/plugins/telekasten.lua create mode 100644 home/neovim/lua/plugins/telescope.lua create mode 100644 home/neovim/lua/plugins/tmux-navigator.lua create mode 100644 home/neovim/lua/plugins/treesitter-context.lua create mode 100644 home/neovim/lua/plugins/treesitter.lua diff --git a/home/neovim/default.nix b/home/neovim/default.nix index 038818e..6418e45 100644 --- a/home/neovim/default.nix +++ b/home/neovim/default.nix @@ -33,10 +33,17 @@ vscode-langservers-extracted ]; extraPython3Packages = pyPkgs: with pyPkgs; [ pylint ]; - plugins = [ pkgs.vimPlugins.packer-nvim ]; + # plugins = [ pkgs.vimPlugins.lazy-nvim ]; extraLuaConfig = builtins.readFile ./init.lua; }; + home.file.lua = { + recursive = true; + source = ./lua; + target = "/.config/nvim/lua"; + }; home.packages = [ pkgs.neovide ]; + + home.file = { notes.source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/Nextcloud/notes"; }; diff --git a/home/neovim/init.lua b/home/neovim/init.lua index 23051e5..e27f6bf 100644 --- a/home/neovim/init.lua +++ b/home/neovim/init.lua @@ -1,471 +1,97 @@ -- luacheck: globals vim -require("packer").startup(function(use) - use('nvim-tree/nvim-web-devicons') - use("freitass/todo.txt-vim") - - use("psliwka/vim-smoothie") - - -- navigation - use("easymotion/vim-easymotion") - use("tpope/vim-unimpaired") - use("tpope/vim-surround") - use("christoomey/vim-tmux-navigator") - - -- fern - use("lambdalisue/fern.vim") - use("lambdalisue/glyph-palette.vim") - use("lambdalisue/fern-git-status.vim") - use("lambdalisue/fern-mapping-git.vim") -- to check - use("lambdalisue/fern-hijack.vim") - use("TheLeoP/fern-renderer-web-devicons.nvim") - - -- airline - use("vim-airline/vim-airline") - use("vim-airline/vim-airline-themes") - - use("tpope/vim-fugitive") - use("airblade/vim-gitgutter") - - use("honza/vim-snippets") - use("SirVer/ultisnips") - - use("junegunn/fzf.vim") - - use("junegunn/goyo.vim") - use("junegunn/limelight.vim") - - use("preservim/nerdcommenter") - - use("luochen1990/rainbow") - use("ap/vim-css-color") - - use("Yggdroot/indentLine") - - use("gruvbox-community/gruvbox") - - -- language support - use("Glench/Vim-Jinja2-Syntax") - use("preservim/vim-markdown") - use("mzlogin/vim-markdown-toc") - use("LnL7/vim-nix") - use("hashivim/vim-terraform") - use("LaTeX-Box-Team/LaTeX-Box") - use("vito-c/jq.vim") - use("tpope/vim-haml") - use("elzr/vim-json") - - use("jpalardy/vim-slime") - - use("neovim/nvim-lspconfig") - use("hrsh7th/nvim-cmp") -- Autocompletion plugin - use("hrsh7th/cmp-nvim-lsp") -- LSP source for nvim-cmp - use("hrsh7th/cmp-buffer") - use("hrsh7th/cmp-path") - use("saadparwaiz1/cmp_luasnip") -- Snippets source for nvim-cmp - use("L3MON4D3/LuaSnip") -- Snippets plugin - use("lukas-reineke/lsp-format.nvim") - - use { - 'nvim-telescope/telescope.nvim', - requires = { { 'nvim-lua/plenary.nvim' } } - } - use { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' } - use { 'nvim-lua/popup.nvim' } - use { 'nvim-telescope/telescope-media-files.nvim' } - use { - 'renerocksai/telekasten.nvim', - requires = { 'nvim-telescope/telescope.nvim' } - } - use { 'nvim-telescope/telescope-symbols.nvim' } - use { 'renerocksai/calendar-vim' } - use { "nvim-telescope/telescope-bibtex.nvim" } - - use("sheerun/vim-polyglot") - - use("nvim-treesitter/nvim-treesitter") -end) +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) vim.g.mapleader = "," vim.g.maplocaleader = "\\" +require("lazy").setup('plugins') -local o = vim.opt +vim.opt.wrap = false +vim.opt.number = true +vim.opt.compatible = false +vim.opt.mouse = "a" -- mouse support +vim.opt.showcmd = true -- show incomplete cmds down the bottom +vim.opt.showmode = true -- show current mode +vim.opt.showmatch = true -- set show matching parenthesis +vim.opt.visualbell = true -- no sounds +vim.opt.autoread = true -- reload files changed outside of vim +vim.opt.backspace = [[indent,eol,start]] -- allow backspacing over everything in insert mode +vim.opt.ignorecase = true -- ignore case when searching +vim.opt.shiftround = true -- use multiple of shiftwidth when indenting with '<' and '>' +vim.opt.smartcase = true -- ignore case if searching pattern is all lowecase, case-sensitive otherwise +vim.opt.smarttab = true -- insert tabs on the start of a line according to shiftwidth, not tabstop +vim.opt.hlsearch = true -- highlight search terms +vim.opt.incsearch = true -- show search matches as you type +vim.opt.hidden = true +vim.opt.ruler = true +vim.opt.clipboard = "unnamed" -- system clipboard +vim.opt.colorcolumn = "80" -local function map(mode, shortcut, command) - vim.api.nvim_set_keymap(mode, shortcut, command, { noremap = true, silent = true }) -end - -local function nmap(shortcut, command) - map("n", shortcut, command) -end - ---local function imap(shortcut, command) --- map("i", shortcut, command) ---end - -o.wrap = false -o.number = true -o.compatible = false -o.mouse = "a" -- mouse support -o.showcmd = true -- show incomplete cmds down the bottom -o.showmode = true -- show current mode -o.showmatch = true -- set show matching parenthesis -o.visualbell = true -- no sounds -o.autoread = true -- reload files changed outside of vim -o.backspace = [[indent,eol,start]] -- allow backspacing over everything in insert mode -o.ignorecase = true -- ignore case when searching -o.shiftround = true -- use multiple of shiftwidth when indenting with '<' and '>' -o.smartcase = true -- ignore case if searching pattern is all lowecase, case-sensitive otherwise -o.smarttab = true -- insert tabs on the start of a line according to shiftwidth, not tabstop -o.hlsearch = true -- highlight search terms -o.incsearch = true -- show search matches as you type -o.hidden = true -o.ruler = true -o.clipboard = "unnamed" -- system clipboard -o.colorcolumn = "80" - -vim.cmd("syntax on") +-- vim.cmd("syntax on") vim.cmd("filetype plugin on") if vim.fn.has("multi_byte") == 1 and vim.o.encoding == "utf-8" then - o.listchars = [[tab:▸ ,extends:❯,precedes:❮,nbsp:±,trail:…]] + vim.opt.listchars = [[tab:▸ ,extends:❯,precedes:❮,nbsp:±,trail:…]] else - o.listchars = [[tab:> ,extends:>,precedes:<,nbsp:.,trail:_]] + vim.opt.listchars = [[tab:> ,extends:>,precedes:<,nbsp:.,trail:_]] end -o.splitbelow = true -o.splitright = true -nmap("", "r") +vim.opt.splitbelow = true +vim.opt.splitright = true +vim.api.nvim_set_keymap('n', "", "r", {}) -nmap("", "1gt") -nmap("", "2gt") -nmap("", "3gt") -nmap("", "4gt") -nmap("", "5gt") -nmap("", "6gt") -nmap("", "7gt") -nmap("", "8gt") -nmap("", ":tablast") +vim.api.nvim_set_keymap('n', "", "1gt", {}) +vim.api.nvim_set_keymap('n', "", "2gt", {}) +vim.api.nvim_set_keymap('n', "", "3gt", {}) +vim.api.nvim_set_keymap('n', "", "4gt", {}) +vim.api.nvim_set_keymap('n', "", "5gt", {}) +vim.api.nvim_set_keymap('n', "", "6gt", {}) +vim.api.nvim_set_keymap('n', "", "7gt", {}) +vim.api.nvim_set_keymap('n', "", "8gt", {}) +vim.api.nvim_set_keymap('n', "", ":tablast", {}) -nmap("", ":nohl") +vim.api.nvim_set_keymap('n', "", ":nohl", { noremap = true }) -- todo: try to do it with `vim.api.nvim_set_hl` vim.cmd("hi CursorLine cterm=NONE,underline ctermbg=NONE") -- highlight line when in insert mode -vim.cmd("hi tklink ctermfg=72 guifg=#689d6a cterm=bold,underline gui=bold,underline") -vim.cmd("hi tkBrackets ctermfg=gray guifg=gray") -o.timeoutlen = 1000 -o.ttimeoutlen = 0 +vim.opt.timeoutlen = 1000 +vim.opt.ttimeoutlen = 0 vim.cmd("autocmd InsertEnter * :set cursorline") vim.cmd("autocmd InsertLeave * :set nocursorline") -- indentation vim.cmd("filetype indent on") -o.softtabstop = 4 -o.expandtab = true -o.shiftwidth = 4 -o.tabstop = 4 -o.autoindent = true -o.copyindent = true +vim.opt.softtabstop = 4 +vim.opt.expandtab = true +vim.opt.shiftwidth = 4 +vim.opt.tabstop = 4 +vim.opt.autoindent = true +vim.opt.copyindent = true -- folds -o.foldmethod = "indent" -o.foldnestmax = 3 -o.foldenable = false +vim.opt.foldmethod = "indent" +vim.opt.foldnestmax = 3 +vim.opt.foldenable = false -o.termguicolors = true -vim.g.gruvbox_contrast_dark = "hard" -vim.g.gruvbox_contrast_light = "hard" -vim.g.gruvbox_italic = 1 -vim.g.gruvbox_invert_indent_guides = 1 -vim.g.gruvbox_vert_split = "bg1" -vim.cmd("colorscheme gruvbox") -o.background = "dark" +vim.opt.termguicolors = true -vim.g.markdown_syntax_conceal = 0 +-- vim.g.markdown_syntax_conceal = 0 -o.updatetime = 100 -- to make gigutter more responsive - -vim.g["fern#renderer"] = "nvim-web-devicons" -vim.cmd([[ -function! s:init_fern() abort - nmap T (fern-action-open:tab) - nmap S (fern-action-open:split) - nmap V (fern-action-open:vsplit) - nmap (fern-action-mark:toggle) -endfunction - -augroup fern-custom - autocmd! * - autocmd FileType fern call s:init_fern() -augroup END - -augroup my-glyph-palette - autocmd! * - autocmd FileType fern call glyph_palette#apply() - autocmd FileType nerdtree,startify call glyph_palette#apply() -augroup END -]]) -nmap("t", ":Fern . -drawer -toggle") -nmap("", ": cd ..") - -vim.g["indentLine_char"] = "▏" -vim.g["indentLine_setConceal"] = 0 - -vim.g["slime_target"] = "tmux" -vim.g["slime_python_ipython"] = 1 - -vim.g["tmux_navigator_no_mappings"] = 1 -nmap("", ":TmuxNavigateLeft") -nmap("", ":TmuxNavigateDown") -nmap("", ":TmuxNavigateUp") -nmap("", ":TmuxNavigateRight") - -vim.g["airline_theme"] = "base16_gruvbox_dark_hard" -vim.g["airline#extensions#tabline#enabled"] = 1 -vim.g["airline#extensions#ale#enabled"] = 1 - -vim.g["deoplete#enable_at_startup"] = 1 - -vim.g["NERDDefaultAlign"] = "left" - -vim.g["UltiSnipsExpandTrigger"] = "" -vim.g["UltiSnipsJumpForwardTrigger"] = "" -vim.g["UltiSnipsJumpBackwardTrigger"] = "" - -local lspconfig = require("lspconfig") -local capabilities = require("cmp_nvim_lsp").default_capabilities() - -lspconfig.pyright.setup { capabilities = capabilities } -lspconfig.ruff_lsp.setup { capabilities = capabilities } - -lspconfig.nixd.setup { capabilities = capabilities } -lspconfig.jsonls.setup { capabilities = capabilities } -lspconfig.beancount.setup { capabilities = capabilities } -lspconfig.ltex.setup { capabilities = capabilities } - -lspconfig.terraformls.setup { capabilities = capabilities } -lspconfig.tflint.setup { capabilities = capabilities } - -lspconfig.docker_compose_language_service.setup { - root_dir = lspconfig.util.root_pattern("docker-compose.yaml", "docker-compose.yml"), - filetypes = { "yaml", "yaml.docker-compose" }, - capabilities = capabilities, -} -lspconfig.dockerls.setup { capabilities = capabilities } - --- lspconfig.sqlls.setup {capabilities = capabilities} - -lspconfig.lua_ls.setup { - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = "LuaJIT", - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { "vim" }, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true), - }, - -- Do not send telemetry data containing a randomized but unique identifier - telemetry = { - enable = false, - }, - }, - }, - capabilities = capabilities -} - -lspconfig.efm.setup { - init_options = { documentFormatting = true }, - filetypes = { "python", "sh" }, - settings = { - rootMarkers = { ".git/", "pyproject.toml" }, - languages = { - python = { { formatCommand = "black -", formatStdin = true } }, - sql = { { - formatCommand = "sqlfluff fix --dialect bigquery -", - formatStdin = true - } }, - sh = { { - formatCommand = "shfmt -i 4 -bn -sr -p -ci", - formatStdin = true, - lintCommand = "shellcheck -f gcc -x", - lintSource = "shellcheck", - lintFormats = { - "%f:%l:%c: %trror: %m", - "%f:%l:%c: %tarning: %m", - "%f:%l:%c: %tote: %m", - } - } }, - }, - }, - capabilities = capabilities -} - -local luasnip = require 'luasnip' -local cmp = require 'cmp' -cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), -- Up - [''] = cmp.mapping.scroll_docs(4), -- Down - -- C-b (back) C-f (forward) for snippet placeholder navigation. - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }, - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { 'i', 's' }), - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { 'i', 's' }), - }), - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'buffer' }, - { name = 'path' }, - }, -} - -vim.api.nvim_create_autocmd("LspAttach", { - group = vim.api.nvim_create_augroup("UserLspConfig", {}), - callback = function(ev) - -- Enable completion triggered by - vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc" - - -- Buffer local mappings. - -- See `:help vim.lsp.*` for documentation on any of the below functions - local opts = { buffer = ev.buf } - vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) - vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) - vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) - vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) - vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) - vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) - vim.keymap.set('n', 'wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, opts) - vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) - vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) - vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, opts) - vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) - vim.keymap.set('n', 'f', function() - vim.lsp.buf.format { async = true } - end, opts) - end, -}) - -local telescope_builtin = require('telescope.builtin') -vim.keymap.set('n', 'ff', telescope_builtin.find_files, {}) -vim.keymap.set('n', 'fg', telescope_builtin.live_grep, {}) -vim.keymap.set('n', 'fb', telescope_builtin.buffers, {}) -vim.keymap.set('n', 'fh', telescope_builtin.help_tags, {}) -vim.keymap.set('n', 'fs', function() - telescope_builtin.symbols({ sources = 'emoji', 'gitmoji', 'nerd' }) -end) -vim.keymap.set('n', 'fb', ":Telescope bibtex") - -local telescope = require("telescope") -telescope.setup { - extensions = { - fzf = { - fuzzy = true, -- false will only do exact matching - override_generic_sorter = true, -- override the generic sorter - override_file_sorter = true, -- override the file sorter - case_mode = "smart_case", -- or "ignore_case" or "respect_case" - -- the default case_mode is "smart_case" - }, - -- media_files = { - -- -- filetypes whitelist - -- -- defaults to {"png", "jpg", "mp4", "webm", "pdf"} - -- filetypes = { "png", "webp", "jpg", "jpeg" }, - -- -- find command (defaults to `fd`) - -- find_cmd = "rg" - -- }, - bibtex = { - global_files = { vim.fn.expand("~/notes/refs") }, - } - } -} -telescope.load_extension("fzf") -telescope.load_extension("media_files") -telescope.load_extension("bibtex") - -require 'nvim-web-devicons'.setup() - -local telekasten = require('telekasten') -telekasten.setup({ - home = vim.fn.expand("~/notes"), - daily = vim.fn.expand("~/notes/daily"), - weeklies = vim.fn.expand("~/notes/weeklies"), - templates = vim.fn.expand("~/notes/templates"), - - -- -- Specific note templates - -- -- set to `nil` or do not specify if you do not want a template - -- template_new_note = '/path/to/file', -- template for new notes - -- template_new_daily = '/path/to/file', -- template for new daily notes - -- template_new_weekly = '/path/to/file', -- template for new weekly notes - -- - image_subdir = "img", - extension = ".md", - - install_syntax = true, - media_previewer = "telescope-media-files", -}) - -vim.keymap.set("n", "z", telekasten.panel) - -vim.keymap.set("n", "zf", telekasten.find_notes) -vim.keymap.set("n", "zd", telekasten.find_daily_notes) -vim.keymap.set("n", "zg", telekasten.search_notes) -vim.keymap.set("n", "zz", telekasten.follow_link) -vim.keymap.set("n", "zT", telekasten.goto_today) -vim.keymap.set("n", "zW", telekasten.goto_thisweek) -vim.keymap.set("n", "zw", telekasten.find_weekly_notes) -vim.keymap.set("n", "zn", telekasten.new_note) -vim.keymap.set("n", "zN", telekasten.new_templated_note) -vim.keymap.set("n", "zy", telekasten.yank_notelink) -vim.keymap.set("n", "zc", telekasten.show_calendar) -vim.keymap.set("n", "zC", ":CalendarT") -vim.keymap.set("n", "zi", telekasten.paste_img_and_link) -vim.keymap.set("n", "zt", telekasten.toggle_todo) -vim.keymap.set("v", "zt", function() telekasten.toggle_todo({ v = true }) end) -vim.keymap.set("n", "zb", telekasten.show_backlinks) -vim.keymap.set("n", "zF", telekasten.find_friends) -vim.keymap.set("n", "zI", function() telekasten.insert_img_link({ i = true }) end) -vim.keymap.set("n", "zp", telekasten.preview_img) -vim.keymap.set("n", "zm", telekasten.browse_media) -vim.keymap.set("n", "#", telekasten.show_tags) -vim.keymap.set("i", "[[", function() telekasten.insert_link({ i = true }) end) -vim.keymap.set("i", "zt", function() telekasten.toggle_todo({ i = true }) end) -vim.keymap.set("i", "#", function() telekasten.show_tags({ i = true }) end) +vim.opt.updatetime = 100 -- to make gigutter more responsive if vim.g.neovide then vim.o.guifont = "Hack Nerd Font:h10" diff --git a/home/neovim/lua/plugins/alpha.lua b/home/neovim/lua/plugins/alpha.lua new file mode 100644 index 0000000..0da0a8a --- /dev/null +++ b/home/neovim/lua/plugins/alpha.lua @@ -0,0 +1,15 @@ +return { + 'goolord/alpha-nvim', + event = "VimEnter", + dependencies = { 'nvim-tree/nvim-web-devicons' }, + config = function() + local alpha = require('alpha') + local dashboard = require('alpha.themes.dashboard') + dashboard.section.header.val = { + [[┌┐┌┌─┐┌─┐┬ ┬┬┌┬┐]], + [[│││├┤ │ │└┐┌┘││││]], + [[┘└┘└─┘└─┘ └┘ ┴┴ ┴]], + } + alpha.setup(dashboard.config) + end +} diff --git a/home/neovim/lua/plugins/cmp.lua b/home/neovim/lua/plugins/cmp.lua new file mode 100644 index 0000000..a0e9675 --- /dev/null +++ b/home/neovim/lua/plugins/cmp.lua @@ -0,0 +1,53 @@ +return { + "hrsh7th/nvim-cmp", -- Autocompletion plugin + dependencies = { + "hrsh7th/cmp-nvim-lsp", -- LSP source for nvim-cmp + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "saadparwaiz1/cmp_luasnip", -- Snippets source for nvim-cmp + "L3MON4D3/LuaSnip", -- Snippets plugin + }, + config = function() + require('cmp').setup { + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = require('cmp').mapping.preset.insert({ + [''] = require('cmp').mapping.scroll_docs(-4), -- Up + [''] = require('cmp').mapping.scroll_docs(4), -- Down + -- C-b (back) C-f (forward) for snippet placeholder navigation. + [''] = require('cmp').mapping.complete(), + [''] = require('cmp').mapping.confirm { + behavior = require('cmp').ConfirmBehavior.Replace, + select = true, + }, + [''] = require('cmp').mapping(function(fallback) + if require('cmp').visible() then + require('cmp').select_next_item() + elseif require('luasnip').expand_or_jumpable() then + require('luasnip').expand_or_jump() + else + fallback() + end + end, { 'i', 's' }), + [''] = require('cmp').mapping(function(fallback) + if require('cmp').visible() then + require('cmp').select_prev_item() + elseif require('luasnip').jumpable(-1) then + require('luasnip').jump(-1) + else + fallback() + end + end, { 'i', 's' }), + }), + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'buffer' }, + { name = 'path' }, + }, + } + end, +} diff --git a/home/neovim/lua/plugins/gruvbox.lua b/home/neovim/lua/plugins/gruvbox.lua new file mode 100644 index 0000000..762c6f9 --- /dev/null +++ b/home/neovim/lua/plugins/gruvbox.lua @@ -0,0 +1,9 @@ +return { + "ellisonleao/gruvbox.nvim", + lazy = false, + priority = 1000, + config = function() + vim.o.background = "dark" + vim.cmd([[colorscheme gruvbox]]) + end +} diff --git a/home/neovim/lua/plugins/indent-blankline.lua b/home/neovim/lua/plugins/indent-blankline.lua new file mode 100644 index 0000000..f78a1fb --- /dev/null +++ b/home/neovim/lua/plugins/indent-blankline.lua @@ -0,0 +1,10 @@ +return { + "lukas-reineke/indent-blankline.nvim", + dependencies = { 'nvim-treesitter/nvim-treesitter' }, + config = { + -- show_current_context = true, + -- show_current_context_start = true, + show_current_context = false, + show_current_context_start = false, + }, +} diff --git a/home/neovim/lua/plugins/init.lua b/home/neovim/lua/plugins/init.lua new file mode 100644 index 0000000..72d7e7d --- /dev/null +++ b/home/neovim/lua/plugins/init.lua @@ -0,0 +1,12 @@ +return { + "psliwka/vim-smoothie", + + -- navigation + "tpope/vim-unimpaired", + "tpope/vim-surround", + + "tpope/vim-fugitive", + "airblade/vim-gitgutter", + + "mzlogin/vim-markdown-toc", +} diff --git a/home/neovim/lua/plugins/lspconfig.lua b/home/neovim/lua/plugins/lspconfig.lua new file mode 100644 index 0000000..c7c1d40 --- /dev/null +++ b/home/neovim/lua/plugins/lspconfig.lua @@ -0,0 +1,110 @@ +return { + "neovim/nvim-lspconfig", + lazy = false, + dependencies = { + "hrsh7th/cmp-nvim-lsp", + }, + config = function() + local capabilities = require("cmp_nvim_lsp").default_capabilities() + local lspconfig = require("lspconfig") + + lspconfig.pyright.setup { capabilities = capabilities } + lspconfig.ruff_lsp.setup { capabilities = capabilities } + + lspconfig.nixd.setup { capabilities = capabilities } + lspconfig.jsonls.setup { capabilities = capabilities } + lspconfig.beancount.setup { capabilities = capabilities } + lspconfig.ltex.setup { capabilities = capabilities } + + lspconfig.terraformls.setup { capabilities = capabilities } + lspconfig.tflint.setup { capabilities = capabilities } + + lspconfig.docker_compose_language_service.setup { + root_dir = lspconfig.util.root_pattern("docker-compose.yaml", "docker-compose.yml"), + filetypes = { "yaml", "yaml.docker-compose" }, + capabilities = capabilities, + } + lspconfig.dockerls.setup { capabilities = capabilities } + + -- lspconfig.sqlls.setup {capabilities = capabilities} + + lspconfig.lua_ls.setup { + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, + capabilities = capabilities + } + + lspconfig.efm.setup { + init_options = { documentFormatting = true }, + filetypes = { "python", "sh" }, + settings = { + rootMarkers = { ".git/", "pyproject.toml" }, + languages = { + python = { { formatCommand = "black -", formatStdin = true } }, + sql = { { + formatCommand = "sqlfluff fix --dialect bigquery -", + formatStdin = true + } }, + sh = { { + formatCommand = "shfmt -i 4 -bn -sr -p -ci", + formatStdin = true, + lintCommand = "shellcheck -f gcc -x", + lintSource = "shellcheck", + lintFormats = { + "%f:%l:%c: %trror: %m", + "%f:%l:%c: %tarning: %m", + "%f:%l:%c: %tote: %m", + } + } }, + }, + }, + capabilities = capabilities + } + + vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("UserLspConfig", {}), + callback = function(ev) + -- Enable completion triggered by + vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc" + end + }) + end, + + keys = { + { 'gD', vim.lsp.buf.declaration }, + { 'gd', vim.lsp.buf.definition }, + { 'K', vim.lsp.buf.hover }, + { 'gi', vim.lsp.buf.implementation }, + { '', vim.lsp.buf.signature_help }, + { 'wa', vim.lsp.buf.add_workspace_folder }, + { 'wr', vim.lsp.buf.remove_workspace_folder }, + { 'D', vim.lsp.buf.type_definition }, + { 'rn', vim.lsp.buf.rename }, + { 'gr', vim.lsp.buf.references }, + { 'ca', vim.lsp.buf.code_action, { 'n', 'v' } }, + { 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end }, + { 'f', function() + vim.lsp.buf.format { async = true } + end }, + }, +} diff --git a/home/neovim/lua/plugins/lualine.lua b/home/neovim/lua/plugins/lualine.lua new file mode 100644 index 0000000..848b1aa --- /dev/null +++ b/home/neovim/lua/plugins/lualine.lua @@ -0,0 +1,10 @@ +return { + 'nvim-lualine/lualine.nvim', + dependenceies = { 'nvim-tree/nvim-web-devicons' }, + config = { + icons_enabled = true, + theme = 'gruvbox_dark', + component_separators = '|', + section_separators = '', + } +} diff --git a/home/neovim/lua/plugins/neo-tree.lua b/home/neovim/lua/plugins/neo-tree.lua new file mode 100644 index 0000000..61d5e64 --- /dev/null +++ b/home/neovim/lua/plugins/neo-tree.lua @@ -0,0 +1,12 @@ +return { + "nvim-neo-tree/neo-tree.nvim", + branch = "v3.x", + cmd = "Neotree", + keys = { { "t", "Neotree toggle" } }, + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", + "MunifTanjim/nui.nvim", + "s1n7ax/nvim-window-picker", + } +} diff --git a/home/neovim/lua/plugins/nerdcommenter.lua b/home/neovim/lua/plugins/nerdcommenter.lua new file mode 100644 index 0000000..8490ce6 --- /dev/null +++ b/home/neovim/lua/plugins/nerdcommenter.lua @@ -0,0 +1,6 @@ +return { + "preservim/nerdcommenter", + config = function () + vim.g["NERDDefaultAlign"] = "left" + end +} diff --git a/home/neovim/lua/plugins/slime.lua b/home/neovim/lua/plugins/slime.lua new file mode 100644 index 0000000..1b5d8c9 --- /dev/null +++ b/home/neovim/lua/plugins/slime.lua @@ -0,0 +1,7 @@ +return { + "jpalardy/vim-slime", + config = function() + vim.g["slime_target"] = "tmux" + vim.g["slime_python_ipython"] = 1 + end +} diff --git a/home/neovim/lua/plugins/telekasten.lua b/home/neovim/lua/plugins/telekasten.lua new file mode 100644 index 0000000..287b58e --- /dev/null +++ b/home/neovim/lua/plugins/telekasten.lua @@ -0,0 +1,57 @@ +return { + 'renerocksai/telekasten.nvim', + dependencies = { + 'nvim-telescope/telescope.nvim', + 'renerocksai/calendar-vim', + { + 'nvim-telescope/telescope-media-files.nvim', + dependencies = { + 'nvim-lua/popup.nvim', + 'nvim-lua/plenary.nvim', + 'nvim-telescope/telescope.nvim', + 'nvim-telescope/telescope-media-files.nvim', + }, + }, + }, + config = function() + require('telekasten').setup { + home = vim.fn.expand("~/notes"), + daily = vim.fn.expand("~/notes/daily"), + weeklies = vim.fn.expand("~/notes/weeklies"), + templates = vim.fn.expand("~/notes/templates"), + auto_set_filetype = false, + install_syntax = true, + media_previewer = "telescope-media-files", + } + vim.cmd("hi tklink ctermfg=72 guifg=#689d6a cterm=bold,underline gui=bold,underline") + vim.cmd("hi tkBrackets ctermfg=gray guifg=gray") + end, + + keys = { + { "z", 'Telekasten panel' }, + { "zf", 'Telekasten find_notes' }, + { "zd", 'Telekasten find_daily_notes' }, + { "zg", 'Telekasten search_notes' }, + { "zz", 'Telekasten follow_link' }, + { "zT", 'Telekasten goto_today' }, + { "zW", 'Telekasten goto_thisweek' }, + { "zw", 'Telekasten find_weekly_notes' }, + { "zn", 'Telekasten new_note' }, + { "zN", 'Telekasten new_templated_note' }, + { "zy", 'Telekasten yank_notelink' }, + { "zc", 'Telekasten show_calendar' }, + { "zi", 'Telekasten paste_img_and_link' }, + { "zt", 'Telekasten toggle_todo' }, + { "zb", 'Telekasten show_backlinks' }, + { "zF", 'Telekasten find_friends' }, + { "zp", 'Telekasten preview_img' }, + { "zm", 'Telekasten browse_media' }, + { "#", 'Telekasten show_tags' }, + { "zI", function() require('telekasten').insert_img_link({ i = true }) end }, + { "zt", function() require('telekasten').toggle_todo({ v = true }) end, "v" }, + { "zt", function() require('telekasten').toggle_todo({ i = true }) end, "i" }, + { "#", function() require('telekasten').show_tags({ i = true }) end, "i" }, + -- { "[[", function() require('telekasten').insert_link({ i = true }) end, "i" }, + { "zC", "CalendarT" }, + }, +} diff --git a/home/neovim/lua/plugins/telescope.lua b/home/neovim/lua/plugins/telescope.lua new file mode 100644 index 0000000..bad5c2c --- /dev/null +++ b/home/neovim/lua/plugins/telescope.lua @@ -0,0 +1,58 @@ +return { + 'nvim-telescope/telescope.nvim', + dependencies = { + { + 'nvim-telescope/telescope-fzf-native.nvim', + build = 'make' + }, + 'nvim-lua/plenary.nvim', + 'nvim-telescope/telescope-symbols.nvim', + "nvim-telescope/telescope-bibtex.nvim", + { + 'nvim-telescope/telescope-media-files.nvim', + dependencies = { + 'nvim-lua/popup.nvim', + 'nvim-lua/plenary.nvim', + 'nvim-telescope/telescope.nvim', + 'nvim-telescope/telescope-media-files.nvim', + }, + }, + }, + config = function() + local telescope = require("telescope") + telescope.setup { + extensions = { + fzf = { + fuzzy = true, -- false will only do exact matching + override_generic_sorter = true, -- override the generic sorter + override_file_sorter = true, -- override the file sorter + case_mode = "smart_case", -- or "ignore_case" or "respect_case" + -- the default case_mode is "smart_case" + }, + -- media_files = { + -- -- filetypes whitelist + -- -- defaults to {"png", "jpg", "mp4", "webm", "pdf"} + -- filetypes = { "png", "webp", "jpg", "jpeg" }, + -- -- find command (defaults to `fd`) + -- find_cmd = "rg" + -- }, + bibtex = { + global_files = { vim.fn.expand("~/notes/refs") }, + } + } + } + telescope.load_extension("fzf") + telescope.load_extension("media_files") + telescope.load_extension("bibtex") + end, + keys = { + { 'ff', 'Telescope find_files' }, + { 'fg', 'Telescope live_grep' }, + { 'fb', 'Telescope buffers' }, + { 'fh', 'Telescope help_tags' }, + { 'fs', function() + require('telescope_builtin').symbols({ sources = 'emoji', 'gitmoji', 'nerd' }) + end }, + -- { 'fb', "Telescope bibtex"} + } +} diff --git a/home/neovim/lua/plugins/tmux-navigator.lua b/home/neovim/lua/plugins/tmux-navigator.lua new file mode 100644 index 0000000..698ed94 --- /dev/null +++ b/home/neovim/lua/plugins/tmux-navigator.lua @@ -0,0 +1,12 @@ +return { + "christoomey/vim-tmux-navigator", + config = function() + vim.g["tmux_navigator_no_mappings"] = 1 + end, + keys = { + { "", "TmuxNavigateLeft" }, + { "", "TmuxNavigateDown" }, + { "", "TmuxNavigateUp" }, + { "", "TmuxNavigateRight" }, + } +} diff --git a/home/neovim/lua/plugins/treesitter-context.lua b/home/neovim/lua/plugins/treesitter-context.lua new file mode 100644 index 0000000..709a921 --- /dev/null +++ b/home/neovim/lua/plugins/treesitter-context.lua @@ -0,0 +1,7 @@ +return { + "nvim-treesitter/nvim-treesitter-context", + dependencies = { 'nvim-treesitter/nvim-treesitter' }, + config = { + enable = true, + }, +} diff --git a/home/neovim/lua/plugins/treesitter.lua b/home/neovim/lua/plugins/treesitter.lua new file mode 100644 index 0000000..2cb7789 --- /dev/null +++ b/home/neovim/lua/plugins/treesitter.lua @@ -0,0 +1,15 @@ +return { + "nvim-treesitter/nvim-treesitter", + dependencies = { "nvim-treesitter/nvim-treesitter-textobjects" }, + build = ":TSUpdate", + config = { + ensure_installed = "all", + sync_install = true, + ignore_install = {}, + auto_install = true, + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + }, + } +}