Skip to content

Commit 4fe46b0

Browse files
committed
feat(vscode):migrate vscode config to lua
1 parent b95f49a commit 4fe46b0

File tree

7 files changed

+372
-312
lines changed

7 files changed

+372
-312
lines changed

vim/my.nvim/init.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
require('setup')
1+
require('setup').setup()
2+
3+
vim.keymap.set("n", "<leader>sv", function() require('setup').setup() end, {noremap = true,silent = true})

vim/my.nvim/lua/setup.lua

+23-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
22
local ____exports = {}
3-
local loadVim, ensurePluginManager, ensurePlugins, configCoc, configVim
3+
local loadVscode, loadVim, ensurePluginManager, ensurePlugins, configCoc, configVim
44
local plug = require("plug")
5+
function loadVscode()
6+
local vscode = require("vscode.init")
7+
if not vim.g.pluginDir then
8+
vim.g.pluginDir = vim.fn.stdpath("data") .. "/mynvim"
9+
end
10+
vscode.setup()
11+
end
512
function loadVim()
6-
vim.g.pluginDir = vim.fn.stdpath("data") .. "/mynvim"
7-
vim.g.cocData = tostring(vim.g.pluginDir) .. "/coc"
8-
vim.g.rootPath = vim.fn.fnamemodify(
9-
vim.fn.resolve(vim.fn.expand("<sfile>:p")),
10-
":h"
11-
)
12-
vim.g.configDefault = tostring(vim.g.rootPath) .. "/default.vim"
13+
if not vim.g.pluginDir then
14+
vim.g.pluginDir = vim.fn.stdpath("data") .. "/mynvim"
15+
vim.g.cocData = tostring(vim.g.pluginDir) .. "/coc"
16+
vim.g.rootPath = vim.fn.fnamemodify(
17+
vim.fn.resolve(vim.fn.expand("<sfile>:p")),
18+
":h"
19+
)
20+
vim.g.configDefault = tostring(vim.g.rootPath) .. "/default.vim"
21+
end
1322
vim.fn.execute(
1423
"source " .. tostring(vim.g.configDefault),
1524
"silent!"
@@ -201,12 +210,11 @@ function configVim()
201210
print(vim.g.rootPath)
202211
vim.fn["utils#source_file"](vim.g.rootPath, "keybinding.vim")
203212
end
204-
if vim.fn.exists("g:vscode") == 1 then
205-
vim.fn.execute(("source " .. vim.fn.fnamemodify(
206-
vim.fn.expand("<sfile>"),
207-
":h"
208-
)) .. "/vscode/init.vim")
209-
else
210-
loadVim()
213+
function ____exports.setup()
214+
if vim.fn.exists("g:vscode") == 1 then
215+
loadVscode()
216+
else
217+
loadVim()
218+
end
211219
end
212220
return ____exports

vim/my.nvim/lua/vscode/init.lua

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
-- vim: set foldmethod=marker fdl=0:
2+
local map = vim.keymap.set;
3+
local mapopt = { noremap = true, silent = true }
4+
local vscode = require("vscode-neovim")
5+
6+
vim.notify = vscode.notify
7+
8+
local M = {}
9+
10+
local function ensurePluginManager(dir)
11+
local lazypath = dir .. "/lazy.nvim"
12+
if not vim.loop.fs_stat(lazypath) then
13+
vim.fn.system({
14+
"git",
15+
"clone",
16+
"--filter=blob:none",
17+
"https://github.com/folke/lazy.nvim.git",
18+
"--branch=stable",
19+
lazypath
20+
})
21+
end
22+
vim.opt.runtimepath:prepend(lazypath)
23+
end
24+
25+
26+
local function ensurePlugins(dir)
27+
local lazy = require("lazy")
28+
29+
lazy.setup({
30+
'rcarriga/nvim-notify',
31+
'unblevable/quick-scope',
32+
{ [1] = 'folke/flash.nvim', branch = 'main' },
33+
'tpope/vim-surround',
34+
'ruifm/gitlinker.nvim',
35+
'nvim-lua/plenary.nvim',
36+
})
37+
end
38+
39+
40+
local function vscode_call(s)
41+
return function()
42+
vscode.call(s)
43+
end
44+
end
45+
46+
local function maximize_editor()
47+
vscode.call("workbench.action.closeSidebar")
48+
vscode.call("workbench.action.closePanel")
49+
end
50+
51+
local function loadConfig()
52+
-- {{{ flash
53+
54+
require('flash').setup(
55+
{
56+
modes = {
57+
char = {
58+
enabled = false
59+
}
60+
},
61+
highlight = {
62+
-- show a backdrop with hl FlashBackdrop
63+
backdrop = false,
64+
}
65+
66+
}
67+
)
68+
69+
map('n', 's', require('flash').jump, mapopt)
70+
71+
vim.api.nvim_set_hl(0, "FlashLabel", { ctermbg = 0, bg = '#fa036a' })
72+
vim.api.nvim_set_hl(0, "FlashMatch", { ctermbg = 0, bg = '#2f50cd' })
73+
vim.api.nvim_set_hl(0, "FlashCurrent", { ctermbg = 0, bg = '#2f50cd' })
74+
75+
-- }}}
76+
77+
-- {{{ quick scope
78+
79+
vim.cmd [[
80+
highlight QuickScopePrimary guifg='#afff5f' gui=underline ctermfg=155 cterm=underline
81+
highlight QuickScopeSecondary guifg='#5fffff' gui=underline ctermfg=81 cterm=underline
82+
]]
83+
84+
--}}}
85+
86+
-- {{{ gitlinker
87+
88+
map('n', '<leader>gl', '<cmd>lua require"gitlinker".get_buf_range_url("n")<cr>', { silent = true })
89+
map('v', '<leader>gl', '<cmd>lua require"gitlinker".get_buf_range_url("v")<cr>', {})
90+
91+
--}}}
92+
93+
--{{{ vim options
94+
95+
vim.o.ignorecase = true
96+
97+
-- 设置leader为空格
98+
vim.g.mapleader = " "
99+
100+
--}}}
101+
102+
--{{{ mapping
103+
104+
105+
map('n', '<leader>wm', maximize_editor, mapopt)
106+
--map('n', '<C-a>',function vscode.call("workbench.action.focusLastEditorGroup") end, mapopt)
107+
--map('n', '<C-p>',function() vscode.call("workbench.action.quickOpen") end, mapopt)
108+
--map('n', '<leader>ws','<C-w>s', mapopt)
109+
--map('n', '<leader>wo','<C-w>o', mapopt)
110+
--map('n', '<leader>wv','<C-w>v', mapopt)
111+
--map('n', '<leader>ws','<C-w>s', mapopt)
112+
--map('n', '<leader>ws','<C-w>s', mapopt)
113+
map('n', 'zc', vscode_call("editor.fold"), mapopt)
114+
map('n', 'zo', vscode_call("editor.unfold"), mapopt)
115+
map('n', 'zM', vscode_call("editor.foldAll"), mapopt)
116+
map('n', 'zR', vscode_call("editor.unfoldAll"), mapopt)
117+
118+
map('n', ']c', vscode_call("workbench.action.editor.nextChange"), mapopt)
119+
map('n', '[c', vscode_call("workbench.action.editor.previousChange"), mapopt)
120+
121+
map('n', 'mi', vscode_call("bookmarks.toggleLabeled"), mapopt)
122+
map('n', 'ma', vscode_call("bookmarks.listFromAllFiles"), mapopt)
123+
map('n', 'mm', vscode_call("bookmarks.toggle"), mapopt)
124+
125+
126+
map('n', '<leader><leader>', vscode_call("workbench.action.showCommands"), mapopt)
127+
128+
map('n', '<leader>;', vscode_call("editor.action.commentLine"), mapopt)
129+
map('v', '<leader>;', vscode_call("editor.action.commentLine"), mapopt)
130+
131+
map('n', '<C-P>', vscode_call("workbench.action.quickOpen"), mapopt)
132+
133+
--" file
134+
map('n', '<leader>fs', vscode_call("workbench.action.quickOpen"), mapopt)
135+
map('n', '<leader>ft', vscode_call("workbench.files.action.focusFilesExplorer"), mapopt)
136+
137+
--" tag
138+
map('n', '<leader>tb', vscode_call("outline.focus"), mapopt)
139+
140+
--" search
141+
map('n', '<leader>sw', [[<cmd>Rg <C-R><C-W>]], mapopt)
142+
map('n', '<leader>sr', vscode_call("workbench.action.findInFiles"), mapopt)
143+
map('n', '<leader>sf', vscode_call("workbench.action.quickOpen"), mapopt)
144+
145+
map('n', 'K', vscode_call("editor.action.showHover"), mapopt)
146+
147+
--}}}
148+
end
149+
150+
function M.setup()
151+
ensurePluginManager(vim.g.pluginDir)
152+
ensurePlugins(vim.g.pluginDir)
153+
loadConfig()
154+
end
155+
156+
return M
File renamed without changes.

0 commit comments

Comments
 (0)