Skip to content

Commit

Permalink
feat!: modularize all things
Browse files Browse the repository at this point in the history
way easier to maintain, this `init.lua` was getting too big.
  • Loading branch information
realeinherjar committed Sep 15, 2023
1 parent 544b485 commit 251eaec
Show file tree
Hide file tree
Showing 21 changed files with 1,048 additions and 1,032 deletions.
1,035 changes: 3 additions & 1,032 deletions init.lua

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions lua/config/highlight_yank.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-------------------------------------------------------------------------------
-- 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", {
callback = function()
vim.highlight.on_yank()
end,
group = highlight_group,
pattern = "*",
})
5 changes: 5 additions & 0 deletions lua/config/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require("config.options")
require("config.keymaps")
require("config.netrw")
require("config.highlight_yank")
require("config.restore_cursor")
63 changes: 63 additions & 0 deletions lua/config/keymaps.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
-- Keymaps for better default experience
-- See `:help vim.keymap.set()`
vim.keymap.set({ "n", "v" }, "<Space>", "<Nop>", { silent = true })
vim.keymap.set("n", "Q", "<nop>")

-- File explorer
vim.keymap.set("n", "<C-p>", vim.cmd.Ex)

-- Move to window using the <ctrl> hjkl keys
vim.keymap.set("n", "<C-h>", "<C-w>h", { desc = "Go to left window", remap = true })
vim.keymap.set("n", "<C-j>", "<C-w>j", { desc = "Go to lower window", remap = true })
vim.keymap.set("n", "<C-k>", "<C-w>k", { desc = "Go to upper window", remap = true })
vim.keymap.set("n", "<C-l>", "<C-w>l", { desc = "Go to right window", remap = true })

-- Resize window using <ctrl> arrow keys
vim.keymap.set("n", "<C-Up>", "<CMD>resize +2<CR>", { desc = "Increase window height" })
vim.keymap.set("n", "<C-Down>", "<CMD>resize -2<CR>", { desc = "Decrease window height" })
vim.keymap.set("n", "<C-Left>", "<CMD>vertical resize -2<CR>", { desc = "Decrease window width" })
vim.keymap.set("n", "<C-Right>", "<CMD>vertical resize +2<CR>", { desc = "Increase window width" })

-- Better movement
vim.keymap.set("n", "J", "mzJ`z")
vim.keymap.set("n", "<C-d>", "<C-d>zz")
vim.keymap.set("n", "<C-u>", "<C-u>zz")
vim.keymap.set("n", "n", "nzzzv")
vim.keymap.set("n", "N", "Nzzzv")

-- better indenting
vim.keymap.set("v", "<", "<gv")
vim.keymap.set("v", ">", ">gv")

-- Clear search, diff update and redraw
-- taken from runtime/lua/_editor.lua
vim.keymap.set(
"n",
"<leader>R",
"<CMD>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>",
{ desc = "[R]edraw / clear hlsearch / diff update" }
)

-- J/K to move up/down visual lines
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")

-- Remap for dealing with word wrap
vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })

-- Easy save
vim.keymap.set("n", "<leader>w", "<CMD>w<CR>", { silent = true, desc = "[S]ave File" })

-- Easy Quit
vim.keymap.set("n", "<leader>q", "<CMD>q<CR>", { silent = true, desc = "[Q]uit" })
vim.keymap.set("n", "<leader>Q", "<CMD>qa!<CR>", { silent = true, desc = "[Q]uit Force All" })

-- Global Yank/Paste
vim.keymap.set(
{ "n", "v" },
"<leader>y",
'"*y :let @+=@*<CR>',
{ noremap = true, silent = true, desc = "Global [Y]ank" }
)
vim.keymap.set({ "n", "v" }, "<leader>p", '"+p', { noremap = true, silent = true, desc = "Global [P]aste" })
18 changes: 18 additions & 0 deletions lua/config/netrw.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-------------------------------------------------------------------------------
-- Netrw Customizations
-------------------------------------------------------------------------------

vim.g.netrw_browse_split = 0
vim.g.netrw_banner = 0
vim.g.netrw_winsize = 25

vim.api.nvim_create_autocmd("filetype", {
pattern = "netrw",
desc = "Better mappings for netrw",
callback = function()
-- edit new file
vim.keymap.set("n", "n", "%", { remap = true, buffer = true })
-- rename file
vim.keymap.set("n", "r", "R", { remap = true, buffer = true })
end,
})
75 changes: 75 additions & 0 deletions lua/config/options.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
-------------------------------------------------------------------------------
-- Options
-------------------------------------------------------------------------------
-- Set highlight on search
vim.opt.hlsearch = false
vim.opt.incsearch = true

-- Make line numbers default
vim.opt.nu = true
vim.opt.relativenumber = true

-- Tab settings
vim.opt.tabstop = 4
vim.opt.softtabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true

-- Lazy redraw for crazy macros
--vim.opt.lazyredraw = true

-- A lot of plugins depends on hidden true
vim.opt.hidden = true

-- set command line height to zero/two lines
-- vim.opt.cmdheight = 2
vim.opt.cmdheight = 0

-- Statusbar
vim.opt.laststatus = 3

