nova config en lua, basada na do ThePrimeagen

This commit is contained in:
serxoz 2023-03-06 12:49:58 +01:00
parent fea53fd1d6
commit 422cb2c409
31 changed files with 447 additions and 180 deletions

2
nvim/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
plugin/packer_compiled.lua

View File

@ -1,14 +1,4 @@
custom config files for nvchad # Serxoz init.lua
Prerequisite: install [ripgrep](https://github.com/BurntSushi/ripgrep).
## First run Based on the [ThePrimeagen's one](https://github.com/ThePrimeagen/init.lua).
In order to install nvchad pluggins and custom ones you must follow:
- sh install.sh
- <ESC>:q
- exec nvim
- <ESC>:PackerSync
- <ESC>:MasonInstallAll
- now it must work fine
## Add language to LSP
- Add lang server in "custom/plugins/lspconfig.lua" file.
- Add lang server to Mason custom override in "custom/override.lua" to install with ":MasonInstallAll"

View File

@ -0,0 +1,18 @@
require("bufferline").setup{
options = {
separator_style = "slant",
show_buffer_icons = true,
show_close_icon = false,
diagnostics = "nvim_lsp",
diagnostics_indicator = function(count, level)
local icon = level:match("error") and "" or ""
return icon .. count
end,
highlights = {
tab = {
fg = '#121212',
bg = '#120000'
}
}
}
}

View File

@ -0,0 +1,22 @@
require("cloak").setup({
enabled = true,
cloak_character = "*",
-- The applied highlight group (colors) on the cloaking, see `:h highlight`.
highlight_group = "Comment",
patterns = {
{
-- Match any file starting with ".env".
-- This can be a table to match multiple file patterns.
file_pattern = {
".env*",
"wrangler.toml",
".dev.vars",
},
-- Match an equals sign and any character after it.
-- This can also be a table of patterns to cloak,
-- example: cloak_pattern = { ":.+", "-.+" } for yaml files.
cloak_pattern = "=.+"
},
},
})

View File

@ -0,0 +1,15 @@
require("gruvbox").setup({
gruvbox_contrast_dark = 'hard',
gruvbox_invert_selection = '0',
})
function ColorMyPencils(color)
color = color or "gruvbox"
vim.cmd.colorscheme(color)
vim.api.nvim_set_hl(0, "Normal", { bg = "none" })
vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" })
end
ColorMyPencils()

View File

@ -0,0 +1 @@
require('nvim_comment').setup()

View File

@ -0,0 +1,29 @@
vim.keymap.set("n", "<leader>gs", vim.cmd.Git)
local Serxoz_Fugitive = vim.api.nvim_create_augroup("Serxoz_Fugitive", {})
local autocmd = vim.api.nvim_create_autocmd
autocmd("BufWinEnter", {
group = Serxoz_Fugitive,
pattern = "*",
callback = function()
if vim.bo.ft ~= "fugitive" then
return
end
local bufnr = vim.api.nvim_get_current_buf()
local opts = {buffer = bufnr, remap = false}
vim.keymap.set("n", "<leader>p", function()
vim.cmd.Git('push')
end, opts)
-- rebase always
vim.keymap.set("n", "<leader>P", function()
vim.cmd.Git({'pull', '--rebase'})
end, opts)
-- NOTE: It allows me to easily set the branch i am pushing and any tracking
-- needed if i did not set the branch up correctly
vim.keymap.set("n", "<leader>t", ":Git push -u origin ", opts);
end,
})

View File

@ -1,5 +0,0 @@
require('go').setup()
-- Run gofmt + goimport on save
vim.api.nvim_exec([[ autocmd BufWritePre *.go :silent! lua require('go.format').gofmt() ]], false)
vim.api.nvim_exec([[ autocmd BufWritePre *.go :silent! lua require('go.format').goimport() ]], false)

View File

@ -0,0 +1,12 @@
local mark = require("harpoon.mark")
local ui = require("harpoon.ui")
vim.keymap.set("n", "<leader>a", mark.add_file)
vim.keymap.set("n", "<C-e>", ui.toggle_quick_menu)
vim.keymap.set("n", "<C-u>", function() ui.nav_file(1) end)
vim.keymap.set("n", "<C-i>", function() ui.nav_file(2) end)
vim.keymap.set("n", "<C-o>", function() ui.nav_file(3) end)
vim.keymap.set("n", "<C-p>", function() ui.nav_file(4) end)

View File

@ -1 +0,0 @@
vim.cmd(":TSInstall all");

71
nvim/after/plugin/lsp.lua Normal file
View File

@ -0,0 +1,71 @@
local lsp = require("lsp-zero")
lsp.preset("recommended")
lsp.ensure_installed({
'tsserver',
'rust_analyzer',
'jedi_language_server',
'gopls',
'cssls'
})
-- Fix Undefined global 'vim'
lsp.configure('lua-language-server', {
settings = {
Lua = {
diagnostics = {
globals = { 'vim' }
}
}
}
})
local cmp = require('cmp')
local cmp_select = {behavior = cmp.SelectBehavior.Select}
local cmp_mappings = lsp.defaults.cmp_mappings({
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
['<C-y>'] = cmp.mapping.confirm({ select = true }),
["<C-Space>"] = cmp.mapping.complete(),
})
cmp_mappings['<Tab>'] = nil
cmp_mappings['<S-Tab>'] = nil
lsp.setup_nvim_cmp({
mapping = cmp_mappings
})
lsp.set_preferences({
suggest_lsp_servers = false,
sign_icons = {
error = 'E',
warn = 'W',
hint = 'H',
info = 'I'
}
})
lsp.on_attach(function(client, bufnr)
local opts = {buffer = bufnr, remap = false}
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts)
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts)
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, opts)
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts)
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
end)
lsp.setup()
vim.diagnostic.config({
virtual_text = true
})

