commit e93e15cda3b5efa0554898e0cb144536d88d6c37 Author: Penguin Date: Wed Mar 29 22:01:27 2023 -0500 added stuff diff --git a/README.org b/README.org new file mode 100644 index 0000000..5fda0e5 --- /dev/null +++ b/README.org @@ -0,0 +1,43 @@ +* Getting Started with Neovim/Lunarvim +** Background Information +This guide will go over very surface-level stuff for lunarvim. It will covering installing neovim and then lunarvim. It will also cover very basic configuration options. + +** What is Neovim? Lunarvim? +Neovim is a "forked, more feature-rich version of [vim]". It utilizes lua to do its configuration, but vimscript also works just fine in it. In text editors like neovim and emacs, there aren't /settings/ like how a normal IDE or text editor might handle configuration. This is a good thing and a bad thing. On one hand, it means that literally every part of the text editor is yours to configure. Once you are done with it, the text editor is /your/ text editor. Rather than settings, you will make your changes to the editor with *code*. The bad thing about this is that it is more work, but that doesn't /have/ to be a bad thing. It's only a bad thing if you let it become a bad thing. More on this later. + +These configurations you make via code are called... configs. Think of LunarVim is a well put-together config, with a lot of features set up out of the box. It essentially moves a lot of the initial configuration away from you and into the hands of the lunarvim devs. That being said, it is still neovim and is still 100% configurable. + +** Why use a text editor like lunarvim? +Lunarvim is a great starter text editor because it sets you up to configure things the way you want with lots of documentation without having to focus on primitive features most text-editors already have like a file explorer or window tabs. Think about it like this: Have you ever wanted some really niche feature that most people wouldn't want? In something like VSCode, this is a hard sell. If the extension doesn't exist, you're welcome to try developing it yourself, but that's (in my opinion) an entire project all on its own. In something like neovim or emacs, your tiny feature has probably already been implemented by someone on the internet, and even if it hasn't, it's probably only a small snippet of code to make it happen. +I also have to throw in the low hanging fruits of perks: speed, power, and portability. + +** Installing Neovim on ubuntu +#+begin_src +sudo snap install nvim +#+end_src +One downside of ubuntu is snaps. They are a bait. They generally suck. They are slow. The security features are basically security theater. However, it is the easiest way to install a somewhat up-to-date version of neovim. + +That's really it. I'm not sure why I made this a whole section. +** Installing LunarVim +Before we install lunarvim, let's make one thing clear. Lunarvim is not a /program/. It's literally a super well-thought out config file. I cannot stress that enough because it is important! + +AND before we install lunarvim, we should install some prerequisites. These aren't /necessary/, but you want them. I'm going to assume we already have pip installed. Let's install rust: +*** Why are we installing rust? +We are installing rust because it installs cargo, the rust package manager. We can use that to install rust programs and toolchains. The only rust program we really care about is *ripgrep*. Ripgrep is like grep, except ripgrep is, scientifically speaking, fast as f!^k. It will allow you to find keywords in extremely large projects insanely fast, if not instantaneously. +*** Installing rust +#+begin_src +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh +source "$HOME"/.cargo/env # this is just refreshing your environment so it sees the cargo binary +#+end_src + +*** Installing Lunarvim + +#+begin_src +LV_BRANCH='release-1.2/neovim-0.8' bash <(curl -s https://raw.githubusercontent.com/lunarvim/lunarvim/fc6873809934917b470bff1b072171879899a36b/utils/installer/install.sh) +#+end_src +The above snippet is from lunarvims official website: https://www.lunarvim.org/docs/installation +If any dependencies are missing, it should tell you what you're missing. +*** What did this just do? +If you want to know specifically what we just did, open the install.sh file and inspect it! I will give a general overview if you don't want to do that: +The install script is really well put together. It verifies that your neovim will work with lunarvim and then it installs lunarvim to ~/.config/lvim. It also installs dependencies (like ripgrep) through cargo, pip, and npm, though I opt not to use npm and say no to that during the install. +Inside of your ~/.config/lvim folder, you'll find a config.lua file. That's your config! diff --git a/config.lua b/config.lua new file mode 100755 index 0000000..ff66a7e --- /dev/null +++ b/config.lua @@ -0,0 +1,386 @@ +--[[ +lvim is the global options object + +Linters should be +filled in as strings with either +a global executable or a path to +an executable +]] +-- THESE ARE EXAMPLE CONFIGS FEEL FREE TO CHANGE TO WHATEVER YOU WANT + +-- vim.cmd [[set nomodeline]] +-- vim.cmd [[set modelines=0]] + +-- general +lvim.log.level = "warning" +lvim.format_on_save = false +lvim.colorscheme = "space-vim-dark" +vim.lsp.set_log_level("debug") + +local tables = { "clangd" } +vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, tables, 1, #tables) +vim.list_extend(lvim.lsp.override, tables, 1, #tables) + +local clangd_bin = "clangd" +-- local clangd_flags = { +-- "--query-driver=/usr/bin/arm-none-eabi*", +-- "--background-index", "--pch-storage=memory", "-j=4", "--log=verbose", +-- -- "--path-mappings=/from=/to", +-- } +local clangd_flags = { + "--query-driver=/usr/bin/g++-12", + "--background-index", "--pch-storage=memory", "-j=4", "--log=verbose", + -- "--path-mappings=/from=/to", +} + + +-- Example +local custom_on_attach = function(client, bufnr) + require("lvim.lsp").common_on_attach(client, bufnr) + local opts = { noremap = true, silent = true } + vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "lua vim.lsp.buf.implementation()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "", "lua vim.lsp.buf.signature_help()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "lh", "ClangdSwitchSourceHeader", opts) + vim.api.nvim_buf_create_user_command(bufnr, 'FormatRegion', function(_opts) + local format_opts = { async = false} + + if _opts.range > 0 then + format_opts.range = { + { _opts.line1, 0 }, + { _opts.line2, 0 }, + } + end + vim.lsp.buf.format(format_opts) + + end, { range = true }) + +end + +local opts = { + cmd = { clangd_bin, unpack(clangd_flags) }, + on_attach = custom_on_attach, +} + +require("lvim.lsp.manager").setup("clangd", opts) +-- keymappings [view all the defaults by pressing Lk] +lvim.leader = "space" +lvim.keys.normal_mode[""] = ":w" + +lvim.builtin.terminal.open_mapping = [[]] +lvim.builtin.terminal.direction = "horizontal" + +local keymap_opts = { noremap = true, silent = true } +vim.api.nvim_set_keymap("v", "p", '"_dP', keymap_opts) +-- unmap a default keymapping +-- lvim.keys.normal_mode[""] = false +-- edit a default keymapping +-- lvim.keys.normal_mode[""] = ":q" + +-- Change Telescope navigation to use j and k for navigation and n and p for history in both input and normal mode. +-- we use protected-mode (pcall) just in case the plugin wasn't loaded yet. +-- local _, actions = pcall(require, "telescope.actions") +-- lvim.builtin.telescope.defaults.mappings = { +-- -- for input mode +-- i = { +-- [""] = actions.move_selection_next, +-- [""] = actions.move_selection_previous, +-- [""] = actions.cycle_history_next, +-- [""] = actions.cycle_history_prev, +-- }, +-- -- for normal mode +-- n = { +-- [""] = actions.move_selection_next, +-- [""] = actions.move_selection_previous, +-- }, +-- } + +lvim.builtin.which_key.mappings["G"] = { + "Glow", "Markdown Preview" +} + + +lvim.builtin.which_key.vmappings["f"] = { + "FormatRegion", "Format Region", +} +-- Telescope +lvim.builtin.which_key.mappings["f"] = { + name = "+Finder", + f = { "Telescope find_files", "Find files" }, + g = { "Telescope live_grep", "Live Grep" } +} + +lvim.builtin.which_key.mappings["t"] = { + name = "+Trouble", + r = { "Trouble lsp_references", "References" }, + f = { "Trouble lsp_definitions", "Definitions" }, + d = { "Trouble document_diagnostics", "Diagnostics" }, + q = { "Trouble quickfix", "QuickFix" }, + l = { "Trouble loclist", "LocationList" }, + w = { "Trouble workspace_diagnostics", "Wordspace Diagnostics" }, +} + +lvim.builtin.which_key.mappings["w"] = { + name = "+Window", + [""] = { "h", "Jump to Left Buffer" }, + [""] = { "j", "Jump to Below Buffer" }, + [""] = { "k", "Jump to Above Buffer" }, + [""] = { "l", "Jump to Right Buffer" }, + h = { ":bprevious", "Previous buffer tab" }, + l = { ":bnext", "Next buffer tab" }, + x = { "BufferKill", "Close Buffer" } +} + +-- TODO: User Config for predefined plugins +-- After changing plugin config exit and reopen LunarVim, Run :PackerInstall :PackerCompile +lvim.builtin.alpha.active = true +lvim.builtin.alpha.mode = "dashboard" +lvim.builtin.bufferline.options.close_command = ":BufDel %d" +lvim.builtin.terminal.active = true +lvim.builtin.nvimtree.setup.view.side = "left" +-- lvim.builtin.nvimtree.show_icons.git = 0 + +-- if you don't want all the parsers change this to a table of the ones you want +lvim.builtin.treesitter.ensure_installed = { + "bash", + "c", + "javascript", + "json", + "lua", + "python", + "typescript", + "tsx", + "css", + "rust", + "java", + "yaml", +} + +lvim.builtin.treesitter.ignore_install = { "haskell" } +lvim.builtin.treesitter.highlight.enabled = true +lvim.builtin.treesitter.rainbow.enable = true +lvim.builtin.treesitter.indent = false + +lvim.lsp.diagnostics.virtual_text = false + + +-- generic LSP settings + +-- ---@usage disable automatic installation of servers +-- lvim.lsp.automatic_servers_installation = false + +-- ---@usage Select which servers should be configured manually. Requires `:LvimCacheReset` to take effect. +-- See the full default list `:lua print(vim.inspect(lvim.lsp.override))` +-- vim.list_extend(lvim.lsp.override, { "pylsp" }) + +-- ---@usage setup a server -- see: https://www.lunarvim.org/languages/#overriding-the-default-configuration +-- local opts = {} -- check the lspconfig documentation for a list of all possible options +-- require("lvim.lsp.manager").setup("pylsp", opts) + +-- -- you can set a custom on_attach function that will be used for all the language servers +-- -- See +-- lvim.lsp.on_attach_callback = function(client, bufnr) +-- local function buf_set_option(...) +-- vim.api.nvim_buf_set_option(bufnr, ...) +-- end +-- --Enable completion triggered by +-- buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") +-- end + +-- -- set a formatter, this will override the language server formatting capabilities (if it exists) +-- local formatters = require "lvim.lsp.null-ls.formatters" +-- formatters.setup { +-- { command = "black", filetypes = { "python" } }, +-- { command = "isort", filetypes = { "python" } }, +-- { +-- -- each formatter accepts a list of options identical to https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md#Configuration +-- command = "prettier", +-- ---@usage arguments to pass to the formatter +-- -- these cannot contain whitespaces, options such as `--line-width 80` become either `{'--line-width', '80'}` or `{'--line-width=80'}` +-- extra_args = { "--print-with", "100" }, +-- ---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports. +-- filetypes = { "typescript", "typescriptreact" }, +-- }, +-- } + +-- -- set additional linters +-- local linters = require "lvim.lsp.null-ls.linters" +-- linters.setup { +-- { command = "flake8", filetypes = { "python" } }, +-- { +-- -- each linter accepts a list of options identical to https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md#Configuration +-- command = "shellcheck", +-- ---@usage arguments to pass to the formatter +-- -- these cannot contain whitespaces, options such as `--line-width 80` become either `{'--line-width', '80'}` or `{'--line-width=80'}` +-- extra_args = { "--severity", "warning" }, +-- }, +-- { +-- command = "codespell", +-- ---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports. +-- filetypes = { "javascript", "python" }, +-- }, +-- } + + +-- Additional Plugins +lvim.plugins = { + { "liuchengxu/space-vim-dark" }, + { "p00f/nvim-ts-rainbow" }, + { + "folke/trouble.nvim", + cmd = "TroubleToggle", + }, + { "ellisonleao/glow.nvim" }, + { + "TimUntersberger/neogit", + requires = "nvim-lua/plenary.nvim", + requires = "sindrets/diffview.nvim", + require('neogit').setup { + disable_signs = false, + disable_hint = false, + disable_context_highlighting = false, + disable_commit_confirmation = false, + auto_refresh = true, + disable_builtin_notifications = false, + use_magit_keybindings = false, + kind = "tab", + console_timeout = 2000, + auto_show_console = true, + commit_popup = { + kind = "split", + }, + popup = { + kind = "split", + }, + signs = { + -- { CLOSED, OPENED } + section = { ">", "v" }, + item = { ">", "v" }, + hunk = { "", "" }, + }, + integrations = { + diffview = true + }, + sections = { + untracked = { + folded = false + }, + unstaged = { + folded = false + }, + staged = { + folded = false + }, + stashes = { + folded = true + }, + unpulled = { + folded = true + }, + unmerged = { + folded = false + }, + recent = { + folded = true + }, + }, + -- override/add mappings + mappings = { + -- modify status buffer mappings + status = { + -- Adds a mapping with "B" as key that does the "BranchPopup" command + ["B"] = "BranchPopup", + -- -- Removes the default mapping of "s" + -- ["s"] = "", + } + } + } + }, + { + "sindrets/diffview.nvim", + requires = "nvim-lua/plenary.nvim", + }, +} + +-- lvim.plugins = { +-- {"folke/tokyonight.nvim"}, +-- { +-- "folke/trouble.nvim", +-- cmd = "TroubleToggle", +-- }, +-- } + +-- Autocommands (https://neovim.io/doc/user/autocmd.html) +-- lvim.autocommands.custom_groups = { +-- { "BufWinEnter", "*.lua", "setlocal ts=8 sw=8" }, +-- } + +local options = { + backup = true, -- creates a backup file + clipboard = "unnamedplus", -- allows neovim to access the system clipboard + cmdheight = 2, -- more space in the neovim command line for displaying messages + completeopt = { "menuone", "noselect" }, -- mostly just for cmp + conceallevel = 0, -- so that `` is visible in markdown files + fileencoding = "utf-8", -- the encoding written to a file + hlsearch = true, -- highlight all matches on previous search pattern + ignorecase = true, -- ignore case in search patterns + mouse = "a", -- allow the mouse to be used in neovim + pumheight = 10, -- pop up menu height + showmode = false, -- we don't need to see things like -- INSERT -- anymore + showtabline = 2, -- always show tabs + smartcase = true, -- smart case + smartindent = false, -- make indenting smarter again + splitbelow = true, -- force all horizontal splits to go below current window + splitright = true, -- force all vertical splits to go to the right of current window + swapfile = true, -- creates a swapfile + termguicolors = true, -- set term gui colors (most terminals support this) + timeoutlen = 1000, -- time to wait for a mapped sequence to complete (in milliseconds) + undofile = true, -- enable persistent undo + updatetime = 300, -- faster completion (4000ms default) + writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited + expandtab = false, -- convert tabs to spaces + shiftwidth = 4, -- the number of spaces inserted for each indentation + tabstop = 4, -- insert 2 spaces for a tab + cursorline = true, -- highlight the current line + number = true, -- set numbered lines + relativenumber = false, -- set relative numbered lines + numberwidth = 4, -- set number column width to 2 {default 4} + signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time + wrap = false, -- display lines as one long line + scrolloff = 8, -- is one of my fav + sidescrolloff = 8, + guifont = "monospace:h17", -- the font used in graphical neovim applications + backupdir = "/home/penguin/.vim/backup//", + directory = "/home/penguin/.vim/swap//", +} + +for k, v in pairs(options) do + vim.opt[k] = v +end + + + +vim.cmd [[ +augroup RestoreCursorShapeOnExit + autocmd! + autocmd VimSuspend,VimLeave * set guicursor=a:ver50 +augroup END]] + +vim.cmd [[ + augroup Markdown + autocmd! + autocmd FileType markdown setlocal wrap shiftwidth=2 tabstop=2 + augroup END +]] + +vim.cmd [[ + augroup Lua + autocmd! + autocmd FileType lua setlocal shiftwidth=2 tabstop=2 + augroup END +]] + +-- vim.opt.cinoptions:append("=0")