-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
243 lines (204 loc) · 9.38 KB
/
Copy pathinit.lua
File metadata and controls
243 lines (204 loc) · 9.38 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
-- =============================================================================
-- Neovim Setup Overview
-- (Prolog) define list of plugins and list of lsps, setup default hooks
-- (Project) run .nvim.lua as a function; append to plugin list and lsp list, configure options, setup project hooks
-- (Epilog) install plugins via vim.pack, run their config hooks, configure lsps
-- =============================================================================
DEBUG = false
function vim.debug(msg)
if DEBUG then vim.print(msg) end
end
-- =============================================================================
-- (Prolog::Plugin) define list of plugins
-- =============================================================================
-- variable for collecting plugin
local spec = {}
local function plugin(plugin_)
table.insert(spec, plugin_)
end
-- =============================================================================
-- (Prolog::LSP) define list of lsps, setup default hooks
-- =============================================================================
-- variable for collecting lsp
local lsps = {}
local function lsp(name_, spec_)
lsps[name_] = spec_
end
-- severity_sort places the most severe diagnostic's virtual text first on each
-- line, so the dominant (red) message reads at the top.
vim.diagnostic.config({
underline = true, -- squiggly underline under the offending text
virtual_text = true, -- inline message to the right of the line
signs = false, -- no gutter markers in the sign column
severity_sort = true, -- most severe diagnostic's text renders first per line
})
-- By default do not use semantic colors
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
if not client then return end
vim.debug("highlight(semantics): lsp semantics syntax off")
client.server_capabilities.semanticTokensProvider = nil
end,
})
-- Hotkeys: setup default hot keys
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(_args)
vim.keymap.set("n", "K", vim.lsp.buf.hover, { desc = "Hover" })
vim.keymap.set("n", "<F12>", vim.lsp.buf.definition, { desc = "Goto definition" })
vim.keymap.set("n", "<F2>", vim.lsp.buf.rename, { desc = "Rename" })
vim.keymap.set("n", "<F8>", function() vim.diagnostic.setqflist({ open = true }) end,
{ desc = "Populate quickfix with all diagnostics and open" })
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, { desc = "LSP Code Actions" })
vim.keymap.set("n", "<leader>cf", function() vim.lsp.buf.format() end, { desc = "Format code" })
end,
})
-- =============================================================================
-- (Prolog::Statusline) remove most editor widgets
-- =============================================================================
vim.opt.cmdheight = 0
vim.opt.laststatus = 3
vim.opt.showmode = false
vim.opt.showcmd = false
vim.opt.ruler = false
vim.opt.showtabline = 0 -- no tab bar; tabs are shown as dots in the statusline
local _modes = { n = "N", i = "I", v = "V", V = "VL", ["\22"] = "VB", R = "R", c = "C", t = "T", s = "S" }
_G.statusline_mode = function() return _modes[vim.fn.mode()] or vim.fn.mode() end
-- One dot per tabpage, current filled; shown only when more than one tab exists.
_G.statusline_tabs = function()
local n = vim.fn.tabpagenr("$")
if n < 2 then return "" end
local cur = vim.fn.tabpagenr()
local dots = {}
for i = 1, n do dots[i] = (i == cur) and "●" or "○" end
return table.concat(dots) .. " | "
end
vim.opt.statusline = " %{v:lua.statusline_mode()} | %f %m%r%= %y | %{v:lua.statusline_tabs()}%l:%c "
-- =============================================================================
-- (Prolog::Navi) define navigation hot keys
-- =============================================================================
-- Cursor navigation: arrow keys move by display line.
vim.keymap.set("n", "<down>", "gj")
vim.keymap.set("n", "<up>", "gk")
vim.keymap.set("i", "<Down>", "<C-o>gj", { noremap = true, silent = true })
vim.keymap.set("i", "<Up>", "<C-o>gk", { noremap = true, silent = true })
-- Window navigation: Ctrl+Arrow in any mode.
for key, dir in pairs({ Left = "h", Down = "j", Up = "k", Right = "l" }) do
vim.keymap.set({ "n", "v", "i", "t" }, "<C-" .. key .. ">", "<Cmd>wincmd " .. dir .. "<CR>",
{ desc = "Window " .. key:lower() })
end
-- =============================================================================
-- (Prolog::VimState) configure vim state persisting folders
-- =============================================================================
-- Persistent undo, swap, and backup in centralized dirs.
-- The // suffix encodes full file paths to ensure uniqueness.
local statedir = vim.fn.stdpath("state")
for _, sub in ipairs({ "undo", "swap", "backup" }) do
vim.fn.mkdir(statedir .. "/" .. sub, "p")
end
vim.opt.undofile = true
vim.opt.undodir = statedir .. "/undo//"
vim.opt.directory = statedir .. "/swap//"
vim.opt.backupdir = statedir .. "/backup//"
-- =============================================================================
-- (Prolog::Default) define hot keys and indentation
-- =============================================================================
-- Default indent (soft default; ftplugins/.editorconfig may override).
vim.opt.expandtab = true
vim.opt.shiftwidth = 4
vim.opt.softtabstop = 4
vim.opt.autoindent = false
-- Leader Key
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
-- =============================================================================
-- (Prolog::Yazi) Setup file navigation using yazi
-- =============================================================================
vim.keymap.set({ "n", "v" }, "<leader>ya",
function() require("yazi").open() end,
{ desc = "Open yazi in current window" })
vim.keymap.set({ "n" }, "<leader>yr",
function() require("yazi").rg(function(path) if path then vim.cmd("edit " .. vim.fn.fnameescape(path)) end end) end,
{ desc = "Open yazi for search" })
require("yazi").setup()
-- =============================================================================
-- (Prolog::Narrow) toggle a centered reading column on wide screens
-- =============================================================================
vim.keymap.set("n", "<leader>z", function() require("narrow").toggle() end,
{ desc = "Toggle narrow reading mode" })
require("narrow").setup()
-- =============================================================================
-- (Prolog::Syntax) Treesitter for all projects
-- =============================================================================
vim.opt.guicursor = "n-v-c:block-Cursor/lCursor,i-ci:ver25-Cursor,r-cr:hor20-Cursor"
vim.cmd("colorscheme brutal")
-- Tree sitter installation
plugin {
"romus204/tree-sitter-manager.nvim",
dependencies = {}, -- tree-sitter CLI must be installed system-wide
config = function()
require("tree-sitter-manager").setup({
languages = {
cuda = {
install_info = {
url = "https://github.com/Y-jiji/tree-sitter-cuda",
revision = "64f84c00a604a50faa98b8487e311a65d3891b92",
},
},
},
})
end,
}
-- Start treesitter
vim.api.nvim_create_autocmd("FileType", {
callback = function(args)
local lang = vim.treesitter.language.get_lang(vim.bo[args.buf].filetype)
vim.debug(("highlight(syntax): treesitter syntax on (lang: %s)"):format(lang))
local status, _ = pcall(vim.treesitter.start, args.buf, lang)
if not status then
vim.debug(("No treesitter for %s"):format(lang))
end
end
})
-- =============================================================================
-- (Project) load per-project .nvim.lua; run it as function
-- =============================================================================
local nvimlua, err = loadfile(vim.fn.getcwd() .. "/.nvim.lua")
if nvimlua then
local ok, err = pcall(nvimlua, plugin, lsp)
if not ok then
vim.debug(("project(execute): %s"):format(err))
end
else
vim.debug(("project(load): %s"):format(err))
end
-- =============================================================================
-- (Epilog) install plugins via vim.pack + configure lsps
-- =============================================================================
-- "owner/repo" expands over SSH; a URL or local path is used verbatim.
local function gitof(p)
local s = p.dir or p.src or p[1]
if s and not (s:match("://") or s:match("^git@") or s:match("^/")) then
s = "git@github.com:" .. s
end
return s
end
-- Collect specs, dependencies first, de-duplicated by source.
local order, seen = {}, {}
local function collect(p)
if type(p) == "string" then p = { p } end
for _, d in ipairs(p.dependencies or {}) do collect(d) end
local s = gitof(p)
if not seen[s] then seen[s] = true; order[#order + 1] = p end
end
for _, p in ipairs(spec) do collect(p) end
vim.pack.add(vim.tbl_map(function(p)
return { src = gitof(p), version = p.commit or p.tag or p.branch or p.version }
end, order))
for _, p in ipairs(order) do if p.config then p.config() end end
for name, spec in pairs(lsps) do
vim.lsp.config(name, spec)
vim.lsp.enable(name)
end