-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.lua
More file actions
304 lines (258 loc) · 12.4 KB
/
Copy pathinit.lua
File metadata and controls
304 lines (258 loc) · 12.4 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
vim.cmd('source ~/.vimrc.base')
-- 允许关闭文件后 undo
vim.opt.undofile = true
vim.opt.undodir = '/tmp/nvim/undo'
-- 允许在项目文件夹添加.nvim.lua
vim.opt.exrc = true
-- Fix for position_encoding warning in Neovim v0.11+
if vim.fn.has('nvim-0.11') == 1 then
local original_make_position_params = vim.lsp.util.make_position_params
---@diagnostic disable-next-line: duplicate-set-field
vim.lsp.util.make_position_params = function(win, offset_encoding)
if not offset_encoding then
local bufnr = vim.api.nvim_win_get_buf(win or 0)
local clients = vim.lsp.get_clients({ bufnr = bufnr })
if clients and clients[1] then
offset_encoding = clients[1].offset_encoding or 'utf-16'
else
offset_encoding = 'utf-16'
end
end
return original_make_position_params(win, offset_encoding)
end
end
-- 允许 options map
vim.g.neovide_input_macos_option_key_is_meta = 'only_left'
vim.keymap.set("n", "bn", "<cmd>bnext<CR>")
vim.keymap.set("n", "bp", "<cmd>bprevious<CR>")
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
vim.keymap.set("v", "K", ":m '>-2<CR>gv=gv")
vim.keymap.set("n", "<space>", "@=((foldclosed(line('.')) < 0) ? 'zc' : 'zO')<CR>")
vim.keymap.set("n", "za", "zM")
vim.keymap.set("n", "zo", "zO")
-- Smart sentence navigation for markdown and latex files
local function smart_dollar()
local ft = vim.bo.filetype
if ft == "markdown" or ft == "tex" or ft == "latex" then
local line = vim.api.nvim_get_current_line()
local col = vim.fn.col('.')
local rest_of_line = line:sub(col + 1)
-- Search for sentence ending punctuation: . , ; ?
local next_pos = rest_of_line:find('[%.,%?;]')
if next_pos then
-- Move to the punctuation mark
vim.cmd('normal! ' .. next_pos .. 'l')
else
-- No punctuation found, go to end of line
vim.cmd('normal! $')
end
else
vim.cmd('normal! $')
end
end
local function smart_zero()
local ft = vim.bo.filetype
if ft == "markdown" or ft == "tex" or ft == "latex" then
local line = vim.api.nvim_get_current_line()
local col = vim.fn.col('.')
local before_cursor = line:sub(1, col - 1)
-- Search backwards for sentence ending punctuation: . , ; ?
local prev_pos = nil
for i = #before_cursor, 1, -1 do
local char = before_cursor:sub(i, i)
if char == '.' or char == ',' or char == ';' or char == '?' then
prev_pos = i
break
end
end
if prev_pos then
-- Move cursor to the punctuation mark
vim.api.nvim_win_set_cursor(0, {vim.fn.line('.'), prev_pos - 1})
else
-- No punctuation found, go to beginning of line
vim.cmd('normal! 0')
end
else
vim.cmd('normal! 0')
end
end
-- vim.keymap.set({"n", "v", "x"}, "0", smart_zero, { noremap = true, silent = true })
-- vim.keymap.set({"n", "v", "x"}, "$", smart_dollar, { noremap = true, silent = true })
-- 导入数学符号map
vim.cmd('source ~/.vimrc.unimap')
-- 设置字体
vim.opt.guifont = "Hack:h15"
if os.getenv("OS") == "Windows_NT" then
vim.opt.guifontwide = "YouYuan:h10.5:cGB2312"
elseif not os.getenv("HOME") == '/Users' then
vim.opt.guifontwide = "WenQuanYi Micro Hei 11"
end
vim.g.netrw_banner = 0
vim.g.netrw_liststyle = 3
vim.g.netrw_browse_split = 4
vim.g.netrw_altv = 1
vim.g.netrw_winsize = 20
vim.g.netrw_list_hide = '.*\\~$,\\~$,\\~\\~$'
vim.g.netrw_sort_sequence = '[\\/],$,*'
-- copy visual location: @File#L1-99
local function copy_visual_location()
local file = vim.api.nvim_buf_get_name(0)
local s = vim.fn.getpos("v")
local e = vim.fn.getpos(".")
local sline, eline = s[2], e[2]
-- 防反选
if eline < sline then
sline, eline = eline, sline
end
local location
if sline == eline then
location = string.format("@%s#L%d", file, sline)
else
location = string.format("@%s#L%d-%d", file, sline, eline)
end
vim.fn.setreg("+", location)
vim.notify("Copied: " .. location)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", false)
end
vim.keymap.set("x", "<leader>g", copy_visual_location, { noremap = true, silent = true })
local function load_lazy()
-- lazyvim 插件
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--depth=1",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
local head_file = lazypath .. "/.git/HEAD"
if vim.fn.filereadable(head_file) == 1 then
local head = vim.fn.readfile(head_file, "", 1)[1] or ""
if head ~= "" and not vim.startswith(head, "ref: ") then
vim.fn.system({
"git",
"-C",
lazypath,
"checkout",
"-B",
"stable",
})
end
end
vim.opt.rtp:prepend(lazypath)
end
local is_ssh = os.getenv("SSH_CONNECTION") or os.getenv("SSH_CLIENT")
if is_ssh then
vim.opt.cursorline = false
vim.o.mouse = ""
elseif vim.g.vscode then
if vim.g.vscode_clipboard then
vim.g.clipboard = vim.g.vscode_clipboard
end
load_lazy()
require("lazy").setup("vsplugins")
-- Ensure lazy.nvim is on the runtimepath when running embedded in VSCode
-- so subsequent calls to `require('lazy')` succeed.
local vscode = require('vscode')
-- using 'open default keyboard shortcuts' to see the command list
vim.keymap.set({ "n" }, "mm", function () vscode.action("bookmarks.toggle") end , { noremap = true })
vim.keymap.set({ "n" }, "mp", function () vscode.action("bookmarks.jumpToPrevious") end, { noremap = true })
vim.keymap.set({ "n" }, "mn", function () vscode.action("bookmarks.jumpToNext") end, { noremap = true })
vim.keymap.set({ "n"}, "<F9>", function () vscode.action("workbench.action.tasks.runTask") end )
vim.keymap.set({ "n"}, "<F10>", function () vscode.action("workbench.action.debug.start") end)
vim.keymap.set({ "n" }, "bn", "<Cmd>Tabnext<CR>", { noremap = true })
vim.keymap.set({ "n" }, "bp", "<Cmd>Tabprevious<CR>", { noremap = true })
vim.keymap.set({ "n" }, "<leader>fe", function () vscode.action("workbench.action.findInFiles") end, { noremap = true })
vim.keymap.set({ "n" }, "fe", function() vscode.action("workbench.action.findInFiles") end, { noremap = true })
vim.keymap.set({'n'}, '<leader>c', function() vscode.action("keybindings.editor.clearSearchResults") end, { noremap = true })
vim.keymap.set({ "n" }, "<leader>ff", function ()
vscode.action("keybindings.editor.clearSearchResults")
vscode.action("workbench.action.showAllSymbols")
end, { noremap = true })
vim.keymap.set({ "n" }, "fe", function() vscode.action("workbench.action.findInFiles") end, { noremap = true })
vim.keymap.set({ "n" }, "<leader>fr", function () vscode.action("workbench.action.openRecent") end, { noremap = true })
vim.keymap.set({ "n" }, "fr", function() vscode.action("workbench.action.openRecent") end, { noremap = true })
vim.keymap.set({ "n" }, "<space>", function() vscode.action("editor.toggleFold") end, { noremap = true })
vim.keymap.set({ "n" }, "zo", function() vscode.action("editor.unfold") end, { noremap = true })
vim.keymap.set({ "n" }, "zz", function() vscode.action("editor.fold") end, { noremap = true })
vim.keymap.set({ "n" }, "za", function() vscode.action("editor.foldAll") end, { noremap = true })
vim.keymap.set({'n'}, '=', function() vscode.action("editor.action.formatDocument") end, { noremap = true })
vim.keymap.set({'n','i','v'}, '<leader>ci', function() vscode.action("editor.action.commentLine") end, { noremap = true })
-- TODO 多行编辑
vim.keymap.set({ "n", "x" }, "<leader>rn", function()
vscode.with_insert(function()
vscode.action("editor.action.rename")
end)
end)
vim.keymap.set({'n'}, 'gi', function() vscode.action("editor.action.goToImplementation") end, { noremap = true })
vim.keymap.set({'n'}, 'go', function() vscode.action("workbench.action.navigateBack") end, { noremap = true })
vim.keymap.set({'n'}, 'gd', function() vscode.action("editor.action.revealDefinition") end, { noremap = true })
vim.keymap.set({'n'}, 'gp', function() vscode.action("workbench.action.navigateToLastEditLocation") end, { noremap = true })
vim.keymap.set({'n'}, 'gn', function() vscode.action("workbench.action.navigateForwardInEditLocations") end, { noremap = true })
vim.keymap.set({'n'}, 'gq', function() vscode.action("editor.action.marker.nextInFiles") end, { noremap = true })
-- vim.keymap.set({'n','x'}, '<Right>', function() vscode.action("workbench.action.navigateRight") end, { noremap = true })
-- vim.keymap.set({'n','x'}, '<Left>', function() vscode.action("workbench.action.navigateLeft") end, { noremap = true })
-- vim.keymap.set({'n','x'}, '<Up>', function() vscode.action("workbench.action.navigateUp") end, { noremap = true })
-- vim.keymap.set({'n','x'}, '<Down>', function() vscode.action("workbench.action.navigateDown") end, { noremap = true })
vim.keymap.set({'v'}, 'v', function() vscode.action("editor.action.smartSelect.expand") end, { noremap = true })
-- config in vscode might be better?
vim.keymap.set({'n'}, '<F9>', function() vscode.action("workbench.action.debug.run") end, { noremap = true })
vim.keymap.set({'n'}, '<F10>', function() vscode.action("workbench.action.debug.start") end, { noremap = true })
vim.keymap.set({'n'}, '<F2>', function() vscode.action("workbench.action.toggleSidebarVisibility") vscode.action("workbench.view.explorer") end, { noremap = true })
vim.keymap.set({'n'}, '<F3>', function() vscode.action("workbench.action.terminal.toggleTerminal") end, { noremap = true })
vim.keymap.set({'n'}, '<F4>', function() vscode.action("workbench.files.action.showActiveFileInExplorer") end, { noremap = true })
vim.keymap.set({'n'}, '<F5>', function() vscode.action("workbench.action.toggleZenMode") end, { noremap = true })
local function move_vscode_wrapped_line(direction, select)
vscode.action("cursorMove", {
args = {
to = direction,
by = "wrappedLine",
value = vim.v.count1,
select = select,
},
})
end
local function move_vscode_visual_wrapped_line(direction)
local mode = vim.api.nvim_get_mode().mode
if mode == "V" or mode == "\022" then
return direction == "down" and "j" or "k"
end
move_vscode_wrapped_line(direction, true)
return "<Ignore>"
end
local opts = { desc = "Move by display line", silent = true, noremap = true }
vim.keymap.set("n", "j", function() move_vscode_wrapped_line("down", false) end, opts)
vim.keymap.set("n", "k", function() move_vscode_wrapped_line("up", false) end, opts)
local visual_opts = { desc = "Move by display line", expr = true, silent = true, noremap = true }
vim.keymap.set({ "v", "x" }, "j", function() return move_vscode_visual_wrapped_line("down") end, visual_opts)
vim.keymap.set({ "v", "x" }, "k", function() return move_vscode_visual_wrapped_line("up") end, visual_opts)
else
--[[ normal init ]]
load_lazy()
local opts = {
install = {
-- try to load one of these colorschemes when starting an installation during startup
colorscheme = { "tokyonight-storm" },
},
}
require("lazy").setup("plugins", opts)
local opts = { desc = "Move by display line", silent = true, noremap = true }
vim.keymap.set({ "n", "v", "x" }, "j", "gj", opts)
vim.keymap.set({ "n", "v", "x" }, "k", "gk", opts)
vim.o.autoread = true
local group = vim.api.nvim_create_augroup("auto_checktime", { clear = true })
vim.api.nvim_create_autocmd({ "FocusGained", "BufEnter", "CursorHold", "CursorHoldI" }, {
group = group,
pattern = "*",
command = "checktime",
})
end
if vim.g.neovide then
vim.g.neovide_cursor_animation_length = 0
end
vim.keymap.set('c', '<D-v>', '<C-r>+', { noremap = true })
vim.keymap.set('i', '<D-v>', '<Cmd>put +<CR>', {})