Skip to content

Commit

Permalink
feat(vscode): better vscode support
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 24, 2023
1 parent eba510e commit 5bf45e3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 37 deletions.
2 changes: 2 additions & 0 deletions lua/lazyvim/config/init.lua
Expand Up @@ -161,6 +161,8 @@ function M.load(name)
-- HACK: LazyVim may have overwritten options of the Lazy ui, so reset this here
vim.cmd([[do VimResized]])
end
local pattern = "LazyVim" .. name:sub(1, 1):upper() .. name:sub(2)
vim.api.nvim_exec_autocmds("User", { pattern = pattern, modeline = false })
end

M.did_init = false
Expand Down
21 changes: 11 additions & 10 deletions lua/lazyvim/config/keymaps.lua
@@ -1,4 +1,5 @@
-- This file is automatically loaded by lazyvim.config.init
vim.notify("load")

local Util = require("lazyvim.util")

Expand All @@ -18,10 +19,10 @@ map("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
map("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })

-- Move to window using the <ctrl> hjkl keys
map("n", "<C-h>", "<C-w>h", { desc = "Go to left window" })
map("n", "<C-j>", "<C-w>j", { desc = "Go to lower window" })
map("n", "<C-k>", "<C-w>k", { desc = "Go to upper window" })
map("n", "<C-l>", "<C-w>l", { desc = "Go to right window" })
map("n", "<C-h>", "<C-w>h", { desc = "Go to left window", remap = true })
map("n", "<C-j>", "<C-w>j", { desc = "Go to lower window", remap = true })
map("n", "<C-k>", "<C-w>k", { desc = "Go to upper window", remap = true })
map("n", "<C-l>", "<C-w>l", { desc = "Go to right window", remap = true })

-- Resize window using <ctrl> arrow keys
map("n", "<C-Up>", "<cmd>resize +2<cr>", { desc = "Increase window height" })
Expand Down Expand Up @@ -129,12 +130,12 @@ map("n", "<leader>fT", function() Util.float_term() end, { desc = "Terminal (cwd
map("t", "<esc><esc>", "<c-\\><c-n>", { desc = "Enter Normal Mode" })

-- windows
map("n", "<leader>ww", "<C-W>p", { desc = "Other window" })
map("n", "<leader>wd", "<C-W>c", { desc = "Delete window" })
map("n", "<leader>w-", "<C-W>s", { desc = "Split window below" })
map("n", "<leader>w|", "<C-W>v", { desc = "Split window right" })
map("n", "<leader>-", "<C-W>s", { desc = "Split window below" })
map("n", "<leader>|", "<C-W>v", { desc = "Split window right" })
map("n", "<leader>ww", "<C-W>p", { desc = "Other window", remap = true })
map("n", "<leader>wd", "<C-W>c", { desc = "Delete window", remap = true })
map("n", "<leader>w-", "<C-W>s", { desc = "Split window below", remap = true })
map("n", "<leader>w|", "<C-W>v", { desc = "Split window right", remap = true })
map("n", "<leader>-", "<C-W>s", { desc = "Split window below", remap = true })
map("n", "<leader>|", "<C-W>v", { desc = "Split window right", remap = true })

-- tabs
map("n", "<leader><tab>l", "<cmd>tablast<cr>", { desc = "Last Tab" })
Expand Down
57 changes: 30 additions & 27 deletions lua/lazyvim/plugins/extras/vscode.lua
Expand Up @@ -14,49 +14,52 @@ local enabled = {
"nvim-treesitter-textobjects",
"nvim-ts-context-commentstring",
"vim-repeat",
"LazyVim",
}

local Config = require("lazy.core.config")
local Plugin = require("lazy.core.plugin")
Config.options.checker.enabled = false
Config.options.change_detection.enabled = false

local update_state = Plugin.update_state
---@diagnostic disable-next-line: duplicate-set-field
Plugin.update_state = function()
-- Config.spec.disabled = {}
for name, plugin in pairs(Config.plugins) do
-- HACK: disable all plugins except the ones we want
local fix_disabled = Plugin.Spec.fix_disabled
function Plugin.Spec.fix_disabled(self)
for _, plugin in pairs(self.plugins) do
if not (vim.tbl_contains(enabled, plugin.name) or plugin.vscode) then
Config.plugins[name] = nil
end
end
for _, plugin in pairs(Config.plugins) do
if plugin.dependencies then
plugin.dependencies = vim.tbl_filter(function(dep)
return Config.plugins[dep]
end, plugin.dependencies)
plugin.enabled = false
end
end
fix_disabled(self)
end

-- HACK: don't clean plugins in vscode
local update_state = Plugin.update_state
function Plugin.update_state()
update_state()
Config.to_clean = {}
end

local map = vim.keymap.set

map("n", "<leader><space>", "<cmd>Find<cr>")
map("n", "<leader>/", [[<cmd>call VSCodeNotify('workbench.action.findInFiles')<cr>]])
map("n", "<leader>ss", [[<cmd>call VSCodeNotify('workbench.action.gotoSymbol')<cr>]])

map("n", "<C-h>", "<C-w>h", { desc = "Go to left window", remap = true })
map("n", "<C-j>", "<C-w>j", { desc = "Go to lower window", remap = true })
map("n", "<C-k>", "<C-w>k", { desc = "Go to upper window", remap = true })
map("n", "<C-l>", "<C-w>l", { desc = "Go to right window", remap = true })

map("n", "<leader>wd", "<C-W>c", { desc = "Delete window", remap = true })
map("n", "<leader>-", "<C-W>s", { desc = "Split window below", remap = true })
map("n", "<leader>|", "<C-W>v", { desc = "Split window right", remap = true })
-- Add some vscode specific keymaps
vim.api.nvim_create_autocmd("User", {
pattern = "LazyVimKeymaps",
callback = function()
vim.keymap.set("n", "<leader><space>", "<cmd>Find<cr>")
vim.keymap.set("n", "<leader>/", [[<cmd>call VSCodeNotify('workbench.action.findInFiles')<cr>]])
vim.keymap.set("n", "<leader>ss", [[<cmd>call VSCodeNotify('workbench.action.gotoSymbol')<cr>]])
end,
})

return {
{
"LazyVim/LazyVim",
config = function(_, opts)
opts = opts or {}
-- disable the colorscheme
opts.colorscheme = function() end
require("lazyvim").setup(opts)
end,
},
{
"nvim-treesitter/nvim-treesitter",
opts = { highlight = { enable = false } },
Expand Down

0 comments on commit 5bf45e3

Please sign in to comment.