Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Neovim config in lua with NvChad and Lazy #124

Merged
merged 4 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions config/nvim/autoload/mdsanima.vim

This file was deleted.

43 changes: 0 additions & 43 deletions config/nvim/colors/mdsanima.vim

This file was deleted.

58 changes: 58 additions & 0 deletions config/nvim/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-- Initial configuration for the Neovim editor with Lazy, Mason, NvChad, and other cool plugins.

-- The other configs will be loaded automatically and will be loaded on startup. The entire
-- configuration setup for the Neovim editor is defined in this file and other files in the `lua`
-- directory on this repo. Make sure to check these files for more information.

-- Config is based on NvChad starter. See docs: https://github.com/NvChad/starter
-- Some options is from NormalNvim. See docs: https://github.com/NormalNvim/NormalNvim

-- The config are still a work in progress and subject to change. I still need to think about this.

-- NvChad starter with cache and key leader
vim.g.base46_cache = vim.fn.stdpath "data" .. "/nvchad/base46/"
vim.g.mapleader = " "

-- Bootstrap lazy and all plugins
local lazy_path = vim.fn.stdpath "data" .. "/lazy/lazy.nvim/"
local lazy_conf = require "base.lazy"

if not vim.uv.fs_stat(lazy_path) then
local lazy_repo = "https://github.com/folke/lazy.nvim.git"
vim.fn.system { "git", "clone", "--filter=blob:none", lazy_repo, "--branch=stable", lazy_path }
end

vim.opt.rtp:prepend(lazy_path)

-- Load plugins
require("lazy").setup({
{
"NvChad/NvChad",
lazy = false,
branch = "v2.5",
import = "nvchad.plugins",
},

{ import = "plugins" },
}, lazy_conf)

-- Load themes
dofile(vim.g.base46_cache .. "defaults")
dofile(vim.g.base46_cache .. "statusline")

-- Custom modules
require "mdsanima.autocmds"
require "mdsanima.commands"
require "mdsanima.options"

vim.schedule(function()
require "mdsanima.mappings"
end)

-- Custom configs
local tree_conf = require "base.tree"
local null_conf = require "base.null"

-- Custom options
require("nvim-tree").setup(tree_conf)
require("null-ls").setup(null_conf)
10 changes: 0 additions & 10 deletions config/nvim/init.vim

This file was deleted.

18 changes: 18 additions & 0 deletions config/nvim/lua/base/format.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Base configuration for `conform.nvim` plugin.

return {
formatters_by_ft = {
lua = { "stylua" },
css = { "prettier" },
html = { "prettier" },
c = { "clang-format" },
cpp = { "clang-format" },
cmake = { "gersemi" },
["_"] = { "trim_whitespace" },
},

format_on_save = {
timeout_ms = 500,
lsp_fallback = true,
},
}
51 changes: 51 additions & 0 deletions config/nvim/lua/base/lazy.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-- Base configuration for `lazy.nvim` plugin.

return {
defaults = { lazy = true },
install = { colorscheme = { "nvchad" } },

ui = {
icons = {
ft = " ",
lazy = "󰂠 ",
loaded = " ",
not_loaded = " ",
},
},

performance = {
rtp = {
disabled_plugins = {
"2html_plugin",
"bugreport",
"compiler",
"ftplugin",
"getscript",
"getscriptPlugin",
"gzip",
"logipat",
"matchit",
"netrw",
"netrwFileHandlers",
"netrwPlugin",
"netrwSettings",
"optwin",
"rplugin",
"rrhelper",
"spellfile_plugin",
"synmenu",
"syntax",
"tar",
"tarPlugin",
"tohtml",
"tutor",
"vimball",
"vimballPlugin",
"zip",
"zipPlugin",
},
},
},

lockfile = vim.fn.stdpath "cache" .. "/lazy-lock.json",
}
18 changes: 18 additions & 0 deletions config/nvim/lua/base/lsp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Base configuration for `nvim-lspconfig` plugin.

-- Load defaults configuration i.e lua_lsp
require("nvchad.configs.lspconfig").defaults()

local lspconfig = require "lspconfig"

local servers = { "html", "cssls", "clangd", "cmake" }
local nvlsp = require "nvchad.configs.lspconfig"

-- Default LSP configuration
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
on_attach = nvlsp.on_attach,
on_init = nvlsp.on_init,
capabilities = nvlsp.capabilities,
}
end
10 changes: 10 additions & 0 deletions config/nvim/lua/base/null.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Base configuration for `none-ls.nvim` plugin.

return {
sources = {
require("null-ls").builtins.diagnostics.commitlint.with {
command = "commitlint",
extra_args = { "--config", ".commitlintrc.mjs" },
},
},
}
40 changes: 40 additions & 0 deletions config/nvim/lua/base/tree.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- Base configuration for `nvim-tree` plugin.

