Initial commit

This commit is contained in:
ItsDrike 2022-10-29 20:25:42 +02:00
parent b912871070
commit a3e01caebf
No known key found for this signature in database
GPG key ID: B014E761034AF742
157 changed files with 9696 additions and 0 deletions

View file

@ -0,0 +1,30 @@
-- Define an abbreviation
local function abbrev(mode, input, result, reabbrev)
reabbrev = reabbrev or false
local command
if reabbrev then
command = mode .. "abbrev"
else
command = mode .. "noreabbrev"
end
vim.cmd(command .. " " .. input .. " " .. result)
end
-- In case I have caps on (don't judge me for using caps)
abbrev("c", "Wq", "wq")
abbrev("c", "wQ", "wq")
abbrev("c", "WQ", "wq")
abbrev("c", "WQ!", "wq")
abbrev("c", "wQ!", "wq")
abbrev("c", "Wq!", "wq")
abbrev("c", "W", "w")
abbrev("c", "W!", "w!")
abbrev("c", "Q", "q!")
abbrev("c", "Q!", "q!")
abbrev("c", "Qall", "qall")
abbrev("c", "Qall!", "qall")
abbrev("c", "QALL", "qall")
abbrev("c", "QALL!", "qall")
-- Save file with sudo
abbrev("c", "w!!", "w !sudo tee > /dev/null %")

View file

@ -0,0 +1,19 @@
-- Autocommands (https://neovim.io/doc/user/autocmd.html)
-- Delete all trailing whitespace on saving
vim.api.nvim_create_autocmd("BufWritePre", { pattern = "*.py", command = [[%s/\s\+$//e]] })
-- Set text wrap to 119 characters
vim.api.nvim_create_autocmd("BufWinEnter", { pattern = "*.md", command = "setlocal tw=119" })
-- Jump to last position when opening a file
vim.api.nvim_create_autocmd("BufReadPost", {
pattern = "*",
command = [[if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif]],
})
-- Highlight current line number
vim.api.nvim_create_autocmd("ColorScheme", { pattern = "*", command = "highlight CursorLine guibg=#2b2b2b" })
vim.api.nvim_create_autocmd("ColorScheme", {
pattern = "*",
command = "highlight CursorLineNr guifg=#1f85de ctermfg=LightBlue",
})
-- Custom syntax definitions based on file extensions
vim.api.nvim_create_autocmd("BufRead", { pattern = "*.axml", command = "set ft=xml" })

View file

@ -0,0 +1,118 @@
-- keymappings [view all the defaults by pressing <leader>Lk]
lvim.leader = "space"
-- Common shortcuts
lvim.keys.normal_mode["<C-s>"] = ":w<CR>"
lvim.keys.insert_mode["<C-s>"] = "<Esc>:w<CR>i"
lvim.keys.normal_mode["<C-z>"] = ":undo<CR>"
lvim.keys.normal_mode["<C-y>"] = ":redo<CR>"
-- Moevements
lvim.keys.normal_mode["H"] = "^"
lvim.keys.normal_mode["L"] = "$"
-- Moving through buffers
lvim.keys.normal_mode["<A-l>"] = ":BufferLineCycleNext<CR>"
lvim.keys.normal_mode["<A-h>"] = ":BufferLineCyclePrev<CR>"
lvim.keys.normal_mode["<A-L>"] = ":BufferLineMoveNext<CR>"
lvim.keys.normal_mode["<A-H>"] = ":BufferLineMovePrev<CR>"
-- Opening various menus
lvim.keys.normal_mode["<C-n>"] = ":NvimTreeFindFileToggle<CR>"
lvim.keys.normal_mode["<C-f>"] = ":Lf<CR>"
lvim.keys.normal_mode["<A-m>"] = ":MinimapToggle<CR>"
lvim.keys.normal_mode["<A-s>"] = ":SymbolsOutline<CR>"
-- Delete to void register
lvim.keys.visual_mode["<A-d>"] = '"_d'
lvim.keys.normal_mode["<A-d>"] = '"_d'
lvim.keys.visual_mode["<A-p>"] = '"_dP'
lvim.keys.visual_mode["p"] = '"_dP'
-- Remove highlight
lvim.keys.normal_mode["<esc><esc>"] = ":nohlsearch<cr>"
-- Debugger
lvim.keys.normal_mode["<F9>"] = ":DapToggleBreakpoint<CR>"
lvim.keys.normal_mode["<F5>"] = ":DapContinue<CR>"
lvim.keys.normal_mode["<F6>"] = ":DapToggleRepl<CR>"
lvim.keys.normal_mode["<S-F5>"] = ":DapTerminate<CR>"
lvim.keys.normal_mode["<F10>"] = ":DapStepOver<CR>"
lvim.keys.normal_mode["<F11>"] = ":DapStepInto<CR>"
lvim.keys.normal_mode["<S-F11>"] = ":DapStepOut<CR>"
lvim.builtin.which_key.mappings["h"] = {
name = "+Hop",
w = { "<cmd>HopWord<CR>", "Word" },
p = { "<cmd>HopPattern<CR>", "Pattern" },
a = { "<cmd>HopAnywhere<CR>", "Anywhere" },
v = { "<cmd>HopVertical<CR>", "Vertical" },
}
-- Quick word replacing (use . for next word)
lvim.keys.normal_mode["cn"] = "*``cgn"
lvim.keys.normal_mode["cN"] = "*``cgN"
-- Quick replace all
vim.api.nvim_set_keymap("n", "<A-r>", "", {
noremap = true,
callback = function()
vim.fn.inputsave()
local query = vim.fn.input "To replace: "
vim.fn.inputsave()
local answer = vim.fn.input("Replace text: ", query)
vim.api.nvim_command("%s/\\V" .. query:gsub("/", "\\/") .. "/" .. answer:gsub("/", "\\/") .. "/")
vim.fn.inputrestore()
vim.api.nvim_feedkeys("v", "n", false)
end,
})
vim.api.nvim_set_keymap("v", "<A-r>", "", {
noremap = true,
callback = function()
local getselection = function()
return vim.fn.strcharpart(vim.fn.getline(vim.fn.line "."), vim.fn.min {
vim.fn.charcol ".",
vim.fn.charcol "v",
} - 1, vim.fn.abs(vim.fn.charcol "." - vim.fn.charcol "v") + 1)
end
local query = getselection()
vim.fn.inputsave()
local answer = vim.fn.input("Replace text: ", query)
vim.api.nvim_command("%s/\\V" .. query:gsub("/", "\\/") .. "/" .. answer:gsub("/", "\\/") .. "/")
vim.fn.inputrestore()
vim.api.nvim_feedkeys("v", "n", false)
end,
})
-- 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 = {
-- ["<C-j>"] = actions.move_selection_next,
-- ["<C-k>"] = actions.move_selection_previous,
-- ["<C-n>"] = actions.cycle_history_next,
-- ["<C-p>"] = actions.cycle_history_prev,
-- },
-- -- for normal mode
-- n = {
-- ["<C-j>"] = actions.move_selection_next,
-- ["<C-k>"] = actions.move_selection_previous,
-- },
-- }
-- Use which-key to add extra bindings with the leader-key prefix
-- lvim.builtin.which_key.mappings["P"] = { "<cmd>Telescope projects<CR>", "Projects" }
-- lvim.builtin.which_key.mappings["t"] = {
-- name = "+Trouble",
-- r = { "<cmd>Trouble lsp_references<cr>", "References" },
-- f = { "<cmd>Trouble lsp_definitions<cr>", "Definitions" },
-- d = { "<cmd>Trouble document_diagnostics<cr>", "Diagnostics" },
-- q = { "<cmd>Trouble quickfix<cr>", "QuickFix" },
-- l = { "<cmd>Trouble loclist<cr>", "LocationList" },
-- w = { "<cmd>Trouble workspace_diagnostics<cr>", "Workspace Diagnostics" },
-- }

View file

@ -0,0 +1,68 @@
-- generic LSP settings
-- -- make sure server will always be installed even if the server is in skipped_servers list
-- lvim.lsp.installer.setup.ensure_installed = {
-- "sumeko_lua",
-- "jsonls",
-- }
-- -- change UI setting of `LspInstallInfo`
-- -- see <https://github.com/williamboman/nvim-lsp-installer#default-configuration>
-- lvim.lsp.installer.setup.ui.check_outdated_servers_on_open = false
-- lvim.lsp.installer.setup.ui.border = "rounded"
-- lvim.lsp.installer.setup.ui.keymaps = {
-- uninstall_server = "d",
-- toggle_server_expand = "o",
-- }
-- ---@usage disable automatic installation of servers
lvim.lsp.installer.setup.automatic_installation = false
-- ---configure a server manually. !!Requires `:LvimCacheReset` to take effect!!
-- ---see the full default list `:lua print(vim.inspect(lvim.lsp.automatic_configuration.skipped_servers))`
-- vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "pyright" })
-- local opts = {} -- check the lspconfig documentation for a list of all possible options
-- require("lvim.lsp.manager").setup("pyright", opts)
-- ---remove a server from the skipped list, e.g. eslint, or emmet_ls. !!Requires `:LvimCacheReset` to take effect!!
-- ---`:LvimInfo` lists which server(s) are skipped for the current filetype
-- lvim.lsp.automatic_configuration.skipped_servers = vim.tbl_filter(function(server)
-- return server ~= "emmet_ls"
-- end, lvim.lsp.automatic_configuration.skipped_servers)
-- -- you can set a custom on_attach function that will be used for all the language servers
-- -- See <https://github.com/neovim/nvim-lspconfig#keybindings-and-completion>
-- 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 <c-x><c-o>
-- buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
-- end
-- set a formatter, this will override the language server formatting capabilities (if it exists)
lvim.format_on_save = false
local formatters = require "lvim.lsp.null-ls.formatters"
formatters.setup {
-- 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 = "black", filetypes = { "python" } },
{ command = "isort", filetypes = { "python" } },
{
command = "prettier",
extra_args = { "--print-width", "100" },
filetypes = { "typescript", "typescriptreact" },
},
{ command = "stylua", filetypes = { "lua" } },
-- { command = "rustfmt", filetypes = { "rust" } },
}
-- set additional linters
local linters = require "lvim.lsp.null-ls.linters"
linters.setup {
-- 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 = "flake8", filetypes = { "python" } },
{ command = "shellcheck", extra_args = { "--severity", "warning" } },
{ command = "codespell", filetypes = { "javascript", "python" } },
{ command = "luacheck", filetypes = { "lua" } },
}

View file

@ -0,0 +1,3 @@
-- Add location (row:col) to lualine
local components = require "lvim.core.lualine.components"
lvim.builtin.lualine.sections.lualine_z = { components.location }

View file

@ -0,0 +1,24 @@
-- Show whitespaces
vim.opt.list = true -- Enable showing characters like <Tab>, <EOL>
vim.opt.listchars = { tab = "", trail = "·" } -- Specify which characters to show
-- Theme options
vim.opt.cursorline = true -- Highlight cursor line
vim.opt.laststatus = 2 -- Always show status line
vim.opt.relativenumber = true -- Use relative line numbers
vim.opt.wrap = true -- Allow line wrapping
-- Tab/Indent settings
-- vim.opt.autoindent = true -- Enable automatic indenting
-- vim.opt.expandtab = true -- Expand tabs into spaces
-- vim.opt.tabstop = 2 -- Number of spaces a tab in file accounts for
-- vim.opt.shiftwidth = 4 -- Indentation size for Tab
-- vim.opt.softtabstop = 4 -- Tabs/Spaces interlop
-- vim.opt.tabpagemax = 50 -- More tabs
-- vim.opt.shiftround = true -- Always round indent to multiple of shiftwidth
-- Enable syntax highlighting in fenced markdown code-blocks
vim.g.markdown_fenced_languages = {"html", "javascript", "typescript", "css", "scss", "lua", "vim", "python"}
-- Other
vim.opt.shell = "/bin/sh"

View file

@ -0,0 +1,101 @@
-- Additional Plugins
lvim.plugins = {
{ "wakatime/vim-wakatime" },
-- LSP
{
-- Tree-like view for symbols in current file using LSP
"simrat39/symbols-outline.nvim",
config = function()
require("symbols-outline").setup {
width = 18,
autofold_depth = 1,
}
end,
},
{
-- Show function signature while typing
"ray-x/lsp_signature.nvim",
config = function()
require("lsp_signature").on_attach()
end,
event = "BufRead",
},
-- User interface
{
-- Code minimap for easy orientation in a longer file
"wfxr/minimap.vim",
run = "cargo install --locked code-minimap",
config = function()
vim.cmd "let g:minimap_width = 10"
end,
},
{
-- Integrated lf file manager
"ptzz/lf.vim",
config = function()
vim.g.lf_map_keys = 0
end,
requires = "voldikss/vim-floaterm",
},
-- Github copilot for code completion
{
"zbirenbaum/copilot.lua",
event = { "VimEnter" },
config = function()
vim.defer_fn(function()
require("copilot").setup()
end, 100)
end,
},
{ "zbirenbaum/copilot-cmp", after = { "copilot.lua", "nvim-cmp" } },
--
{ "jasonccox/vim-wayland-clipboard" },
-- Yuck.vim (eww configuration language support)
{ "elkowar/yuck.vim" },
-- Treesitter
-- {
-- -- Colorize matching parenthesis using treesitter
-- "p00f/nvim-ts-rainbow",
-- },
{
-- Treesitter information shown directly in neovim
"nvim-treesitter/playground",
},
{
-- Alwats show class/function name we're in
"romgrk/nvim-treesitter-context",
config = function()
require("treesitter-context").setup {
enable = true, -- Enable this plugin (Can be enabled/disabled later via commands)
throttle = true, -- Throttles plugin updates (may improve performance)
max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit.
patterns = { -- Match patterns for TS nodes. These get wrapped to match at word boundaries.
-- For all filetypes
-- Note that setting an entry here replaces all other patterns for this entry.
-- By setting the 'default' entry below, you can control which nodes you want to
-- appear in the context window.
default = {
"class",
"function",
"method",
"while",
"for",
"if",
"switch",
"case",
},
},
}
end,
},
}
-- Register copilot as cmp source
lvim.builtin.cmp.formatting.source_names["copilot"] = "(Copilot)"
table.insert(lvim.builtin.cmp.sources, 1, { name = "copilot" })

View file

@ -0,0 +1,42 @@
-- 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 = {}
lvim.builtin.treesitter.highlight.enabled = true
-- lvim.builtin.treesitter.rainbow.enable = true
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.apparmor = {
install_info = {
url = "~/Personal/Programming/GitHub/Other/tree-sitter-apparmor", -- local path or git repo
files = {"src/parser.c"},
-- optional entries:
branch = "main", -- default branch in case of git repo if different from master
generate_requires_npm = false, -- if stand-alone parser without npm dependencies
requires_generate_from_grammar = false, -- if folder contains pre-generated src/parser.c
},
filetype = "apparmor", -- if filetype does not match the parser name
}
local ft_to_parser = require"nvim-treesitter.parsers".filetype_to_parsername
ft_to_parser.apparmor = "apparmor"
-- Temporary treesitter
lvim.keys.normal_mode["gu"] = ":TSUpdate apparmor<CR>"
lvim.keys.normal_mode["gU"] = ":TSToggle apparmor<CR>"
lvim.keys.normal_mode["gt"] = ":TSPlaygroundToggle<CR>"
lvim.keys.normal_mode["gh"] = ":TSNodeUnderCursor<CR>"
lvim.keys.normal_mode["gH"] = ":TSHighlightCapturesUnderCursor<CR>"