-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
137 lines (117 loc) · 4.37 KB
/
Copy pathinit.lua
File metadata and controls
137 lines (117 loc) · 4.37 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
vim.g.mapleader = ","
vim.g.maplocalleader = "\\"
-- tolerate some typos on file related commands
local abbreviations = {
e = { "E" },
w = { "W" },
qa = { "q", "Q", "QA" },
wq = { "Wq", "WQ", "qw", "QW" },
wa = { "WA" },
}
for target, sources in pairs(abbreviations) do
for _, source in ipairs(sources) do
vim.cmd.cnoreabbrev(source, target)
vim.cmd.cnoreabbrev(source .. "!", target .. "!")
end
end
vim.opt.clipboard = "unnamedplus" -- use standard clipboard
vim.opt.diffopt:append("iwhite") -- ignore whitespace in vimdiff
-- spelllang from $LANG (e.g. pt_BR.UTF-8 -> "pt_br")
vim.opt.spelllang = (vim.env.LANG or ""):lower():match("^%l%l_%l%l") or "pt_br"
vim.api.nvim_create_autocmd("FileType", {
pattern = { "gitcommit", "jjdescription" },
callback = function() vim.wo.spell = true end,
})
-- Searching
vim.opt.ignorecase = true
vim.opt.smartcase = true
-- tabstops
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
-- use this otherwise markdown will have these set to 4
vim.g.markdown_recommended_style = false
vim.keymap.set("n", "<leader><space>", vim.cmd.nohl, { desc = "Clear highlights" })
vim.keymap.set("n", "<Tab>", vim.cmd.bnext, { desc = "Next buffer" })
vim.keymap.set("n", "<S-Tab>", vim.cmd.bprevious, { desc = "Previous buffer" })
vim.keymap.set("n", "<leader>c", vim.cmd.bdelete, { desc = "Close buffer" })
vim.keymap.set("n", "<f12>", vim.cmd.restart, { desc = "Restart Neovim" })
-- maintain Visual Mode after shifting > and <
vim.keymap.set("v", "<", "<gv")
vim.keymap.set("v", ">", ">gv")
-- configure extra file types
vim.filetype.add({
pattern = {
["ipython_log%.py.*"] = "python", -- ipython log
[".envrc"] = "zsh", -- direnv config
[".*ghostty/config"] = "toml",
[".*/templates/.*%.html"] = "htmldjango", -- django-plus.vim is not detecting some templates
},
extension = {
zcml = "xml", -- plone zcml
dconf = "dosini",
},
})
-- gf with file:line support (e.g. `# vendor/htmx/test/hx-get.js:11`)
vim.keymap.set("n", "gf", function()
local line = vim.api.nvim_get_current_line()
local col = vim.api.nvim_win_get_cursor(0)[2] + 1 -- 1-indexed
local pattern = "([%w%./%-_]+):(%d+)"
local pos = 1
while true do
local s, e, file, lnum = line:find(pattern, pos)
if not s then break end
if col >= s and col <= e then
vim.cmd("edit " .. vim.fn.fnameescape(file))
vim.api.nvim_win_set_cursor(0, { tonumber(lnum), 0 })
return
end
pos = e + 1
end
vim.cmd("normal! gf")
end, { desc = "Go to file (supports file:line syntax)" })
-- add project subdirectories to path to find files (with `gf`, for example)
vim.opt.path:append(vim.uv.cwd() .. "/**")
-- but ignore the directory `zzz`
-- TODO: ignore everything that is git ignored
vim.opt.wildignore:append({ "**/zzz/**", ".git" })
vim.opt.wrap = true -- enable line wrap by default
vim.opt.splitright = true -- open splits at the right
vim.opt.swapfile = false -- disable annoying warnings about swap files
vim.opt.autoread = true -- automatically reload files changed on disk
-- Close quickfix list automatically when selecting an item
vim.api.nvim_create_autocmd("FileType", {
pattern = "qf",
callback = function()
vim.keymap.set("n", "<CR>", "<CR>:cclose<CR>", { buffer = true, silent = true })
end,
})
-- Jump to first conflict marker when opening conflicted files (jj/git)
local function goto_conflict_and_mute(buf)
if vim.fn.search("^<<<<<<< ", "nw") == 0 then return end
vim.fn.search("^<<<<<<< ", "w")
vim.cmd.normal({ "zz", bang = true })
for _, c in ipairs(vim.lsp.get_clients({ bufnr = buf })) do
vim.lsp.buf_detach_client(buf, c.id)
end
vim.diagnostic.enable(false, { bufnr = buf })
vim.schedule(function()
local ok, ac = pcall(require, "tiny-inline-diagnostic.autocmds")
if not ok or not ac.is_attached(buf) then return end
local ex = require("tiny-inline-diagnostic.extmarks")
ac.detach(buf, function(b) ex.clear(b) end)
end)
end
vim.api.nvim_create_autocmd("BufReadPost", {
callback = function(args) goto_conflict_and_mute(args.buf) end,
})
-- for kitty scrollback
-- https://www.reddit.com/r/neovim/comments/1nmqjal/comment/nfiif2z/
-- see https://neovim.io/doc/user/api.html#terminal-scrollback-pager
vim.api.nvim_create_user_command(
"TermHl",
function() vim.api.nvim_open_term(0, {}) end,
{ desc = "Highlights ANSI termcodes in curbuf" }
)
require("vim._core.ui2").enable()
require("utils")