-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
175 lines (146 loc) · 5.15 KB
/
init.lua
File metadata and controls
175 lines (146 loc) · 5.15 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
---@diagnostic disable: undefined-global
-- Keymap setup helper
local h = require("helpers")
local map = h.map
-- Set global stuff
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- Disable unused providers to silence checkhealth warnings
vim.g.loaded_node_provider = 0
vim.g.loaded_perl_provider = 0
vim.g.loaded_python3_provider = 0
vim.g.loaded_ruby_provider = 0
-- Windows shell setup
if vim.fn.has("win32") == 1 then
vim.opt.shell = "pwsh.exe"
vim.opt.shellcmdflag = "-NoLogo -ExecutionPolicy RemoteSigned -Command"
-- tee is a GNU utility, on windows output to a file
vim.opt.shellpipe = ">%s 2>&1"
vim.opt.shellredir = ">%s 2>&1"
-- For handling spaces in Windows paths correctly
vim.opt.shellquote = ""
vim.opt.shellxquote = ""
end
vim.opt.grepprg = "rg --vimgrep --smart-case --follow"
vim.o.mouse = ""
vim.o.clipboard = "unnamedplus"
vim.o.pumheight = 20
vim.o.cmdheight = 0
vim.o.cursorline = true
vim.o.number = true
vim.o.relativenumber = true
vim.o.wrap = false
vim.o.breakindent = true
vim.o.showmode = false
vim.o.scrolloff = 2
vim.o.sidescrolloff = 2
vim.o.splitbelow = true
vim.o.splitright = true
vim.opt.fillchars = { eob = " ", fold = " ", foldclose = "", foldopen = "", foldsep = " ", vert = " " }
vim.o.foldlevel = 99
vim.o.foldtext =
[[' '.getline(v:foldstart).' ... '.trim(getline(v:foldend)).' | '.(v:foldend-v:foldstart+1).' lines']]
vim.o.signcolumn = "yes"
vim.o.inccommand = "split"
vim.o.confirm = true
vim.o.ignorecase = true
vim.o.smartcase = true
vim.o.undofile = true
vim.opt.sessionoptions:remove("blank")
-- Default formatting
vim.o.textwidth = 80
vim.o.expandtab = false
vim.o.tabstop = 8
vim.o.shiftwidth = 8
vim.o.softtabstop = 8
-- This pattern matches:
-- 1. Optional leading whitespace
-- 2. Either digits followed by . ) ] or }
-- 3. OR a single dash (-), asterisk (*), or plus (+)
-- 4. Followed by trailing whitespace
vim.opt.formatlistpat = [[^\s*\(\d\+[\]:.)}\t ]\|[-*+]\s\)\s*]]
vim.opt.formatoptions = "jcroqlnt"
-- Keymaps
-- Move between windows using Ctrl + h,j,k,l
map("<C-h>", "<C-w>h", "Move to left window")
map("<C-j>", "<C-w>j", "Move to lower window")
map("<C-k>", "<C-w>k", "Move to upper window")
map("<C-l>", "<C-w>l", "Move to right window")
-- Resize windows using Ctrl + Arrow keys
map("<C-Up>", "<cmd>resize +1<CR>", "Increase window height")
map("<C-Down>", "<cmd>resize -1<CR>", "Decrease window height")
map("<C-Right>", "<cmd>vertical resize +1<CR>", "Increase window width")
map("<C-Left>", "<cmd>vertical resize -1<CR>", "Decrease window width")
-- Buffers
map("[b", "<cmd>bprevious<cr>", "Previous buffer")
map("]b", "<cmd>bnext<cr>", "Next buffer")
-- Diagnostic
local diagnostic_goto = function(count, severity)
local opts = { count = count, severity = severity and vim.diagnostic.severity[severity] or nil }
return function()
vim.diagnostic.jump(opts)
end
end
map("]d", diagnostic_goto(1), "Next diagnostic")
map("[d", diagnostic_goto(-1), "Previous diagnostic")
map("]e", diagnostic_goto(1, "ERROR"), "Next error")
map("[e", diagnostic_goto(-1, "ERROR"), "Previous error")
map("]w", diagnostic_goto(1, "WARN"), "Next warning")
map("[w", diagnostic_goto(-1, "WARN"), "Previous warning")
-- Center some navigation movements
map("<C-]>", "<C-]>zz", "Jump to the definition", { "n", "v" })
map("<C-o>", "<C-o>zz", "Go to previous position in jump list")
map("<Esc>", "<cmd>nohlsearch<cr>", "Clear highlights")
-- Undo tree (built-in, Neovim 0.12+)
vim.cmd.packadd("nvim.undotree")
map("<leader>u", require("undotree").open, "Undo tree")
-- Load plugins
require("plugins")
-- Highlight on yank
vim.api.nvim_create_autocmd("TextYankPost", {
callback = function()
vim.hl.on_yank()
end,
})
-- Close help, man, and quickfix buffers with q
vim.api.nvim_create_autocmd("FileType", {
pattern = { "help", "man", "qf", "nvim-pack", "nvim-undotree" },
callback = function(e)
vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = e.buf })
end,
})
-- Auto-reload files changed outside Neovim
vim.api.nvim_create_autocmd({ "FocusGained", "BufEnter", "CursorHold", "CursorHoldI" }, {
callback = function()
if vim.fn.mode() ~= "c" and vim.fn.getcmdwintype() == "" then
vim.cmd("checktime")
end
end,
})
vim.api.nvim_create_autocmd("FileChangedShellPost", {
callback = function()
vim.notify("File changed on disk. Buffer reloaded.", vim.log.levels.WARN)
end,
})
-- Enable spell check for prose filetypes
vim.api.nvim_create_autocmd("FileType", {
pattern = { "markdown", "gitcommit", "text" },
callback = function()
vim.opt_local.spell = true
vim.opt_local.spelllang = "en_us"
vim.opt_local.indentexpr = ""
end,
})
-- Restore cursor position when reopening files
vim.api.nvim_create_autocmd("BufWinEnter", {
callback = function(e)
local exclude = { "gitcommit", "gitrebase", "help" }
if vim.tbl_contains(exclude, vim.bo[e.buf].filetype) then
return
end
local pos = vim.api.nvim_buf_get_mark(e.buf, '"')
if pos[1] > 0 and pos[1] <= vim.api.nvim_buf_line_count(e.buf) then
pcall(vim.api.nvim_win_set_cursor, 0, pos)
end
end,
})