-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit.lua
199 lines (172 loc) · 6.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
require("config.lazy")
-- must have options
vim.o.hlsearch = true
vim.o.incsearch = true
vim.o.clipboard = "unnamed"
vim.o.smartindent = true
vim.o.autoindent = true
vim.o.number = true
vim.o.scrolloff = 8
vim.o.guifont = "Input Mono 13"
vim.o.swapfile = false
vim.o.cursorline = true
vim.o.termguicolors = true
vim.o.signcolumn = "yes"
vim.o.showmode = false
vim.o.undofile = true
-- vim.lsp.set_log_level("off")
-- cursor
vim.o.guicursor = "n-v-c-sm:block,i-ci-ve:block,r-cr-o:hor20"
-- indent
-- Default to 4 spaces per tab
vim.o.tabstop = 4
vim.o.shiftwidth = 4
vim.o.expandtab = true
-- Use 2 spaces per tab for HTML, CSS, and JavaScript
vim.api.nvim_create_autocmd("FileType", {
pattern = { "html", "css", "javascript", "javascriptreact", "typescript", "typescriptreact" },
command = "setlocal tabstop=2 shiftwidth=2",
})
-- windows
vim.o.splitbelow = true
vim.o.splitright = true
-- misc
vim.keymap.set("i", "<C-c>", "<ESC>", { noremap = true, silent = true })
vim.keymap.set("n", ";r", "<C-^>", { noremap = true, silent = true })
vim.keymap.set("n", "_", ":e!<CR>", { noremap = true, silent = true })
function toggleQF()
local isOpen = false
for _, win in pairs(vim.fn.getwininfo()) do
if win["quickfix"] == 1 then
isOpen = true
end
end
if isOpen then
vim.cmd("cclose")
else
vim.cmd("copen")
end
end
vim.keymap.set("n", "<leader>wq", toggleQF, { noremap = true, silent = true })
vim.keymap.set("n", "gn", ":%s/")
vim.keymap.set("n", "<leasder>j", "", { noremap = true })
-- non overwrite registers
vim.keymap.set("v", "<leader>p", '"_dP', { noremap = true, silent = true })
vim.keymap.set("n", "<leader>c", '"_c', { noremap = true, silent = true })
vim.keymap.set("v", "<leader>c", '"_c', { noremap = true, silent = true })
vim.keymap.set("n", "<leader>d", '"_d', { noremap = true, silent = true })
vim.keymap.set("v", "<leader>d", '"_d', { noremap = true, silent = true })
--insert editing bindings
vim.keymap.set("i", "<C-f>", "<Right>", { noremap = true, silent = true })
vim.keymap.set("i", "<C-b>", "<Left>", { noremap = true, silent = true })
vim.keymap.set("i", "<C-n>", "<Down>", { noremap = true, silent = true })
vim.keymap.set("i", "<C-p>", "<Up>", { noremap = true, silent = true })
vim.keymap.set("i", "<C-a>", "<Home>", { noremap = true, silent = true })
vim.keymap.set("i", "<C-e>", "<End>", { noremap = true, silent = true })
vim.keymap.set("i", "<A-BS>", "<C-w>", { noremap = true, silent = true })
-- for mac system
vim.keymap.set("i", "<A-Right>", "<S-Right>", { noremap = true, silent = true })
vim.keymap.set("i", "<A-Left>", "<S-Left>", { noremap = true, silent = true })
-- for tmux system
vim.keymap.set("i", "<M-f>", "<S-Right>", { noremap = true, silent = true })
vim.keymap.set("i", "<M-b>", "<S-Left>", { noremap = true, silent = true })
-- vertical movement
vim.keymap.set("n", "K", "5k", { noremap = true, silent = true })
vim.keymap.set("n", "J", "5j", { noremap = true, silent = true })
vim.keymap.set("v", "K", "5k", { noremap = true, silent = true })
vim.keymap.set("v", "J", "5j", { noremap = true, silent = true })
-- vim.keymap.set("n", "<C-e>", "10<C-e>", { noremap = true })
-- vim.keymap.set("v", "<C-e>", "10<C-e>", { noremap = true })
-- vim.keymap.set("n", "<C-y>", "10<C-y>", { noremap = true })
-- vim.keymap.set("v", "<C-y>", "10<C-y>", { noremap = true })
-- indent
vim.keymap.set("v", ">", ">gv", { noremap = true, silent = true })
vim.keymap.set("v", "<", "<gv", { noremap = true, silent = true })
-- quick fix better defaults
vim.api.nvim_create_autocmd("FileType", {
pattern = "qf",
callback = function()
vim.api.nvim_buf_set_keymap(0, "n", "j", "j<CR><C-w>j", { noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(0, "n", "k", "k<CR><C-w>j", { noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(0, "n", "J", "5j<CR><C-w>j", { noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(0, "n", "K", "5k<CR><C-w>j", { noremap = true, silent = true })
end,
})
--color
vim.cmd.colorscheme("tokyonight")
-- if exists fg, then preserve it when changing
local function setBG(group, bg_color)
local current_hl = vim.api.nvim_get_hl_by_name(group, true)
local fg_color = current_hl.foreground or "NONE"
vim.api.nvim_set_hl(0, group, { fg = fg_color, bg = bg_color })
end
local function themeChanges()
-- set highlight orange
local theme
if vim.opt.background:get() == "light" then
vim.api.nvim_set_hl(0, "@lsp.typemod.variable.defaultLibrary", { fg = "#FF00FF" })
vim.api.nvim_set_hl(0, "Identifier", { fg = "#495057" })
vim.api.nvim_set_hl(0, "Visual", { bg = "#D0E0E3", blend = 50 })
vim.api.nvim_set_hl(0, "VisualNOS", { bg = "#D0E0E3", blend = 50 })
vim.api.nvim_set_hl(0, "Normal", { bg = "#F7F7F7", fg = "#495057" })
vim.api.nvim_set_hl(0, "MatchParen", { fg = "#FFD700", bg = "#D0E0E3" })
setBG("SignColumn", "#F7F7F7")
setBG("LineNr", "#F7F7F7")
setBG("CursorLine", "#F0F0F0")
setBG("TelescopeSelection", "#EDEDED")
theme = "iceberg_light"
else
vim.api.nvim_set_hl(0, "@lsp.typemod.variable.defaultLibrary", { fg = "#FF66CC" })
vim.api.nvim_set_hl(0, "Identifier", { fg = "#FFFFFF" })
vim.api.nvim_set_hl(0, "Visual", { bg = "#335E5E", blend = 80 })
vim.api.nvim_set_hl(0, "VisualNOS", { bg = "#335E5E", blend = 80 })
vim.api.nvim_set_hl(0, "Normal", { bg = "#27292C", fg = "#FFFFFF" })
vim.api.nvim_set_hl(0, "MatchParen", { fg = "#FFD700", bg = "#335E5E" })
setBG("SignColumn", "#27292C")
setBG("LineNr", "#27292C")
setBG("CursorLine", "#2f323b")
setBG("TelescopeSelection", "#3a3d45")
theme = "iceberg_dark"
end
vim.api.nvim_set_hl(0, "NormalFloat", { link = "Normal" })
vim.api.nvim_set_hl(0, "@parameter", { link = "Identifier" })
vim.api.nvim_set_hl(0, "@variable", { link = "Identifier" })
vim.api.nvim_set_hl(0, "@variable.parameter", { link = "Identifier" })
vim.api.nvim_set_hl(0, "@function.call", { link = "Function" })
vim.api.nvim_set_hl(0, "@member", { link = "Identifier" })
vim.api.nvim_set_hl(0, "@property", { link = "Identifier" })
require("lualine").setup({
options = {
theme = theme,
},
sections = {
lualine_a = { "mode" },
lualine_b = { { "filename", path = 1 } },
lualine_c = { "diagnostics" },
lualine_x = { "filetype" },
lualine_y = { "progress" },
lualine_z = { "location" },
},
})
-- set cursor to default terminal
vim.cmd("highlight Cursor guifg=NONE guibg=NONE")
-- Remove italic from all highlight groups
for _, group in ipairs(vim.fn.getcompletion("", "highlight")) do
local highlight = vim.api.nvim_get_hl_by_name(group, true)
if highlight and highlight.italic then
highlight.italic = nil
vim.api.nvim_set_hl(0, group, highlight)
end
end
end
function toggleLightDark()
if vim.o.background == "dark" then
vim.o.background = "light"
else
vim.o.background = "dark"
end
themeChanges()
end
vim.keymap.set("n", "<leader>wr", toggleLightDark)
vim.api.nvim_create_autocmd("Colorscheme", { callback = themeChanges })
themeChanges()