diff --git a/init.lua b/init.lua index e9da6ef..1cde3e3 100644 --- a/init.lua +++ b/init.lua @@ -1,94 +1,99 @@ -local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" -if not vim.loop.fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", -- latest stable release - lazypath, +if vim.g.vscode 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({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) + end + vim.opt.rtp:prepend(lazypath) + + -- Set as the leader key + -- See `:help mapleader` + -- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) + vim.g.mapleader = " " + vim.g.maplocalleader = " " + + require("lazy").setup("plugins", { + lockfile = vim.fn.stdpath("data") .. "/lazy-lock.json", -- in data directory as normal location read only as managed by nix + dev = { + path = "~/Projects/Neovim", + }, }) + + -- [[ Setting options ]] + -- See `:help vim.o` + + -- Set highlight on search + vim.o.hlsearch = true + vim.o.incsearch = true + + -- clipboard + vim.o.clipboard = "unnamedplus" + + -- Make line numbers default + vim.wo.number = true + + -- Enable mouse mode + vim.o.mouse = "a" + + -- Enable break indent + vim.o.breakindent = true + + -- Save undo history + vim.o.undofile = true + + -- Case insensitive searching UNLESS /C or capital in search + vim.o.ignorecase = true + vim.o.smartcase = true + + -- Decrease update time + vim.o.updatetime = 250 + vim.wo.signcolumn = "yes" + + vim.g.loaded_netrw = 1 + vim.g.loaded_netrwPlugin = 1 + + -- Set completeopt to have a better completion experience + vim.o.completeopt = "menuone,noselect" + + -- [[ Basic Keymaps ]] + + -- Keymaps for better default experience + -- See `:help vim.keymap.set()` + vim.keymap.set({ "n", "v" }, "", "", { silent = true }) + + -- Remap for dealing with word wrap + 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 }) + + -- [[ Highlight on yank ]] + -- See `:help vim.highlight.on_yank()` + local highlight_group = vim.api.nvim_create_augroup("YankHighlight", { clear = true }) + vim.api.nvim_create_autocmd("TextYankPost", { + callback = function() + vim.highlight.on_yank() + end, + group = highlight_group, + pattern = "*", + }) + + -- Terminal Escape Key Mapping + vim.keymap.set("t", "", [[]]) + + -- Diagnostic keymaps + vim.keymap.set("n", "[d", vim.diagnostic.goto_prev) + vim.keymap.set("n", "]d", vim.diagnostic.goto_next) + vim.keymap.set("n", "e", vim.diagnostic.open_float) + vim.keymap.set("n", "q", vim.diagnostic.setloclist) + + -- The line beneath this is called `modeline`. See `:help modeline` + -- vim: ts=2 sts=2 sw=2 et end -vim.opt.rtp:prepend(lazypath) - --- Set as the leader key --- See `:help mapleader` --- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) -vim.g.mapleader = " " -vim.g.maplocalleader = " " - -require("lazy").setup("plugins", { - lockfile = vim.fn.stdpath("data") .. "/lazy-lock.json", -- in data directory as normal location read only as managed by nix - dev = { - path = "~/Projects/Neovim", - }, -}) - --- [[ Setting options ]] --- See `:help vim.o` - --- Set highlight on search -vim.o.hlsearch = true -vim.o.incsearch = true - --- clipboard -vim.o.clipboard = "unnamedplus" - --- Make line numbers default -vim.wo.number = true - --- Enable mouse mode -vim.o.mouse = "a" - --- Enable break indent -vim.o.breakindent = true - --- Save undo history -vim.o.undofile = true - --- Case insensitive searching UNLESS /C or capital in search -vim.o.ignorecase = true -vim.o.smartcase = true - --- Decrease update time -vim.o.updatetime = 250 -vim.wo.signcolumn = "yes" - -vim.g.loaded_netrw = 1 -vim.g.loaded_netrwPlugin = 1 - --- Set completeopt to have a better completion experience -vim.o.completeopt = "menuone,noselect" - --- [[ Basic Keymaps ]] - --- Keymaps for better default experience --- See `:help vim.keymap.set()` -vim.keymap.set({ "n", "v" }, "", "", { silent = true }) - --- Remap for dealing with word wrap -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 }) - --- [[ Highlight on yank ]] --- See `:help vim.highlight.on_yank()` -local highlight_group = vim.api.nvim_create_augroup("YankHighlight", { clear = true }) -vim.api.nvim_create_autocmd("TextYankPost", { - callback = function() - vim.highlight.on_yank() - end, - group = highlight_group, - pattern = "*", -}) - --- Terminal Escape Key Mapping -vim.keymap.set("t", "", [[]]) - --- Diagnostic keymaps -vim.keymap.set("n", "[d", vim.diagnostic.goto_prev) -vim.keymap.set("n", "]d", vim.diagnostic.goto_next) -vim.keymap.set("n", "e", vim.diagnostic.open_float) -vim.keymap.set("n", "q", vim.diagnostic.setloclist) - --- The line beneath this is called `modeline`. See `:help modeline` --- vim: ts=2 sts=2 sw=2 et diff --git a/lua/user/vscode_keymaps.lua b/lua/user/vscode_keymaps.lua new file mode 100644 index 0000000..c58727b --- /dev/null +++ b/lua/user/vscode_keymaps.lua @@ -0,0 +1,41 @@ +local keymap = vim.keymap.set +local opts = { noremap = true, silent = true } + +-- remap leader key +keymap("n", "", "", opts) +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +-- yank to system clipboard +keymap({ "n", "v" }, "y", '"+y', opts) + +-- paste from system clipboard +keymap({ "n", "v" }, "p", '"+p', opts) + +-- better indent handling +keymap("v", "<", "", ">gv", opts) + +-- move text up and down +keymap("v", "J", ":m .+1==", opts) +keymap("v", "K", ":m .-2==", opts) +keymap("x", "J", ":move '>+1gv-gv", opts) +keymap("x", "K", ":move '<-2gv-gv", opts) + +-- paste preserves primal yanked piece +keymap("v", "p", '"_dP', opts) + +-- removes highlighting after escaping vim search +keymap("n", "", ":noh", opts) + +-- call vscode commands from neovim +keymap({ "n", "v" }, "t", "lua require('vscode').action('workbench.action.terminal.toggleTerminal')") +keymap({ "n", "v" }, "b", "lua require('vscode').action('editor.debug.action.toggleBreakpoint')") +keymap({ "n", "v" }, "d", "lua require('vscode').action('editor.action.showHover')") +keymap({ "n", "v" }, "a", "lua require('vscode').action('editor.action.quickFix')") +keymap({ "n", "v" }, "sp", "lua require('vscode').action('workbench.actions.view.problems')") +keymap({ "n", "v" }, "cn", "lua require('vscode').action('notifications.clearAll')") +keymap({ "n", "v" }, "ff", "lua require('vscode').action('workbench.action.quickOpen')") +keymap({ "n", "v" }, "cp", "lua require('vscode').action('workbench.action.showCommands')") +keymap({ "n", "v" }, "pr", "lua require('vscode').action('code-runner.run')") +keymap({ "n", "v" }, "fd", "lua require('vscode').action('editor.action.formatDocument')")