Skip to content

Instantly share code, notes, and snippets.

@Walcriz
Last active October 14, 2023 20:51
Show Gist options
  • Save Walcriz/c26ed061f9e355ee2a1fcfaaaf093a32 to your computer and use it in GitHub Desktop.
Save Walcriz/c26ed061f9e355ee2a1fcfaaaf093a32 to your computer and use it in GitHub Desktop.
Visual Studio Code Neovim configuration for when I need to use Live Share
--#####################################
-- VSCode Neovim Config for when I am forced to use VSCode
--
-- Walcriz
--#####################################
--------------
-- SETUP
--------------
-- require("bootstrap")
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)
-- require("config.lazysetup")
require("lazy").setup({
{ "folke/lazy.nvim", version = "*" },
{
"echasnovski/mini.pairs",
lazy = false,
opts = {
mappings = {
["<"] = { action = "open", pair = "<>", neigh_pattern = "[^ \t].", register = { cr = false } },
[">"] = { action = "close", pair = "<>", neigh_pattern = "[^ \t].", register = { cr = false } },
},
},
config = function(_, opts)
require("mini.pairs").setup(opts)
end,
},
{
"tpope/vim-commentary",
event = "VeryLazy",
},
}, {
spec = {
{ import = "plugins" },
},
defaults = {
lazy = true,
version = false,
},
checker = {
enabled = false,
},
performance = {
rtp = {
disabled_plugins = {
"gzip",
-- "matchit",
-- "matchparen",
"netrwPlugin",
"tarPlugin",
"tohtml",
"tutor",
"zipPlugin",
},
},
},
})
--------------
-- KEYMAPS
--------------
local function map(mode, lhs, rhs, opts)
opts = opts or {}
opts.silent = opts.silent ~= false
vim.keymap.set(mode, lhs, rhs, opts)
end
local function autocmd(action, opts)
return vim.api.nvim_create_autocmd(action, opts)
end
map("n", "<C-b>", "<C-6>", { desc = "Jump back to previous file" })
map("v", "<BS>", "s")
-- LSP keymaps
map("n", "<M-CR>", "<Cmd>call VSCodeNotify('keyboard-quickfix.openQuickFix')<Cr>")
map("n", "fr", "<Cmd>call VSCodeNotify('workbench.action.findInFiles', { 'query': expand('<cword>')})<CR>")
map("n", "ff", "<Cmd>call VSCodeNotify('workbench.action.quickOpen')<CR>")
map("n", "tt", "<Cmd>call VSCodeNotify('workbench.files.action.focusFilesExplorer')<CR>")
map("n", "rr", "<Cmd>call VSCodeNotify('editor.action.rename')<CR>")
autocmd("BufRead", {
callback = function()
vim.cmd([[
nmap <nowait> gu gH
]])
end,
})
-- Surround in visual mode
local surroundPairs = {
{ "(", ")" },
{ "{", "}" },
{ '"', '"' },
{ "'", "'" },
{ "[", "]" },
{ "`", "`" },
{ "<", ">" },
}
---@diagnostic disable-next-line: unused-local
for i, pair in ipairs(surroundPairs) do
local open = pair[1]
local close = pair[2]
-- Group 1: Spaces/Tabs in the beginning \([ \t]*\)
-- Group 2: The rest \(.*\)
-- Group 3: The last character in selection \(.\)
map("v", open, [[:s/\%V\([ \t]*\)\(.*\)\%V\(.\)/\1]] .. open .. [[\2\3]] .. close .. [[<cr>:noh<cr><esc>`<]])
-- Also map s to close and open
map("s", open, open .. close .. "<Left>")
end
--------------
-- OPTIONS
--------------
local opt = vim.opt
-- ETC --
opt.ruler = true
opt.showmatch = true
opt.showmode = true
-- EDITOR SETTINGS --
opt.confirm = true
opt.hidden = true
opt.backspace = "indent,eol,start"
opt.syntax = "enable"
opt.virtualedit = "onemore"
opt.showmode = false
opt.laststatus = 2
opt.pumblend = 10
opt.pumheight = 10
opt.shortmess:append({ W = true, I = true, c = true })
opt.autowrite = true
opt.updatetime = 50
opt.scrolloff = 15
opt.wildmode = "longest:full,full"
opt.wrap = false
opt.grepformat = "%f:%l:%c:%m"
opt.grepprg = "rg --vimgrep"
-- UNDO SETTINGS --
opt.undodir = os.getenv("HOME") .. "/.vim/undodir"
opt.undofile = true
opt.history = 1000
opt.undolevels = 10000
opt.updatetime = 200
-- COLUMN SETTINGS --
opt.signcolumn = "yes"
opt.colorcolumn = "100"
-- SEARCH SETTINGS --
opt.hlsearch = false
opt.ignorecase = true
opt.incsearch = true
opt.smartcase = true
-- FILE SETTINGS --
opt.formatoptions = "jcroqlnt"
-- WINDOW SETTINGS --
opt.splitbelow = true
opt.splitright = true
opt.winminwidth = 5
-- CLIPBOARD SYNC --
opt.clipboard = "unnamedplus"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment