-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
170 lines (144 loc) · 5.8 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
-- change delete keymap
vim.api.nvim_set_keymap("n", "d", '"_d', { noremap = true, silent = true })
vim.api.nvim_set_keymap("v", "d", '"_d', { noremap = true, silent = true })
local global = require("config.global")
local settings = require("config.settings")
local scheme = require("config.scheme")
-- Create cache dir and data dirs
local createdir = function()
local data_dir = {
global.cache_dir .. "backup",
global.cache_dir .. "session",
global.cache_dir .. "swap",
global.cache_dir .. "tags",
global.cache_dir .. "undo",
}
-- Only check whether cache_dir exists, this would be enough.
if vim.fn.isdirectory(global.cache_dir) == 0 then
os.execute("mkdir -p " .. global.cache_dir)
for _, v in pairs(data_dir) do
if vim.fn.isdirectory(v) == 0 then
os.execute("mkdir -p " .. v)
end
end
end
end
local disable_distribution_plugins = function()
-- Disable menu loading
vim.g.did_install_default_menus = 1
vim.g.did_install_syntax_menu = 1
-- Comment this if you define your own filetypes in `after/ftplugin`
-- vim.g.did_load_filetypes = 1
-- Do not load native syntax completion
vim.g.loaded_syntax_completion = 1
-- Do not load spell files
vim.g.loaded_spellfile_plugin = 1
-- Whether to load netrw by default
-- vim.g.loaded_netrw = 1
-- vim.g.loaded_netrwFileHandlers = 1
-- vim.g.loaded_netrwPlugin = 1
-- vim.g.loaded_netrwSettings = 1
-- newtrw liststyle: https://medium.com/usevim/the-netrw-style-options-3ebe91d42456
vim.g.netrw_liststyle = 3
-- Do not load tohtml.vim
vim.g.loaded_2html_plugin = 1
-- Do not load zipPlugin.vim, gzip.vim and tarPlugin.vim (all of these plugins are
-- related to reading files inside compressed containers)
vim.g.loaded_gzip = 1
vim.g.loaded_tar = 1
vim.g.loaded_tarPlugin = 1
vim.g.loaded_vimball = 1
vim.g.loaded_vimballPlugin = 1
vim.g.loaded_zip = 1
vim.g.loaded_zipPlugin = 1
-- Do not use builtin matchit.vim and matchparen.vim because we're using vim-matchup
vim.g.loaded_matchit = 1
vim.g.loaded_matchparen = 1
-- Disable sql omni completion
vim.g.loaded_sql_completion = 1
-- Set this to 0 in order to disable native EditorConfig support
vim.g.editorconfig = 1
-- Disable remote plugins
-- NOTE:
-- > Disabling rplugin.vim will make `wilder.nvim` complain about missing rplugins during :checkhealth,
-- > but since it's config doesn't require python rtp (strictly), it's fine to ignore that for now.
-- vim.g.loaded_remote_plugins = 1
end
local leader_map = function()
vim.g.mapleader = " "
-- NOTE:
-- > Uncomment the following if you're using a <leader> other than <Space>, and you wish
-- > to disable advancing one character by pressing <Space> in normal/visual mode.
-- vim.api.nvim_set_keymap("n", " ", "", { noremap = true })
-- vim.api.nvim_set_keymap("x", " ", "", { noremap = true })
end
local gui_config = function()
vim.api.nvim_set_option_value("guifont", settings.gui_config.font_name .. ":h" .. settings.gui_config.font_size, {})
end
local clipboard_config = function()
if global.is_mac then
vim.g.clipboard = {
name = "macOS-clipboard",
copy = { ["+"] = "pbcopy", ["*"] = "pbcopy" },
paste = { ["+"] = "pbpaste", ["*"] = "pbpaste" },
cache_enabled = 0,
}
elseif global.is_wsl then
vim.g.clipboard = {
name = "win32yank-wsl",
copy = {
["+"] = "win32yank.exe -i --crlf",
["*"] = "win32yank.exe -i --crlf",
},
paste = {
["+"] = "win32yank.exe -o --lf",
["*"] = "win32yank.exe -o --lf",
},
cache_enabled = 0,
}
end
end
local shell_config = function()
if global.is_windows then
if not (vim.fn.executable("pwsh") == 1 or vim.fn.executable("powershell") == 1) then
vim.notify(
[[
Failed to setup terminal config
PowerShell is either not installed, missing from PATH, or not executable;
cmd.exe will be used instead for `:!` (shell bang) and toggleterm.nvim.
You're recommended to install PowerShell for better experience.]],
vim.log.levels.WARN,
{ title = "[core] Runtime Warning" }
)
return
end
local basecmd = "-NoLogo -MTA -ExecutionPolicy RemoteSigned"
local ctrlcmd = "-Command [console]::InputEncoding = [console]::OutputEncoding = [System.Text.Encoding]::UTF8"
vim.api.nvim_set_option_value("shell", vim.fn.executable("pwsh") == 1 and "pwsh" or "powershell", {})
vim.api.nvim_set_option_value("shellcmdflag", string.format("%s %s;", basecmd, ctrlcmd), {})
vim.api.nvim_set_option_value("shellredir", "-RedirectStandardOutput %s -NoNewWindow -Wait", {})
vim.api.nvim_set_option_value("shellpipe", "2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode", {})
vim.api.nvim_set_option_value("shellquote", nil, {})
vim.api.nvim_set_option_value("shellxquote", nil, {})
end
end
local load_core = function()
createdir()
disable_distribution_plugins()
leader_map()
gui_config()
clipboard_config()
shell_config()
require("config.options")
require("config.events")
require("lazy_setup")
require("keymap")
-- change delete keymap
vim.api.nvim_set_keymap("n", "d", '"_d', { noremap = true, silent = true })
vim.api.nvim_set_keymap("v", "d", '"_d', { noremap = true, silent = true })
local colorscheme = scheme.colorscheme
local background = scheme.background
vim.api.nvim_command("set background=" .. background)
vim.api.nvim_command("colorscheme " .. colorscheme)
end
load_core()