View File

@ -0,0 +1,5 @@
require('refactoring').setup({})
vim.api.nvim_set_keymap("v", "<leader>ri", [[ <Esc><Cmd>lua require('refactoring').refactor('Inline Variable')<CR>]], {noremap = true, silent = true, expr = false})

View File

@ -0,0 +1,14 @@
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>pf', builtin.find_files, {})
vim.keymap.set('n', '<C-p>', builtin.git_files, {})
vim.keymap.set('n', '<leader>ps', function()
builtin.grep_string({ search = vim.fn.input("Grep > ") })
end)
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>fw', function()
builtin.grep_string({ search = vim.fn.expand("<cword>") })
end)

View File

@ -0,0 +1,23 @@
require'nvim-treesitter.configs'.setup {
-- A list of parser names, or "all"
ensure_installed = { "help", "javascript", "typescript", "c", "lua", "rust", "python" },
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
-- Automatically install missing parsers when entering buffer
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
auto_install = true,
highlight = {
-- `false` will disable the whole extension
enable = true,
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
}

View File

@ -0,0 +1,3 @@
vim.keymap.set("n", "<leader>xq", "<cmd>TroubleToggle quickfix<cr>",
{silent = true, noremap = true}
)

View File

@ -0,0 +1,2 @@
vim.keymap.set("n", "<leader>u", vim.cmd.UndotreeToggle)

View File

@ -0,0 +1,30 @@
vim.keymap.set("n", "<leader>zz", function()
require("zen-mode").setup {
window = {
width = 90,
options = { }
},
}
require("zen-mode").toggle()
vim.wo.wrap = false
vim.wo.number = true
vim.wo.rnu = true
ColorMyPencils()
end)
vim.keymap.set("n", "<leader>zZ", function()
require("zen-mode").setup {
window = {
width = 80,
options = { }
},
}
require("zen-mode").toggle()
vim.wo.wrap = false
vim.wo.number = false
vim.wo.rnu = false
vim.opt.colorcolumn = "0"
ColorMyPencils()
end)

View File

@ -1,5 +1,3 @@
#!/bin/sh #!/bin/sh
rm -rf ~/.config/nvim rm ~/.config/nvim
rm -rf ~/.local/share/nvim
rm -rf ~/.cache/nvim

View File

@ -1,20 +0,0 @@
local M = {}
local override = require "custom.override"
M.plugins = {
override = {
["nvim-treesitter/nvim-treesitter"] = override.treesitter,
["williamboman/mason.nvim"] = override.mason,
},
user = require "custom.plugins",
}
M.ui = {
theme = "gruvchad",
}
M.mappings = require "custom.mappings"
return M

View File

@ -1,7 +0,0 @@
vim.opt.rnu = true
vim.opt.colorcolumn = "80"
vim.opt.scrolloff = 8
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true

View File

@ -1,65 +0,0 @@
local M = {}
M.general = {
n = {
["<leader> "] = { ":noh<CR>", "Clean search highlight" },
["<leader>d"] = { "\"_d", "Delete without yank" },
},
v = {
["J"] = { ":m '>+1<CR>gv=gv", "Move visual block up" },
["K"] = { ":m '<-2<CR>gv=gv", "Move visual block down" },
["<"] = { "<gv", "Keep visual on shift" },
[">"] = { ">gv", "Keep visual on shift" },
["<leader>d"] = { "\"_d", "Delete without yank" },
}
}
M.harpoon = {
n = {
["<leader>ss"] = {
function()
require("harpoon.ui").toggle_quick_menu()
end,
" harpoon show menu"
},
["<leader>sa"] = {
function()
require("harpoon.mark").add_file()
end,
" harpoon add file"
},
["<leader>su"] = {
function()
require("harpoon.ui").nav_file(1)
end,
" harpoon go to file 1"
},
["<leader>si"] = {
function()
require("harpoon.ui").nav_file(2)
end,
" harpoon go to file 2"
},
["<leader>so"] = {
function()
require("harpoon.ui").nav_file(3)
end,
" harpoon go to file 3"
},
["<leader>sp"] = {
function()
require("harpoon.ui").nav_file(4)
end,
" harpoon go to file 4"
},
}
}
M.telescope = {
n = {
["<leader>fg"] = { "<cmd> Telescope live_grep <CR>", " live grep" },
["<leader>fm"] = { "<cmd> Telescope marks <CR>", " marks" },
}
}
return M

View File

@ -1,28 +0,0 @@
local M = {}
M.treesitter = {
ensure_installed = {
"vim",
"html",
"css",
"javascript",
"json",
"toml",
"markdown",
"c",
"bash",
"lua",
"python",
"go",
},
}
M.mason = {
ensure_installed = {
"gopls",
"pyright",
"rust-analyzer",
}
}
return M

View File

@ -1,2 +0,0 @@
local M = {}
return M

View File

@ -1,17 +0,0 @@
return {
["neovim/nvim-lspconfig"] = {
config = function()
require "plugins.configs.lspconfig"
require "custom.plugins.lspconfig"
end,
},
['ThePrimeagen/harpoon'] = {
module = "harpoon",
ft = "harpoon",
config = function()
require "custom.plugins.harpoon"
end,
},
['ray-x/go.nvim'] = {},
['ray-x/guihua.lua'] = {},
}

View File

@ -1,13 +0,0 @@
-- custom.plugins.lspconfig
local on_attach = require("plugins.configs.lspconfig").on_attach
local capabilities = require("plugins.configs.lspconfig").capabilities
local lspconfig = require "lspconfig"
local servers = { "html", "cssls", "clangd", "gopls", "pyright", "rust_analyzer"}
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
on_attach = on_attach,
capabilities = capabilities,
}
end

