nvim
This commit is contained in:
256
nvim/init.lua
Normal file
256
nvim/init.lua
Normal file
@@ -0,0 +1,256 @@
|
|||||||
|
require("config.lazy")
|
||||||
|
|
||||||
|
vim.opt.tabstop = 2
|
||||||
|
vim.opt.shiftwidth = 2
|
||||||
|
vim.opt.softtabstop = 2
|
||||||
|
vim.opt.expandtab = false
|
||||||
|
|
||||||
|
vim.opt.number = true
|
||||||
|
vim.opt.relativenumber = true
|
||||||
|
|
||||||
|
vim.opt.cursorline = true
|
||||||
|
vim.opt.scrolloff = 8
|
||||||
|
vim.opt.autoindent = true
|
||||||
|
|
||||||
|
vim.g.equalalways = false
|
||||||
|
|
||||||
|
vim.g.mapleader = " "
|
||||||
|
|
||||||
|
-- terminal mode is annoying :/
|
||||||
|
vim.keymap.set('t', '<Esc>', '<C-\\><C-n>', { silent = true })
|
||||||
|
|
||||||
|
-- use zsh
|
||||||
|
vim.opt.shell = "/usr/bin/zsh"
|
||||||
|
|
||||||
|
-- Setup the LSP stuff
|
||||||
|
local cmp = require("cmp")
|
||||||
|
local luasnip = require("luasnip")
|
||||||
|
|
||||||
|
cmp.setup({
|
||||||
|
snippet = {
|
||||||
|
expand = function(args)
|
||||||
|
luasnip.lsp_expand(args.body)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
mapping = cmp.mapping.preset.insert({
|
||||||
|
["<C-space>"] = cmp.mapping.complete(),
|
||||||
|
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
||||||
|
}),
|
||||||
|
sources = {
|
||||||
|
{ name = "nvim_lsp" },
|
||||||
|
{ name = "luasnip" },
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
local caps = require("cmp_nvim_lsp").default_capabilities()
|
||||||
|
|
||||||
|
local on_attach = function(client, bufnr)
|
||||||
|
local opts = { noremap=true, silent=true, buffer=bufnr }
|
||||||
|
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
|
||||||
|
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- clangd
|
||||||
|
vim.lsp.config("clangd", {
|
||||||
|
cmd = { "clangd", "--compile-commands-dir=build" },
|
||||||
|
capabilities = caps,
|
||||||
|
on_attach = on_attach,
|
||||||
|
})
|
||||||
|
vim.lsp.enable("clangd")
|
||||||
|
|
||||||
|
-- rust-analyzer
|
||||||
|
vim.lsp.config("rust_analyzer", {
|
||||||
|
settings = {
|
||||||
|
["rust-analyzer"] = {
|
||||||
|
inlayHints = {
|
||||||
|
parameterHints = { enable = true },
|
||||||
|
typeHints = { enable = true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
capabilities = caps,
|
||||||
|
on_attach = on_attach,
|
||||||
|
})
|
||||||
|
vim.lsp.enable("rust_analyzer")
|
||||||
|
|
||||||
|
-- typescript
|
||||||
|
vim.lsp.config("ts_ls", {
|
||||||
|
capabilities = caps,
|
||||||
|
on_attach = on_attach,
|
||||||
|
filetypes = { "javascript", "javascriptreact", "typescript", "typescriptreact", "typescript.tsx" },
|
||||||
|
cmd = { "typescript-language-server", "--stdio" },
|
||||||
|
})
|
||||||
|
vim.lsp.enable("ts_ls")
|
||||||
|
|
||||||
|
-- gopls
|
||||||
|
vim.lsp.config("gopls", {
|
||||||
|
settings = {
|
||||||
|
gopls = {
|
||||||
|
gofumpt = true,
|
||||||
|
staticcheck = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
capabilities = caps,
|
||||||
|
on_attach = on_attach,
|
||||||
|
})
|
||||||
|
vim.lsp.enable("gopls")
|
||||||
|
|
||||||
|
-- pyright
|
||||||
|
vim.lsp.config("pyright", {
|
||||||
|
capabilities = caps,
|
||||||
|
})
|
||||||
|
|
||||||
|
local notify = require("notify")
|
||||||
|
|
||||||
|
vim.keymap.set("n", "<leader>cd", function()
|
||||||
|
local buf = vim.api.nvim_create_buf(false, true)
|
||||||
|
|
||||||
|
local width = math.floor(vim.o.columns * 0.8)
|
||||||
|
local height = math.floor(vim.o.lines * 0.5)
|
||||||
|
local row = math.floor((vim.o.lines - height) / 2)
|
||||||
|
local col = math.floor((vim.o.columns - width) / 2)
|
||||||
|
|
||||||
|
local opts = {
|
||||||
|
style = "minimal",
|
||||||
|
relative = "editor",
|
||||||
|
width = width,
|
||||||
|
height = height,
|
||||||
|
row = row,
|
||||||
|
col = col,
|
||||||
|
border = "rounded",
|
||||||
|
}
|
||||||
|
|
||||||
|
vim.api.nvim_open_win(buf, true, opts)
|
||||||
|
|
||||||
|
vim.fn.termopen("mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..", {
|
||||||
|
on_stdout = function(_, _, _)
|
||||||
|
local win = vim.api.nvim_get_current_win()
|
||||||
|
vim.api.nvim_win_set_cursor(win, {vim.api.nvim_buf_line_count(0), 0})
|
||||||
|
end,
|
||||||
|
on_stderr = function(_, _, _)
|
||||||
|
local win = vim.api.nvim_get_current_win()
|
||||||
|
vim.api.nvim_win_set_cursor(win, {vim.api.nvim_buf_line_count(0), 0})
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_buf_set_keymap(buf, "n", "q", "<cmd>bd!<CR>", { silent = true, noremap = true })
|
||||||
|
end, { desc = "Configure CMake Debug Build in floating terminal" })
|
||||||
|
|
||||||
|
vim.keymap.set("n", "<leader>cr", function()
|
||||||
|
local buf = vim.api.nvim_create_buf(false, true)
|
||||||
|
|
||||||
|
local width = math.floor(vim.o.columns * 0.8)
|
||||||
|
local height = math.floor(vim.o.lines * 0.5)
|
||||||
|
local row = math.floor((vim.o.lines - height) / 2)
|
||||||
|
local col = math.floor((vim.o.columns - width) / 2)
|
||||||
|
|
||||||
|
local opts = {
|
||||||
|
style = "minimal",
|
||||||
|
relative = "editor",
|
||||||
|
width = width,
|
||||||
|
height = height,
|
||||||
|
row = row,
|
||||||
|
col = col,
|
||||||
|
border = "rounded",
|
||||||
|
}
|
||||||
|
|
||||||
|
vim.api.nvim_open_win(buf, true, opts)
|
||||||
|
|
||||||
|
vim.fn.termopen("mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..", {
|
||||||
|
on_stdout = function(_, _, _)
|
||||||
|
local win = vim.api.nvim_get_current_win()
|
||||||
|
vim.api.nvim_win_set_cursor(win, {vim.api.nvim_buf_line_count(0), 0})
|
||||||
|
end,
|
||||||
|
on_stderr = function(_, _, _)
|
||||||
|
local win = vim.api.nvim_get_current_win()
|
||||||
|
vim.api.nvim_win_set_cursor(win, {vim.api.nvim_buf_line_count(0), 0})
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_buf_set_keymap(buf, "n", "q", "<cmd>bd!<CR>", { silent = true, noremap = true })
|
||||||
|
end, { desc = "Configure CMake Release Build in floating terminal" })
|
||||||
|
|
||||||
|
vim.keymap.set("n", "<leader>cp", function()
|
||||||
|
local buf = vim.api.nvim_create_buf(false, true)
|
||||||
|
|
||||||
|
local width = math.floor(vim.o.columns * 0.8)
|
||||||
|
local height = math.floor(vim.o.lines * 0.5)
|
||||||
|
local row = math.floor((vim.o.lines - height) / 2)
|
||||||
|
local col = math.floor((vim.o.columns - width) / 2)
|
||||||
|
|
||||||
|
local opts = {
|
||||||
|
style = "minimal",
|
||||||
|
relative = "editor",
|
||||||
|
width = width,
|
||||||
|
height = height,
|
||||||
|
row = row,
|
||||||
|
col = col,
|
||||||
|
border = "rounded",
|
||||||
|
}
|
||||||
|
|
||||||
|
vim.api.nvim_open_win(buf, true, opts)
|
||||||
|
|
||||||
|
vim.fn.termopen("mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..", {
|
||||||
|
on_stdout = function(_, _, _)
|
||||||
|
local win = vim.api.nvim_get_current_win()
|
||||||
|
vim.api.nvim_win_set_cursor(win, {vim.api.nvim_buf_line_count(0), 0})
|
||||||
|
end,
|
||||||
|
on_stderr = function(_, _, _)
|
||||||
|
local win = vim.api.nvim_get_current_win()
|
||||||
|
vim.api.nvim_win_set_cursor(win, {vim.api.nvim_buf_line_count(0), 0})
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_buf_set_keymap(buf, "n", "q", "<cmd>bd!<CR>", { silent = true, noremap = true })
|
||||||
|
end, { desc = "Configure CMake RelWithDebugInfo Build in floating terminal" })
|
||||||
|
|
||||||
|
vim.api.nvim_create_user_command("Build", function(opts)
|
||||||
|
local target = opts.args
|
||||||
|
if target == "" then
|
||||||
|
print("Usage: :Build <target>")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local buf = vim.api.nvim_create_buf(false, true)
|
||||||
|
local win = vim.api.nvim_open_win(buf, true, {
|
||||||
|
relative = 'editor',
|
||||||
|
width = math.floor(vim.o.columns * 0.8),
|
||||||
|
height = math.floor(vim.o.lines * 0.8),
|
||||||
|
row = math.floor(vim.o.lines * 0.1),
|
||||||
|
col = math.floor(vim.o.columns * 0.1),
|
||||||
|
style = 'minimal',
|
||||||
|
border = 'single',
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.fn.termopen("cmake --build build --parallel 20 --target " .. target, {
|
||||||
|
on_stdout = function(_, _, _)
|
||||||
|
local win = vim.api.nvim_get_current_win()
|
||||||
|
vim.api.nvim_win_set_cursor(win, {vim.api.nvim_buf_line_count(0), 0})
|
||||||
|
end,
|
||||||
|
on_stderr = function(_, _, _)
|
||||||
|
local win = vim.api.nvim_get_current_win()
|
||||||
|
vim.api.nvim_win_set_cursor(win, {vim.api.nvim_buf_line_count(0), 0})
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_buf_set_keymap(buf, "n", "q", "<cmd>bd!<CR>", { silent = true, noremap = true })
|
||||||
|
end, {
|
||||||
|
nargs = 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
|
group = vim.api.nvim_create_augroup("AutoFormatOnSave", { clear = true }),
|
||||||
|
pattern = "*",
|
||||||
|
callback = function()
|
||||||
|
vim.lsp.buf.format({ async = false })
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.keymap.set('n', '<leader>cs', function()
|
||||||
|
require('telescope.builtin').colorscheme({
|
||||||
|
enable_preview = true -- live preview
|
||||||
|
})
|
||||||
|
end, { desc = "Pick a colorscheme" })
|
||||||
|
|
||||||
|
vim.keymap.set("n", "<leader>r", "<cmd>Telescope live_grep<cr>", { noremap = true, silent = true })
|
||||||
|
|
||||||
20
nvim/lazy-lock.json
Normal file
20
nvim/lazy-lock.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"LuaSnip": { "branch": "master", "commit": "b3104910bb5ebf40492aadffae18f2528fa757d9" },
|
||||||
|
"cmp-nvim-lsp": { "branch": "main", "commit": "bd5a7d6db125d4654b50eeae9f5217f24bb22fd3" },
|
||||||
|
"cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" },
|
||||||
|
"lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" },
|
||||||
|
"lualine.nvim": { "branch": "master", "commit": "b8c23159c0161f4b89196f74ee3a6d02cdc3a955" },
|
||||||
|
"monochrome.nvim": { "branch": "main", "commit": "2de78d9688ea4a177bcd9be554ab9192337d35ff" },
|
||||||
|
"nvim-autopairs": { "branch": "master", "commit": "23320e75953ac82e559c610bec5a90d9c6dfa743" },
|
||||||
|
"nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" },
|
||||||
|
"nvim-lspconfig": { "branch": "master", "commit": "b3cce1419ca67871ae782b3e529652f8a016f0de" },
|
||||||
|
"nvim-notify": { "branch": "master", "commit": "8701bece920b38ea289b457f902e2ad184131a5d" },
|
||||||
|
"nvim-tree.lua": { "branch": "master", "commit": "e179ad2f83b5955ab0af653069a493a1828c2697" },
|
||||||
|
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
|
||||||
|
"nvim-web-devicons": { "branch": "master", "commit": "6e51ca170563330e063720449c21f43e27ca0bc1" },
|
||||||
|
"oxocarbon.nvim": { "branch": "main", "commit": "9f85f6090322f39b11ae04a343d4eb9d12a86897" },
|
||||||
|
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
|
||||||
|
"telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" },
|
||||||
|
"tokyodark.nvim": { "branch": "master", "commit": "cc70a2fb809d5376f2bd8e5836f9bb3f5fb8ef43" },
|
||||||
|
"tokyonight.nvim": { "branch": "main", "commit": "14fd5ff7f84027064724ec3157fe903199e77ded" }
|
||||||
|
}
|
||||||
35
nvim/lua/config/lazy.lua
Normal file
35
nvim/lua/config/lazy.lua
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
-- Bootstrap lazy.nvim
|
||||||
|
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
||||||
|
if not (vim.uv or vim.loop).fs_stat(lazypath) then
|
||||||
|
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
|
||||||
|
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
|
||||||
|
if vim.v.shell_error ~= 0 then
|
||||||
|
vim.api.nvim_echo({
|
||||||
|
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
|
||||||
|
{ out, "WarningMsg" },
|
||||||
|
{ "\nPress any key to exit..." },
|
||||||
|
}, true, {})
|
||||||
|
vim.fn.getchar()
|
||||||
|
os.exit(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
vim.opt.rtp:prepend(lazypath)
|
||||||
|
|
||||||
|
-- Make sure to setup `mapleader` and `maplocalleader` before
|
||||||
|
-- loading lazy.nvim so that mappings are correct.
|
||||||
|
-- This is also a good place to setup other settings (vim.opt)
|
||||||
|
vim.g.mapleader = " "
|
||||||
|
vim.g.maplocalleader = "\\"
|
||||||
|
|
||||||
|
-- Setup lazy.nvim
|
||||||
|
require("lazy").setup({
|
||||||
|
spec = {
|
||||||
|
-- import your plugins
|
||||||
|
{ import = "plugins" },
|
||||||
|
},
|
||||||
|
-- Configure any other settings here. See the documentation for more details.
|
||||||
|
-- colorscheme that will be used when installing plugins.
|
||||||
|
install = { colorscheme = { "habamax" } },
|
||||||
|
-- automatically check for plugin updates
|
||||||
|
checker = { enabled = true },
|
||||||
|
})
|
||||||
117
nvim/lua/plugins/base.lua
Normal file
117
nvim/lua/plugins/base.lua
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
return {
|
||||||
|
{
|
||||||
|
"folke/tokyonight.nvim",
|
||||||
|
lazy = false, -- make sure we load this during startup if it is your main colorscheme
|
||||||
|
priority = 1000, -- make sure to load this before all the other start plugins
|
||||||
|
config = function()
|
||||||
|
-- load the colorscheme here
|
||||||
|
-- vim.cmd([[colorscheme tokyonight]])
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"nyoom-engineering/oxocarbon.nvim",
|
||||||
|
lazy = false,
|
||||||
|
priority = 1001,
|
||||||
|
config = function()
|
||||||
|
--vim.opt.background = "light"
|
||||||
|
--vim.cmd([[colorscheme oxocarbon]])
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"tiagovla/tokyodark.nvim",
|
||||||
|
opts = {
|
||||||
|
-- custom options here
|
||||||
|
},
|
||||||
|
config = function(_, opts)
|
||||||
|
require("tokyodark").setup(opts) -- calling setup is optional
|
||||||
|
vim.cmd [[colorscheme tokyodark]]
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"kdheepak/monochrome.nvim",
|
||||||
|
lazy = false,
|
||||||
|
priority = 1002,
|
||||||
|
config = function()
|
||||||
|
-- vim.cmd([[colorscheme monochrome]])
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"nvim-treesitter/nvim-treesitter",
|
||||||
|
branch = 'master',
|
||||||
|
lazy = false,
|
||||||
|
build = ":TSUpdate",
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"nvim-tree/nvim-tree.lua",
|
||||||
|
dependencies = { "nvim-tree/nvim-web-devicons" },
|
||||||
|
config = function()
|
||||||
|
require("nvim-tree").setup({
|
||||||
|
on_attach = function(bufnr)
|
||||||
|
local api = require("nvim-tree.api")
|
||||||
|
|
||||||
|
api.config.mappings.default_on_attach(bufnr)
|
||||||
|
vim.keymap.set('n', '<CR>', function()
|
||||||
|
local node = api.tree.get_node_under_cursor()
|
||||||
|
api.node.open.edit()
|
||||||
|
|
||||||
|
if not node or node.nodes == nil then
|
||||||
|
api.tree.close()
|
||||||
|
end
|
||||||
|
|
||||||
|
end, { buffer = bufnr, noremap = true, silent = true })
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.keymap.set("n", "<C-n>", ":NvimTreeToggle<CR>", { noremap = true, silent = true })
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"nvim-telescope/telescope.nvim",
|
||||||
|
tag = "0.1.8",
|
||||||
|
dependencies = { "nvim-lua/plenary.nvim" },
|
||||||
|
config = function()
|
||||||
|
local builtin = require('telescope.builtin')
|
||||||
|
vim.keymap.set("n", "<leader>f", builtin.find_files, { desc = "Telescope find files" })
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"nvim-lualine/lualine.nvim",
|
||||||
|
config = function()
|
||||||
|
require("lualine").setup()
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"windwp/nvim-autopairs",
|
||||||
|
config = function()
|
||||||
|
require("nvim-autopairs").setup()
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"neovim/nvim-lspconfig",
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"hrsh7th/nvim-cmp",
|
||||||
|
dependencies = {
|
||||||
|
"hrsh7th/cmp-nvim-lsp",
|
||||||
|
"L3MON4D3/LuaSnip",
|
||||||
|
"saadparwaiz1/cmp_luasnip",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"rcarriga/nvim-notify",
|
||||||
|
config = function()
|
||||||
|
vim.notify = require("notify")
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user