return {
git = {
ignore = false,
},

filters = {
custom = { "^\\.git$" },
dotfiles = false,
},

renderer = {
icons = {
glyphs = {
git = {
unstaged = "✗",
staged = "✓",
unmerged = "",
renamed = "➜",
untracked = "★",
deleted = "",
ignored = "",
},
folder = {
arrow_closed = "",
arrow_open = "",
default = "",
open = "",
empty = "",
empty_open = "",
symlink = "",
symlink_open = "",
},
},
padding = " ",
},
highlight_git = true,
},
}
16 changes: 16 additions & 0 deletions config/nvim/lua/chadrc.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- This file needs to have same structure as `nvconfig.lua` file.
-- See NvChad config: https://github.com/NvChad/ui/blob/v2.5/lua/nvconfig.lua

---@type ChadrcConfig
local M = {}

M.base46 = {
theme = "tokyonight",

hl_override = {
Comment = { italic = true },
["@comment"] = { italic = true },
},
}

return M
9 changes: 9 additions & 0 deletions config/nvim/lua/mdsanima/autocmds.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- General autocommands. This is a good place to put command that you want to run on every startup.

require "nvchad.autocmds"

-- Back to default terminal cursor style blinking block when leaving the Neovim editor
vim.api.nvim_create_autocmd("VimLeave", {
pattern = "*",
command = "set guicursor=a:block1-blinkon1",
})
15 changes: 15 additions & 0 deletions config/nvim/lua/mdsanima/commands.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- General commands. The commands are loaded on demand. This is a good place to put commands that
-- you want to run on every startup.

-- Example command
local mdsanima = {}

function mdsanima.hello()
print "Hello world from the example command on MDSANIMA"
end

vim.api.nvim_create_user_command("HelloWorld", function()
mdsanima.hello()
end, {})

return mdsanima
42 changes: 42 additions & 0 deletions config/nvim/lua/mdsanima/mappings.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-- Key mappings. These are loaded on demand. This is a good place to put key mappings that you
-- want to run on every startup.

-- NOTE: The key mapping for the 'Visual Block' is not working on Windows Terminal with the
-- keyboard shortcut `CTRL+V` and the solution is to use `CTRL+Q` instead. On the Visual Studio
-- Code and Neovim extension the keyboard shortcut `CTRL+V` is working normally. You can unbind
-- the `CTRL+V` on the Windows Terminal and bind `CTRL+SHIFT+V` instead for the copy text.

require "nvchad.mappings"

local map = vim.keymap.set

-- General
map("n", ";", ":", { desc = "CMD Enter command mode" })
map("i", "jk", "<ESC>")

-- Get folding working with Visual Studio Code and Neovim extension
if vim.g.vscode then
local vsmap = vim.api.nvim_set_keymap

-- Mappings for folding and unfolding
vsmap("n", "zM", ":call VSCodeNotify('editor.foldAll')<CR>", { noremap = true })
vsmap("n", "zR", ":call VSCodeNotify('editor.unfoldAll')<CR>", { noremap = true })
vsmap("n", "zc", ":call VSCodeNotify('editor.fold')<CR>", { noremap = true })
vsmap("n", "zC", ":call VSCodeNotify('editor.foldRecursively')<CR>", { noremap = true })
vsmap("n", "zo", ":call VSCodeNotify('editor.unfold')<CR>", { noremap = true })
vsmap("n", "zO", ":call VSCodeNotify('editor.unfoldRecursively')<CR>", { noremap = true })
vsmap("n", "za", ":call VSCodeNotify('editor.toggleFold')<CR>", { noremap = true })

-- Function for move cursor with macro recording
function MoveCursor(directrion)
if vim.fn.reg_recording() == "" and vim.fn.reg_executing() == "" then
return "g" .. directrion
else
return directrion
end
end

-- Mappings for moving with recording
vsmap("n", "j", "v:lua.MoveCursor('j')", { expr = true })
vsmap("n", "k", "v:lua.MoveCursor('k')", { expr = true })
end
39 changes: 39 additions & 0 deletions config/nvim/lua/mdsanima/options.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- Custom configuration setting options.

require "nvchad.options"

local o = vim.o

-- Base options
o.autoindent = true
o.autoread = true
o.backup = true
o.clipboard = "unnamedplus"
o.colorcolumn = "100"
o.encoding = "utf-8"
o.expandtab = true
o.history = 1000
o.ignorecase = true
o.incsearch = true
o.linespace = 100
o.linebreak = true
o.list = true
o.listchars = "extends:→,precedes:←,nbsp:·,trail:·,tab:» ,"
o.mouse = "a"
o.number = true
o.relativenumber = true
o.scrolloff = 8
o.shiftwidth = 4
o.showbreak = "↪ "
o.smartcase = true
o.splitbelow = true
o.splitright = true
o.tabstop = 4
o.undofile = true
o.writebackup = true

-- Base dirs
o.backupdir = vim.fn.stdpath "cache" .. "/backup/"
o.directory = vim.fn.stdpath "cache" .. "/swap/"
o.undodir = vim.fn.stdpath "cache" .. "/undo/"
o.viewdir = vim.fn.stdpath "cache" .. "/view/"
Loading