2
nvim/init.lua Normal file
View File

@ -0,0 +1,2 @@
require("serxoz")
require('serxoz.packer')

View File

@ -1,9 +1,5 @@
#!/bin/sh #!/bin/sh
rm -rf ~/.config/nvim rm ~/.config/nvim
rm -rf ~/.local/share/nvim
rm -rf ~/.cache/nvim
git clone https://github.com/NvChad/NvChad ~/.config/nvim --depth 1 ; nvim
ln -s $HOME/dotfiles/nvim/custom $HOME/.config/nvim/lua/custom
ln -s $HOME/dotfiles/nvim/after $HOME/.config/nvim/after
ln -s $HOME/dotfiles/nvim $HOME/.config/.

33
nvim/lua/serxoz/init.lua Normal file
View File

@ -0,0 +1,33 @@
require("serxoz.set")
require("serxoz.remap")
local augroup = vim.api.nvim_create_augroup
local SerxozGroup = augroup('Serxoz', {})
local autocmd = vim.api.nvim_create_autocmd
local yank_group = augroup('HighlightYank', {})
function R(name)
require("plenary.reload").reload_module(name)
end
autocmd('TextYankPost', {
group = yank_group,
pattern = '*',
callback = function()
vim.highlight.on_yank({
higroup = 'IncSearch',
timeout = 40,
})
end,
})
autocmd({"BufWritePre"}, {
group = SerxozGroup,
pattern = "*",
command = [[%s/\s\+$//e]],
})
vim.g.netrw_browse_split = 0
vim.g.netrw_banner = 0
vim.g.netrw_winsize = 25

View File

@ -0,0 +1,76 @@
-- This file can be loaded by calling `lua require('plugins')` from your init.vim
-- Only required if you have packer configured as `opt`
vim.cmd.packadd('packer.nvim')
return require('packer').startup(function(use)
-- Packer can manage itself
use 'wbthomason/packer.nvim'
use {
'nvim-telescope/telescope.nvim', tag = '0.1.0',
-- or , branch = '0.1.x',
requires = { {'nvim-lua/plenary.nvim'} }
}
use({
'gruvbox-community/gruvbox',
as = 'gruvbox',
config = function()
vim.cmd('colorscheme gruvbox')
end
})
use({
"folke/trouble.nvim",
config = function()
require("trouble").setup {
icons = false,
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
}
end
})
use({"nvim-treesitter/nvim-treesitter", run = ":TSUpdate"})
use("nvim-treesitter/playground")
use("theprimeagen/harpoon")
use("theprimeagen/refactoring.nvim")
use("mbbill/undotree")
use("tpope/vim-fugitive")
use("nvim-treesitter/nvim-treesitter-context");
use {
'VonHeikemen/lsp-zero.nvim',
branch = 'v1.x',
requires = {
-- LSP Support
{'neovim/nvim-lspconfig'},
{'williamboman/mason.nvim'},
{'williamboman/mason-lspconfig.nvim'},
-- Autocompletion
{'hrsh7th/nvim-cmp'},
{'hrsh7th/cmp-buffer'},
{'hrsh7th/cmp-path'},
{'saadparwaiz1/cmp_luasnip'},
{'hrsh7th/cmp-nvim-lsp'},
{'hrsh7th/cmp-nvim-lua'},
-- Snippets
{'L3MON4D3/LuaSnip'},
{'rafamadriz/friendly-snippets'},
}
}
use("folke/zen-mode.nvim")
use("github/copilot.vim")
use("eandrju/cellular-automaton.nvim")
use("laytan/cloak.nvim")
use("terrortylor/nvim-comment")
use {'akinsho/bufferline.nvim', tag = "v3.*", requires = 'kyazdani42/nvim-web-devicons'}
end)

51
nvim/lua/serxoz/remap.lua Normal file
View File

@ -0,0 +1,51 @@
vim.g.mapleader = " "
vim.keymap.set("n", "<leader>pv", vim.cmd.Ex)
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")
vim.keymap.set("n", "J", "mzJ`z")
vim.keymap.set("n", "<C-d>", "<C-d>zz")
vim.keymap.set("n", "<C-u>", "<C-u>zz")
vim.keymap.set("n", "n", "nzzzv")
vim.keymap.set("n", "N", "Nzzzv")
vim.keymap.set("n", "<leader>vwm", function()
require("vim-with-me").StartVimWithMe()
end)
vim.keymap.set("n", "<leader>svwm", function()
require("vim-with-me").StopVimWithMe()
end)
-- greatest remap ever
vim.keymap.set("x", "<leader>p", [["_dP]])
-- next greatest remap ever : asbjornHaland
vim.keymap.set({"n", "v"}, "<leader>y", [["+y]])
vim.keymap.set("n", "<leader>Y", [["+Y]])
vim.keymap.set({"n", "v"}, "<leader>d", [["_d]])
-- This is going to get me cancelled
vim.keymap.set("i", "<C-c>", "<Esc>")
vim.keymap.set("n", "Q", "<nop>")
vim.keymap.set("n", "<C-f>", "<cmd>silent !tmux neww tmux-sessionizer<CR>")
vim.keymap.set("n", "<leader>f", vim.lsp.buf.format)
vim.keymap.set("n", "<C-k>", "<cmd>cnext<CR>zz")
vim.keymap.set("n", "<C-j>", "<cmd>cprev<CR>zz")
vim.keymap.set("n", "<leader>k", "<cmd>lnext<CR>zz")
vim.keymap.set("n", "<leader>j", "<cmd>lprev<CR>zz")
vim.keymap.set("n", "<leader>s", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]])
vim.keymap.set("n", "<leader>x", "<cmd>!chmod +x %<CR>", { silent = true })
vim.keymap.set("n", "<leader>vpp", "<cmd>e ~/.dotfiles/nvim/.config/nvim/lua/theprimeagen/packer.lua<CR>");
vim.keymap.set("n", "<leader>mr", "<cmd>CellularAutomaton make_it_rain<CR>");
vim.keymap.set("n", "<leader><leader>", function()
vim.cmd("so")
end)

32
nvim/lua/serxoz/set.lua Normal file
View File

@ -0,0 +1,32 @@
vim.opt.guicursor = ""
vim.opt.nu = true
vim.opt.relativenumber = true
vim.opt.tabstop = 4
vim.opt.softtabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
vim.opt.smartindent = true
vim.opt.wrap = false
vim.opt.swapfile = false
vim.opt.backup = false
vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir"
vim.opt.undofile = true
vim.opt.hlsearch = false
vim.opt.incsearch = true
vim.opt.termguicolors = true
vim.opt.scrolloff = 8
vim.opt.signcolumn = "yes"
vim.opt.isfname:append("@-@")
vim.opt.updatetime = 50
vim.opt.colorcolumn = "80"