summaryrefslogtreecommitdiff
path: root/init.lua
blob: c073de897d29350f05d956f0cdc0a110f5696aa4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
-------------------------
-------- Options --------
-------------------------
vim.opt.autoindent = true
vim.opt.backup = false
vim.opt.breakindent = true
vim.opt.expandtab = true
vim.opt.ignorecase = true
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.scrolloff = 8
vim.opt.shiftwidth = 0
vim.opt.smartcase = true
vim.opt.smartindent = true
vim.opt.softtabstop = 4
vim.opt.swapfile = false
vim.opt.swapfile = false
vim.opt.tabstop = 4
vim.opt.termguicolors = true
vim.opt.undodir = vim.fn.expand("~/.local/state/nvim/undodir")
vim.opt.undofile = true
vim.cmd("colorscheme retrobox")

-- Syntax highlighting will be handled by tree-sitter
vim.cmd('syntax off')

-------------------------
-------- Keymaps --------
-------------------------
vim.g.mapleader = ' '

local function map(mode, left, right, opts)
    local default_opts = {
        noremap = true,
        silent = true,
    }
    opts = opts or {}
    -- "keep" mode preserves the values from the leftmost table,
    -- so prioritize any options provided over the defaults
    local full_opts = vim.tbl_extend("keep", opts, default_opts)
    vim.keymap.set(mode, left, right, full_opts)
end

-- Toggle background mode (light/dark)
map("n", "<leader>ct", function() 
    local target = vim.o.bg == "dark" and "light" or "dark"
    vim.opt.background = target
end, { desc = "Toggle background mode (light/dark)" })

-- Clear any highlighted searches when pressing Esc
-- This lets me leave hlsearch on by default while having an easy way to clear
-- it again.
map({ "i", "n" }, "<esc>", "<cmd>noh<cr><esc>", { desc = "Escape and clear hlsearch" })

-- Move lines while in visual mode with J and K
map("v", "J", ":m '>+1<CR>gv=gv")
map("v", "K", ":m '<-2<CR>gv=gv")

-- Keep cursor in the same place when using J to join lines
map("n", "J", "mzJ`z")

-- Center the screen when jumping around with C-d and C-u
map("n", "<C-d>", "<C-d>zz")
map("n", "<C-u>", "<C-u>zz")

-- Center the screen when jumping to next / previous search terms
map("n", "n", "nzzzv")
map("n", "N", "Nzzzv")

-- Quick maps to paste/delete without overwriting the current buffer
map("x", "<leader>p", '"_dP')
map({ "n", "v" }, "<leader>d", '"_dP')

-- System clipboard
map({ "n", "v" }, "<leader>cd", '"+d', { desc = "Clipboard delete" })
map({ "n", "v" }, "<leader>cp", '"+p', { desc = "Clipboard paste" })
map({ "n", "v" }, "<leader>cy", '"+y', { desc = "Clipboard yank" })

-------------------------
-------- Plugins --------
-------------------------
vim.pack.add {
    'https://github.com/stevearc/oil.nvim',
    'https://github.com/nvim-treesitter/nvim-treesitter',
}

-- Oil
require('oil').setup({
    skip_confirm_for_simple_edits = true,
    columns = {"size", "mtime"},
    map("n", "g-", vim.cmd.Oil, { desc = "Open Oil" }),
})

-- Tree-sitter
require('nvim-treesitter').setup()
vim.api.nvim_create_autocmd('FileType', {
    callback = function() pcall(vim.treesitter.start) end,
})