-- Winbar on top of the windows
vim.opt.winbar = "%=%m %f"

-- Enable mouse mode
vim.opt.mouse = "a"

-- Scrolling
vim.opt.scrolloff = 8
vim.opt.sidescrolloff = 8

-- Time in milliseconds to wait for a mapped sequence to complete
vim.opt.timeoutlen = 50

-- No wrap
vim.opt.wrap = false

-- Enable break indent
vim.opt.breakindent = true

-- Better undo history
vim.opt.swapfile = false
vim.opt.backup = false
vim.opt.undodir = vim.fn.stdpath("data") .. "undo"
vim.opt.undofile = true

-- Case insensitive searching UNLESS /C or capital in search
vim.opt.ignorecase = true
vim.opt.smartcase = true

-- Decrease update time
vim.opt.updatetime = 250
vim.wo.signcolumn = "yes"

-- color column
vim.opt.colorcolumn = "80"

-- Window splitting
vim.opt.splitbelow = true
vim.opt.splitright = true

-- [[ Basic Keymaps ]]
-- Set <space> as the leader key
-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used)
vim.g.mapleader = " "
vim.g.maplocalleader = " "
10 changes: 10 additions & 0 deletions lua/config/restore_cursor.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-------------------------------------------------------------------------------
-- Restore Cursors
-------------------------------------------------------------------------------
-- See `:help restore-cursor`
local restore_group = vim.api.nvim_create_augroup("RestoreGroup", { clear = true })
vim.api.nvim_create_autocmd("BufRead", {
command = [[call setpos(".", getpos("'\""))]],
group = restore_group,
pattern = "*",
})
32 changes: 32 additions & 0 deletions lua/plugins/colorscheme.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
return {
{
"folke/tokyonight.nvim", -- Set colorscheme to Gruvbox Theme
lazy = false, -- make sure we load this during startup if it is your main colorscheme
priority = 1000, -- make sure to load this before all
config = function()
require("tokyonight").setup({
transparent = true,
})
vim.o.termguicolors = true
vim.cmd.colorscheme("tokyonight")
end,
keys = {
{ "<leader>l", "<CMD>Lazy<cr>", desc = "[L]azy" },
},
},
{
"nvim-lualine/lualine.nvim", -- Fancier statusline
event = "VeryLazy",
dependencies = { "folke/tokyonight.nvim" },
config = function()
require("lualine").setup({
options = {
icons_enabled = false,
theme = "tokyonight",
component_separators = "|",
section_separators = "",
},
})
end,
},
}
5 changes: 5 additions & 0 deletions lua/plugins/comment.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
return {
"numToStr/Comment.nvim",
config = true,
event = "VeryLazy",
}
11 changes: 11 additions & 0 deletions lua/plugins/flash.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
return {
"folke/flash.nvim", -- Amazing movements
event = "VeryLazy",
-- stylua: ignore
keys = {
{ "s", mode = { "n", "o", "x" }, function() require("flash").jump() end, desc = "Flash" },
-- { "S", mode = { "n", "o", "x" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" }, -- conflicts with nvim.surround `S`.
{ "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" },
{ "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" },
},
}
57 changes: 57 additions & 0 deletions lua/plugins/format.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
return {
"stevearc/conform.nvim",
event = "VeryLazy",
config = function()
require("conform").setup({
formatters_by_ft = {
lua = { "stylua" },
rust = { "rustfmt" },
python = { "isort", "black" }, -- Conform will run multiple formatters sequentially
sh = { "shfmt", "shellharden" },
fish = { "fish_indent" },
nix = { "nixfmt" },
markdown = { { "prettierd", "prettier" }, "markdownlint" }, -- Use a sub-list to run only the first available formatter
html = { { "prettierd", "prettier" } },
css = { { "prettierd", "prettier" } },
javascript = { { "prettierd", "prettier" } },
typescript = { { "prettierd", "prettier" } },
["*"] = { "trim_whitespace" },
},
format_on_save = function(bufnr)
-- Disable with a global or buffer-local variable
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
return { timeout_ms = 500, lsp_fallback = true }
end,
})
require("conform.formatters.markdownlint").command = "markdownlint-cli2"
vim.api.nvim_create_user_command("FormatDisable", function(args)
if args.bang then
-- FormatDisable! will disable formatting just for this buffer
vim.b.disable_autoformat = true
else
vim.g.disable_autoformat = true
end
end, {
desc = "Disable autoformat-on-save",
bang = true,
})
vim.keymap.set("", "<leader>f", function()
require("conform").format({ async = true, lsp_fallback = true })
end, { desc = "[F]ormat" })
vim.api.nvim_create_user_command("FormatEnable", function()
vim.b.disable_autoformat = false
vim.g.disable_autoformat = false
end, {
desc = "Re-enable autoformat-on-save",
})
vim.keymap.set("n", "<leader>F", function()
if vim.b.disable_autoformat or vim.g.disable_autoformat then
vim.cmd("FormatEnable")
else
vim.cmd("FormatDisable")
end
end, { desc = "Toggle [F]ormat" })
end,
}
Loading

0 comments on commit 251eaec

Please sign in to comment.