Neovim: Add config, switch to it from Vim

This commit is contained in:
Riyyi
2024-02-11 18:11:01 +01:00
parent 88dc203b9f
commit 9cc18db3ba
18 changed files with 1372 additions and 1 deletions
+29
View File
@@ -0,0 +1,29 @@
--------------------------------------------
--- Commands ---
-- Prevent typo
vim.cmd [[
cnoreabbrev <expr> W (getcmdtype() is# ":" && getcmdline() is# "W") ? ("w") : ("W")
cnoreabbrev <expr> Q (getcmdtype() is# ":" && getcmdline() is# "Q") ? ("q") : ("Q")
cnoreabbrev <expr> WQ (getcmdtype() is# ":" && getcmdline() is# "WQ") ? ("wq") : ("WQ")
cnoreabbrev <expr> Wq (getcmdtype() is# ":" && getcmdline() is# "Wq") ? ("wq") : ("Wq")
]]
--------------------------------------------
--- Autocommands ---
-- Cut off trailing whitespace and trailing blank lines
local core = require("core.functions")
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
pattern = "*",
callback = core.trim_buffer,
})
-- Highlight on yank
-- See `:help vim.highlight.on_yank()`
local highlight_group = vim.api.nvim_create_augroup("YankHighlight", { clear = true })
vim.api.nvim_create_autocmd("TextYankPost", {
pattern = "*",
group = highlight_group,
callback = function() vim.highlight.on_yank() end,
})
+48
View File
@@ -0,0 +1,48 @@
--- Behavior ---
-- vim.opt.autochdir = true
vim.opt.clipboard = "unnamedplus"
vim.opt.encoding = "utf-8"
vim.opt.fileencoding = "utf-8"
vim.opt.mouse = "a"
vim.opt.scrolloff = 8
vim.opt.signcolumn = "yes" -- always show gutter/fringe
vim.opt.ttimeoutlen = 0
-- Case-insensitive searching UNLESS \C or capital in search
vim.opt.ignorecase = true
vim.opt.smartcase = true
--- Editing ---
vim.opt.number = true
vim.opt.breakindent = true
vim.opt.backspace = "indent,eol,start"
vim.opt.expandtab = false
vim.opt.shiftround = true
vim.opt.shiftwidth = 4
vim.opt.softtabstop = 4
vim.opt.tabstop = 4
vim.opt.smartindent = true
vim.opt.wrap = false
--- Files
vim.opt.backup = true
vim.opt.backupdir = vim.fn.stdpath("cache") .. "/backup"
vim.opt.swapfile = false
vim.opt.undofile = true
vim.opt.undodir = vim.fn.stdpath("cache") .. "/undodir"
vim.opt.shadafile = vim.fn.stdpath("cache") .. "/netrwhist"
--- UI ---
vim.opt.colorcolumn = "81"
vim.opt.completeopt = "menuone,noselect"
vim.opt.cursorline = true
vim.opt.termguicolors = true
vim.opt.title = true
+72
View File
@@ -0,0 +1,72 @@
local M = {}
M.is_buffer_a_file = function()
local buffer_name = vim.fn.bufname()
return buffer_name ~= "" and vim.fn.filereadable(buffer_name) == 1
end
M.get_file_path = function()
if not M.is_buffer_a_file() then
return nil
end
local file_path = vim.fn.expand("%:p")
return vim.fn.fnamemodify(file_path, ":h") .. "/"
end
M.get_netrw_path = function() -- b:netrw_curdir
if vim.fn.expand("#" .. vim.fn.bufnr()) == "0" then
return nil
end
return vim.fn.fnamemodify(vim.fn.bufname(), ":p")
end
M.get_current_directory = function()
return M.get_file_path() or M.get_netrw_path() or vim.fn.getcwd()
end
M.find_project_root = function()
local current_directory = M.get_current_directory()
local directory = current_directory
while directory ~= "/" do
local git_directory = directory .. "/.git"
local project_file = directory .. "/.project"
if vim.fn.isdirectory(git_directory) == 1 or vim.fn.filereadable(project_file) == 1 then
return directory
end
directory = vim.fn.fnamemodify(directory, ":h")
end
return nil, current_directory
end
-- This will merge tables with index-value pairs and keep the unique values
M.table_merge_unique = function(...)
local result = {}
local seen_values = {}
for _, value in ipairs(vim.tbl_flatten(...)) do
if not seen_values[value] then
seen_values[value] = true
table.insert(result, value)
end
end
return result
end
-- Cut off trailing whitespace and trailing blank lines
-- https://vi.stackexchange.com/questions/37421/how-to-remove-neovim-trailing-white-space
-- https://stackoverflow.com/questions/7495932/how-can-i-trim-blank-lines-at-the-end-of-file-in-vim
M.trim_buffer = function()
local save_cursor = vim.fn.getpos(".")
pcall(function() vim.cmd([[%s/\s\+$//e]]) end)
pcall(function() vim.cmd([[%s#\($\n\s*\)\+\%$##]]) end)
vim.fn.setpos(".", save_cursor)
end
return M
+19
View File
@@ -0,0 +1,19 @@
-- Usage:
-- :lua P("Hello World!")
P = function(v)
print(vim.inspect(v))
return v
end
RELOAD = function(...)
return require("plenary.reload").reload_module(...)
end
R = function(name)
RELOAD(name)
return require(name)
end
LOG = function(v)
vim.fn.writefile({ vim.inspect(v) }, "/tmp/nvim-log", "a")
end
+6
View File
@@ -0,0 +1,6 @@
-- Set <space> as the leader key
-- See `:help mapleader`
-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used)
vim.keymap.set({ "n", "v" }, "<Space>", "<Nop>", { silent = true })
vim.g.mapleader = " "
vim.g.maplocalleader = " "