From cfcea95348e5ae55bebec06f0d777bde2e730dd5 Mon Sep 17 00:00:00 2001 From: Rostyslav Hnatyshyn Date: Wed, 25 Sep 2024 01:25:00 -0700 Subject: [PATCH] finished big nvim overhaul --- nvim/cheatsheet.txt | 18 +++ nvim/init.lua | 286 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 256 insertions(+), 48 deletions(-) diff --git a/nvim/cheatsheet.txt b/nvim/cheatsheet.txt index 380bdfd..8bb3ebd 100644 --- a/nvim/cheatsheet.txt +++ b/nvim/cheatsheet.txt @@ -19,6 +19,24 @@ Diff | hd Preview hunk | hp Reset hunk | hr +## Comment +Line (normal & visual mode )| gc +Block (normal & visual mode) | gb +At the end of a line | gcA + +## Surround +With () | ysiw) +With "" | ys$" +Del [] | ds] +Del HTML | dst +'' -> "" & "" -> '' | cs'" +Change HTML tag to [TAG] | cst[TAG] +Del () in fn call; fn(param) -> param | dsf + +## Dial +Increment | +Decrement | + ## Misc Outline | o Trouble | xx diff --git a/nvim/init.lua b/nvim/init.lua index 3865e68..ce53ffb 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,5 +1,10 @@ -- some basic options local vim = vim + +-- nvim tree said to disable netrw +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 + vim.opt.tabstop = 4 vim.opt.shiftwidth = 4 vim.opt.softtabstop = 2 @@ -11,8 +16,7 @@ vim.opt.smarttab = true vim.opt.number = true vim.o.hidden = true vim.o.signcolumn = 'auto' -vim.o.breakindent = true -vim.o.smarttab = true +-- vim.o.breakindent = false -- I think this looks bad vim.o.errorbells = true vim.o.clipboard = "unnamedplus" vim.g.noswapfile = true @@ -20,10 +24,15 @@ vim.cmd [[set mouse=a]] -- enable mouse vim.wo.cursorline = true vim.opt.hlsearch = false vim.opt.wrap = true +vim.opt.linebreak = true vim.opt.showmatch = true vim.opt.completeopt = { 'menu', 'menuone', 'noselect', 'noinsert' } vim.opt.shortmess = vim.opt.shortmess + "c" -vim.api.nvim_set_option("clipboard", "unnamed") + +vim.o.laststatus = 3 +vim.o.cmdheight = 0 -- hides commandbar when not in use, looks ok + +vim.opt.spelllang = 'en_us' vim.g.python3_host_prog = '/home/frosty/.dotfiles/nvim/env/bin/python' @@ -31,7 +40,6 @@ vim.api.nvim_create_user_command('W', 'write', {}) vim.opt.foldmethod = "expr" vim.opt.foldexpr = "nvim_treesitter#foldexpr()" - -- hit zc to enable folding vim.o.foldenable = false @@ -89,6 +97,13 @@ map("t", "t", "FloatermToggle") nmap("dd", " lua vim.diagnostic.open_float() ") +vim.keymap.set("n", "", function() + require("dial.map").manipulate("increment", "normal") +end) +vim.keymap.set("n", "", function() + require("dial.map").manipulate("decrement", "normal") +end) + local augroup = vim.api.nvim_create_augroup("Lspformatting", {}) -- lsp on_attach mappings @@ -138,17 +153,17 @@ end local lsp = require "lspconfig" local lsp_defaults = lsp.util.default_config - -lsp.hls.setup { on_attach = on_attach } -- haskell language server -lsp.pyright.setup { on_attach = on_attach } -lsp.svelte.setup { on_attach = on_attach } - -local capabilities = vim.lsp.protocol.make_client_capabilities() +local capabilities = require('cmp_nvim_lsp').default_capabilities() capabilities.offsetEncoding = { "utf-16" } + lsp.clangd.setup { on_attach = on_attach, capabilities = capabilities } -lsp.ts_ls.setup { on_attach = on_attach } -lsp.marksman.setup { on_attach = on_attach } +lsp.ts_ls.setup { on_attach = on_attach, capabilities = capabilities } +lsp.hls.setup { on_attach = on_attach, capabilities = capabilities } -- haskell language server +lsp.pyright.setup { on_attach = on_attach, capabilities = capabilities } +lsp.svelte.setup { on_attach = on_attach, capabilities = capabilities } +lsp.marksman.setup { on_attach = on_attach, capabilities = capabilities } lsp.rust_analyzer.setup { on_attach = on_attach, + capabilities = capabilities, settings = { ["rust-analyzer"] = { checkOnSave = true, @@ -161,6 +176,7 @@ lsp.rust_analyzer.setup { on_attach = on_attach, } } lsp.lua_ls.setup { on_attach = on_attach, + capabilities = capabilities, settings = { Lua = { diagnostics = { @@ -169,8 +185,13 @@ lsp.lua_ls.setup { on_attach = on_attach, } } } -lsp.tailwindcss.setup { on_attach = on_attach } + +lsp.tailwindcss.setup { on_attach = on_attach, + capabilities = capabilities +} + lsp.julials.setup { + capabilities = capabilities, on_new_config = function(new_config, _) local julia = vim.fn.expand("~/.julia/environments/nvim-lspconfig/bin/julia") if lsp.util.path.is_file(julia) then @@ -188,6 +209,14 @@ vim.api.nvim_create_autocmd("VimLeave", { command = "silent !killall -q eslint_d", }) +--[[ local vertical_help = vim.api.nvim_create_augroup("vertical_help", {}) +vim.api.nvim_create_autocmd("FileType", { + pattern = 'help', + group = vertical_help, + command = ":windcmd L" +}) +]] + -- packer boilerplate local fn = vim.fn local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' @@ -196,25 +225,7 @@ if fn.empty(fn.glob(install_path)) > 0 then install_path }) end --- add code actions listeners? ---lua/code_action_utils.lua ---[[local M = {} - -local lsp_util = vim.lsp.util - -function M.code_action_listener() - local context = { diagnostics = vim.lsp.diagnostic.get_line_diagnostics() } - local params = lsp_util.make_range_params() - params.context = context - vim.lsp.buf_request(0, 'textDocument/codeAction', params, function(err, result, ctx, config) - -- do something with result - e.g. check if empty and show some indication such as a sign - end) -end - -return M]] --- - -vim.cmd("colorscheme carbonfox") +vim.cmd("colorscheme iceberg") return require('packer').startup(function(use) use 'wbthomason/packer.nvim' @@ -231,6 +242,9 @@ return require('packer').startup(function(use) } end } + use { + 'echasnovski/mini.icons' + } use { 'nvim-tree/nvim-web-devicons', } @@ -238,15 +252,26 @@ return require('packer').startup(function(use) 'nvim-tree/nvim-tree.lua', after = "nvim-web-devicons", requires = "nvim-tree/nvim-web-devicons", - config = function() require('nvim-tree').setup {} end + config = function() + require('nvim-tree').setup { + hijack_cursor = true, + disable_netrw = true, + select_prompts = true, + renderer = { + add_trailing = true, + hidden_display = "all", + highlight_opened_files = "icon" + } + } + end } use { "hrsh7th/nvim-cmp", requires = { "hrsh7th/cmp-buffer", "hrsh7th/cmp-nvim-lsp", "L3MON4D3/LuaSnip", "rafamadriz/friendly-snippets", - 'hrsh7th/cmp-nvim-lua', 'octaltree/cmp-look', 'hrsh7th/cmp-path', 'hrsh7th/cmp-calc', - 'f3fora/cmp-spell', 'hrsh7th/cmp-emoji' + 'hrsh7th/cmp-nvim-lua', 'hrsh7th/cmp-path', + 'hrsh7th/cmp-calc', 'hrsh7th/cmp-cmdline', 'f3fora/cmp-spell', }, config = function() local cmp = require("cmp") @@ -265,6 +290,7 @@ return require('packer').startup(function(use) { name = 'luasnip', keyword_length = 2 }, }, window = { + completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered() }, formatting = { @@ -285,9 +311,6 @@ return require('packer').startup(function(use) [''] = cmp.mapping.select_prev_item(select_opts), [''] = cmp.mapping.select_next_item(select_opts), - [''] = cmp.mapping.select_prev_item(select_opts), - [''] = cmp.mapping.select_next_item(select_opts), - [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), @@ -312,7 +335,25 @@ return require('packer').startup(function(use) end, { 'i', 's' }), } }) - end + + cmp.setup.cmdline({ '/', '?' }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' } + } + }) + + -- to select something in the cmdline need to use + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }), + matching = { disallow_symbol_nonprefix_matching = false } + }) + end, } use { 'nvimtools/none-ls.nvim', @@ -404,6 +445,15 @@ return require('packer').startup(function(use) config = function() require("bufferline").setup { options = { + offsets = { + { + filetype = "NvimTree", + text = "Neovim - Files", + highlight = "Directory", + separator = true + }, + }, + separator_style = "slope", diagnostics = "nvim_lsp", } } @@ -414,8 +464,35 @@ return require('packer').startup(function(use) event = "VimEnter", config = function() require("lualine").setup { - options = { theme = 'auto', globalstatus = true }, - sections = { lualine_x = { 'filetype' } } + extensions = { 'nvim-tree', 'fzf', 'symbols-outline' }, + options = { + component_separators = '', + section_separators = { left = '', right = '' }, + theme = 'iceberg_dark', + globalstatus = true, + }, + sections = { + -- would be nice to open code actions but w/e + lualine_b = { + { + 'diff', + }, + }, + lualine_c = { + { + 'diagnostics', + sources = { 'nvim_diagnostic', 'nvim_lsp' }, + sections = { 'hint', 'warn', 'error' }, + colored = true, + update_in_insert = true, + always_visible = false, + on_click = function() + require("trouble").toggle("diagnostics") + end + } + }, + lualine_x = { 'filetype' } + } } end, requires = { 'nvim-tree/nvim-web-devicons', opt = true } @@ -423,9 +500,62 @@ return require('packer').startup(function(use) use { "startup-nvim/startup.nvim", after = "nvim-web-devicons", - requires = { "nvim-tree/nvim-web-devicons", "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim" }, + requires = { + "nvim-tree/nvim-web-devicons", + "nvim-telescope/telescope.nvim", + "nvim-lua/plenary.nvim" + }, config = function() - require "startup".setup() + local startup = require("startup") + local headers = require("startup.headers") + local start_fn = require("startup.functions") + startup.setup({ + banner = { + type = "text", + align = "center", + title = "Header", + content = headers.hydra_header, + highlight = "Statement", + }, + quote = { + type = "text", + align = "center", + fold_section = false, + title = "Quote", + margin = 5, + content = require("startup.functions").quote(), + highlight = "Constant", + default_color = "", + }, + body = { + type = "mapping", + align = "center", + fold_section = false, + title = "Basic Commands", + margin = 5, + content = { + { " New File", "lua require'startup'.new_file()", "nf" }, + { " Recent Files", "Telescope oldfiles", "of" }, + { " Find File", "Telescope find_files", "ff" }, + }, + highlight = "String", + default_color = "", + }, + plugin_info = { + type = "text", + content = require("startup.functions").packer_plugins(), + align = "center", + fold_section = false, + title = "", + margin = 5, + highlight = "TSString", + default_color = "#FFFFFF", + }, + options = { + mapping_keys = true, + }, + parts = { "banner", "quote", "body", "plugin_info" } + }) end } use 'RRethy/vim-illuminate' @@ -443,14 +573,11 @@ return require('packer').startup(function(use) end } use 'voldikss/vim-floaterm' - use { - 'kkoomen/vim-doge', - run = ':call doge#install()' - } use { 'norcalli/nvim-colorizer.lua', config = function() require('colorizer').setup { 'css', + 'scss', 'javascript', 'toml' } @@ -479,5 +606,68 @@ return require('packer').startup(function(use) if packer_bootstrap then require('packer').sync() end - use "EdenEast/nightfox.nvim" + use { + "danymat/neogen", + config = function() + local neogen = require('neogen') + neogen.setup({ + snippet_engine = "luasnip", + placeholders_hl = "None" -- fixes weird bug where the entire page gets colored with this color + }) + nmap('d', ":lua require('neogen').generate()") + end + } + use { + "folke/which-key.nvim", + config = function() + local which_key = require('which-key') + which_key.setup({ + preset = "modern" + }) + end + , + } + use { + 'numToStr/Comment.nvim', + config = function() + require('Comment').setup() + end + } + use({ + "kylechui/nvim-surround", + tag = "*", -- Use for stability; omit to use `main` branch for the latest features + config = function() + require("nvim-surround").setup({ + -- Configuration here, or leave empty to use defaults + }) + end + }) + use { + 'pwntester/octo.nvim', + requires = { + 'nvim-lua/plenary.nvim', + 'nvim-telescope/telescope.nvim', + 'nvim-tree/nvim-web-devicons', + }, + config = function() + require "octo".setup() + end + } + use { + "monaqa/dial.nvim", + config = function() + local augend = require("dial.augend") + local dial = require("dial.config") + local d_map = require("dial.map") + + dial.augends:register_group { + default = { + augend.integer.alias.decimal, + augend.date.alias["%m/%d"], + augend.constant.alias.alpha, + } + } + end + } + use "cocopon/iceberg.vim" end)