-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
211 lines (180 loc) · 4.84 KB
/
init.lua
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
-- Load legacy vimrc config
vim.cmd.source(vim.fn.stdpath("config") .. "/vimrc")
-- Only load the rest of the config if we're not in VSCode.
if vim.g.vscode then
return
end
_G.prequire = function(modname)
local ok, mod = pcall(require, modname)
if ok then
return mod
end
end
---Pretty print. Alias for `vim.inspect()`.
_G.pp = function(a, opt) print(vim.inspect(a, opt)) end
---LibUV
_G.uv = vim.loop
_G.Config = {
fn = {},
plugin = {},
state = {},
}
Config.common = require("user.common")
---Path library.
_G.pl = Config.common.utils.pl
Config.lib = require("user.lib")
Config.term = require("user.modules.term")
-- Disabled for now since it creates issues with Sessions and Remote files in
-- windows (e.g. OneDrive files)
-- Config.buf_cleaner = require("user.modules.buf_cleaner")
-- Config.buf_cleaner.enable()
local Cache = require("user.modules.cache")
Config.state.git = {
rev_name_cache = Cache(),
}
local alias = require("user.modules.cmd_alias").alias
local api = vim.api
local lib = Config.lib
local utils = Config.common.utils
require("user")
-- Custom winbar
-- Disable for neovide. Doesn't work well with it.
if vim.fn.exists("g:neovide") == 0 then
api.nvim_create_autocmd("VimEnter", {
callback = function() require("user.modules.winbar").init() end,
})
end
-- Lastplace
require("user.modules.lastplace")
-- COMMAND ALIASES
alias("brm", "BRemove")
alias("sch", "Scratch")
alias("wins", "Windows")
alias("hh", "HelpHere")
alias("mh", "ManHere")
alias("gh", "Git ++curwin")
alias("T", "Telescope")
alias("gs", "Telescope git_status")
alias("gb", "Telescope git_branches")
alias({ "gd", "DO" }, "DiffviewOpen")
alias("gl", "DiffviewFileHistory")
alias("Q", "q")
alias({ "Qa", "QA", "QA!" }, "qa")
alias({ "WQA", "WQa", "Wqa" }, "wqa")
alias("we", "w | e")
alias("ws", "w | so %")
alias("ftd", "filetype detect")
alias("N", "Neorg")
alias("nim", "Neorg inject-metadata")
-- Toggle conceallevel:
alias("tcl", "exe 'setl conceallevel=' . (&conceallevel == 0 ? 2 : 0)")
alias("do", "diffget")
alias("dp", "diffput")
-- FUNCTIONS
Config.fn.toggle_quickfix = lib.create_view_toggler({
find = function()
return utils.list_bufs({
options = { buftype = "quickfix" },
no_hidden = true,
tabpage = 0,
})[1]
end,
open = function()
if #vim.fn.getloclist(0) > 0 then
vim.cmd("belowright lope")
else
vim.cmd("belowright cope | wincmd J")
end
end,
close = function()
if vim.fn.win_gettype() == "quickfix" then
vim.cmd("ccl")
else
vim.cmd("lcl")
end
end,
focus = true,
remember_height = true,
})
Config.fn.toggle_outline = lib.create_view_toggler({
find = function() return utils.list_bufs({ pattern = "OUTLINE" })[1] end,
open = function()
vim.api.nvim_create_autocmd("BufWinEnter", {
callback = function()
vim.schedule(function() vim.cmd("wincmd =") end)
return true
end,
})
vim.cmd("Outline")
end,
close = function()
vim.cmd("OutlineClose")
vim.cmd("wincmd =")
end,
focus = true,
})
Config.fn.toggle_diagnostics = lib.create_view_toggler({
find = function()
return utils.list_bufs({
options = { filetype = "trouble" },
no_hidden = true,
tabpage = 0,
})[1]
end,
open = function() vim.cmd("Trouble diagnostics") end,
close = function()
local winid = vim.api.nvim_get_current_win()
vim.cmd("wincmd p")
vim.api.nvim_win_close(winid, false)
end,
focus = true,
remember_height = true,
})
---@return string[]
local function get_messages()
local ret = api.nvim_exec2("messages", { output = true })
-- Filter out empty lines.
return vim.tbl_filter(function(v) return v ~= "" end, vim.split(ret.output, "\n"))
end
local function open_messages_win()
vim.cmd("belowright sp")
vim.cmd("wincmd J")
local bufnr = utils.list_bufs({ vars = { bufid = "messages_window" } })[1]
if not bufnr then
bufnr = api.nvim_create_buf(false, false)
api.nvim_buf_set_name(bufnr, "Messages")
api.nvim_buf_set_var(bufnr, "bufid", "messages_window")
end
local lines = get_messages()
api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
api.nvim_set_current_buf(bufnr)
api.nvim_win_set_height(0, math.min(math.max(#lines, 3), 14))
utils.set_local(0, {
list = false,
winfixheight = true,
buftype = "nofile",
bufhidden = "delete",
filetype = "log",
signcolumn = "no",
colorcolumn = {},
})
vim.cmd("norm! G")
end
function Config.fn.update_messages_win()
local bufnr = utils.list_bufs({
vars = { bufid = "messages_window" },
no_hidden = true,
tabpage = 0,
})[1]
if bufnr then
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, get_messages())
local winids = utils.win_find_buf(bufnr, 0)
if #winids > 0 then
api.nvim_set_current_win(winids[1])
vim.cmd("norm! G")
end
else
open_messages_win()
end
end
return Config