add vscode support #11

Merged
softinio merged 1 commit from add-vscode-support into main 2024-08-07 08:20:39 -07:00
2 changed files with 138 additions and 92 deletions
Showing only changes of commit 79193d44f7 - Show all commits

119
init.lua
View file

@ -1,5 +1,9 @@
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if vim.g.vscode then
if not vim.loop.fs_stat(lazypath) then -- VSCode Neovim
require("user.vscode_keymaps")
else
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({ vim.fn.system({
"git", "git",
"clone", "clone",
@ -8,87 +12,88 @@ if not vim.loop.fs_stat(lazypath) then
"--branch=stable", -- latest stable release "--branch=stable", -- latest stable release
lazypath, lazypath,
}) })
end end
vim.opt.rtp:prepend(lazypath) vim.opt.rtp:prepend(lazypath)
-- Set <space> as the leader key -- Set <space> as the leader key
-- See `:help mapleader` -- See `:help mapleader`
-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) -- NOTE: Must happen before plugins are required (otherwise wrong leader will be used)
vim.g.mapleader = " " vim.g.mapleader = " "
vim.g.maplocalleader = " " vim.g.maplocalleader = " "
require("lazy").setup("plugins", { require("lazy").setup("plugins", {
lockfile = vim.fn.stdpath("data") .. "/lazy-lock.json", -- in data directory as normal location read only as managed by nix lockfile = vim.fn.stdpath("data") .. "/lazy-lock.json", -- in data directory as normal location read only as managed by nix
dev = { dev = {
path = "~/Projects/Neovim", path = "~/Projects/Neovim",
}, },
}) })
-- [[ Setting options ]] -- [[ Setting options ]]
-- See `:help vim.o` -- See `:help vim.o`
-- Set highlight on search -- Set highlight on search
vim.o.hlsearch = true vim.o.hlsearch = true
vim.o.incsearch = true vim.o.incsearch = true
-- clipboard -- clipboard
vim.o.clipboard = "unnamedplus" vim.o.clipboard = "unnamedplus"
-- Make line numbers default -- Make line numbers default
vim.wo.number = true vim.wo.number = true
-- Enable mouse mode -- Enable mouse mode
vim.o.mouse = "a" vim.o.mouse = "a"
-- Enable break indent -- Enable break indent
vim.o.breakindent = true vim.o.breakindent = true
-- Save undo history -- Save undo history
vim.o.undofile = true vim.o.undofile = true
-- Case insensitive searching UNLESS /C or capital in search -- Case insensitive searching UNLESS /C or capital in search
vim.o.ignorecase = true vim.o.ignorecase = true
vim.o.smartcase = true vim.o.smartcase = true
-- Decrease update time -- Decrease update time
vim.o.updatetime = 250 vim.o.updatetime = 250
vim.wo.signcolumn = "yes" vim.wo.signcolumn = "yes"
vim.g.loaded_netrw = 1 vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1 vim.g.loaded_netrwPlugin = 1
-- Set completeopt to have a better completion experience -- Set completeopt to have a better completion experience
vim.o.completeopt = "menuone,noselect" vim.o.completeopt = "menuone,noselect"
-- [[ Basic Keymaps ]] -- [[ Basic Keymaps ]]
-- Keymaps for better default experience -- Keymaps for better default experience
-- See `:help vim.keymap.set()` -- See `:help vim.keymap.set()`
vim.keymap.set({ "n", "v" }, "<Space>", "<Nop>", { silent = true }) vim.keymap.set({ "n", "v" }, "<Space>", "<Nop>", { silent = true })
-- Remap for dealing with word wrap -- Remap for dealing with word wrap
vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
-- [[ Highlight on yank ]] -- [[ Highlight on yank ]]
-- See `:help vim.highlight.on_yank()` -- See `:help vim.highlight.on_yank()`
local highlight_group = vim.api.nvim_create_augroup("YankHighlight", { clear = true }) local highlight_group = vim.api.nvim_create_augroup("YankHighlight", { clear = true })
vim.api.nvim_create_autocmd("TextYankPost", { vim.api.nvim_create_autocmd("TextYankPost", {
callback = function() callback = function()
vim.highlight.on_yank() vim.highlight.on_yank()
end, end,
group = highlight_group, group = highlight_group,
pattern = "*", pattern = "*",
}) })
-- Terminal Escape Key Mapping -- Terminal Escape Key Mapping
vim.keymap.set("t", "<Esc>", [[<C-\><C-n>]]) vim.keymap.set("t", "<Esc>", [[<C-\><C-n>]])
-- Diagnostic keymaps -- Diagnostic keymaps
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev) vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next) vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float) vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float)
vim.keymap.set("n", "<leader>q", vim.diagnostic.setloclist) vim.keymap.set("n", "<leader>q", vim.diagnostic.setloclist)
-- The line beneath this is called `modeline`. See `:help modeline` -- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 et -- vim: ts=2 sts=2 sw=2 et
end

View file

@ -0,0 +1,41 @@
local keymap = vim.keymap.set
local opts = { noremap = true, silent = true }
-- remap leader key
keymap("n", "<Space>", "", opts)
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- yank to system clipboard
keymap({ "n", "v" }, "<leader>y", '"+y', opts)
-- paste from system clipboard
keymap({ "n", "v" }, "<leader>p", '"+p', opts)
-- better indent handling
keymap("v", "<", "<gv", opts)
keymap("v", ">", ">gv", opts)
-- move text up and down
keymap("v", "J", ":m .+1<CR>==", opts)
keymap("v", "K", ":m .-2<CR>==", opts)
keymap("x", "J", ":move '>+1<CR>gv-gv", opts)
keymap("x", "K", ":move '<-2<CR>gv-gv", opts)
-- paste preserves primal yanked piece
keymap("v", "p", '"_dP', opts)
-- removes highlighting after escaping vim search
keymap("n", "<Esc>", "<Esc>:noh<CR>", opts)
-- call vscode commands from neovim
keymap({ "n", "v" }, "<leader>t", "<cmd>lua require('vscode').action('workbench.action.terminal.toggleTerminal')<CR>")
keymap({ "n", "v" }, "<leader>b", "<cmd>lua require('vscode').action('editor.debug.action.toggleBreakpoint')<CR>")
keymap({ "n", "v" }, "<leader>d", "<cmd>lua require('vscode').action('editor.action.showHover')<CR>")
keymap({ "n", "v" }, "<leader>a", "<cmd>lua require('vscode').action('editor.action.quickFix')<CR>")
keymap({ "n", "v" }, "<leader>sp", "<cmd>lua require('vscode').action('workbench.actions.view.problems')<CR>")
keymap({ "n", "v" }, "<leader>cn", "<cmd>lua require('vscode').action('notifications.clearAll')<CR>")
keymap({ "n", "v" }, "<leader>ff", "<cmd>lua require('vscode').action('workbench.action.quickOpen')<CR>")
keymap({ "n", "v" }, "<leader>cp", "<cmd>lua require('vscode').action('workbench.action.showCommands')<CR>")
keymap({ "n", "v" }, "<leader>pr", "<cmd>lua require('vscode').action('code-runner.run')<CR>")
keymap({ "n", "v" }, "<leader>fd", "<cmd>lua require('vscode').action('editor.action.formatDocument')<CR>")