dotfiles/init.lua

334 lines
10 KiB
Lua
Raw Normal View History

2024-02-21 23:47:12 +08:00
vim.cmd("set expandtab")
vim.cmd("set tabstop=4")
vim.cmd("set softtabstop=4")
vim.cmd("set shiftwidth=4")
vim.cmd("set splitright")
vim.cmd("set splitbelow")
vim.cmd("set selectmode=key")
vim.cmd("set keymodel=startsel")
vim.cmd("set number")
vim.cmd("set cursorline")
vim.cmd("set termguicolors")
2024-02-22 00:13:31 +08:00
vim.cmd("set clipboard+=unnamedplus")
2024-02-21 23:47:12 +08:00
vim.g.mapleader = " "
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)
local plugins = {
{"loctvl842/monokai-pro.nvim", name="monokai", priority=1000},
{
'nvim-telescope/telescope.nvim', tag = '0.1.5',
dependencies = { 'nvim-lua/plenary.nvim' }
},
{"nvim-treesitter/nvim-treesitter", build = ":TSUpdate"},
{
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons", -- not strictly required, but recommended
"MunifTanjim/nui.nvim",
"3rd/image.nvim"
}
},
{
'neovim/nvim-lspconfig',
dependencies = {
-- Automatically install LSPs to stdpath for neovim
{'williamboman/mason.nvim', config = true},
'williamboman/mason-lspconfig.nvim',
-- Useful status updates for LSP
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
{ 'j-hui/fidget.nvim', tag = 'legacy', opts = {} },
-- Additional lua configuration, makes nvim stuff amazing!
'folke/neodev.nvim',
},
},
{
"hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-emoji",
},
},
{
'romgrk/barbar.nvim',
dependencies = {
'lewis6991/gitsigns.nvim', -- OPTIONAL: for git status
'nvim-tree/nvim-web-devicons', -- OPTIONAL: for file icons
},
init = function() vim.g.barbar_auto_setup = false end,
opts = {
-- lazy.nvim will automatically call setup for you. put your options here, anything missing will use the default:
-- animation = true,
-- insert_at_start = true,
-- …etc.
},
version = '^1.0.0', -- optional: only update when a new 1.x version is released
},
{ 'lvimuser/lsp-inlayhints.nvim' },
{
"ray-x/lsp_signature.nvim",
event = "VeryLazy",
opts = {},
config = function(_, opts) require'lsp_signature'.setup(opts) end
},
{
"folke/which-key.nvim",
event = "VeryLazy",
init = function()
vim.o.timeout = true
vim.o.timeoutlen = 300
end,
opts = {
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
}
},
{ 'jdhao/better-escape.vim' },
{
'Pocco81/auto-save.nvim',
opts = {
enabled = true,
}
},
{
'stevearc/overseer.nvim',
opts = {},
},
{
"windwp/nvim-autopairs",
event = "InsertEnter",
opts = {}
},
{
"dhruvasagar/vim-prosession",
dependencies = {
"tpope/vim-obsession",
},
},
{
"arsham/arshamiser.nvim",
dependencies = {
"arsham/arshlib.nvim",
"famiu/feline.nvim",
"rebelot/heirline.nvim",
"kyazdani42/nvim-web-devicons",
},
config = function()
-- ignore any parts you don't want to use
vim.cmd.colorscheme("arshamiser_light")
require("arshamiser.feliniser")
-- or:
-- require("arshamiser.heirliniser")
_G.custom_foldtext = require("arshamiser.folding").foldtext
vim.opt.foldtext = "v:lua.custom_foldtext()"
-- if you want to draw a tabline:
vim.api.nvim_set_option("tabline", [[%{%v:lua.require("arshamiser.tabline").draw()%}]])
end,
}
}
local opts = {
}
require("lazy").setup(plugins, opts)
require("monokai-pro").setup({
transparent_background = true,
terminal_colors = true,
devicons = true, -- highlight the icons of `nvim-web-devicons`
styles = {
comment = { italic = true },
keyword = { italic = true }, -- any other keyword
type = { italic = true }, -- (preferred) int, long, char, etc
storageclass = { italic = true }, -- static, register, volatile, etc
structure = { italic = true }, -- struct, union, enum, etc
parameter = { italic = true }, -- parameter pass in function
annotation = { italic = true },
tag_attribute = { italic = true }, -- attribute of tag in reactjs
},
filter = "spectrum", -- classic | octagon | pro | machine | ristretto | spectrum
-- Enable this will disable filter option
day_night = {
enable = false, -- turn off by default
day_filter = "pro", -- classic | octagon | pro | machine | ristretto | spectrum
night_filter = "spectrum", -- classic | octagon | pro | machine | ristretto | spectrum
},
inc_search = "background", -- underline | background
background_clear = {
-- "float_win",
"toggleterm",
-- "telescope",
-- "which-key",
"renamer",
"notify",
-- "nvim-tree",
-- "neo-tree",
-- "bufferline", -- better used if background of `neo-tree` or `nvim-tree` is cleared
},-- "float_win", "toggleterm", "telescope", "which-key", "renamer", "neo-tree", "nvim-tree", "bufferline"
plugins = {
bufferline = {
underline_selected = false,
underline_visible = false,
},
indent_blankline = {
context_highlight = "default", -- default | pro
context_start_underline = false,
},
},
})
vim.cmd([[colorscheme monokai-pro]])
local builtin = require("telescope.builtin")
vim.keymap.set('n', '<C-p>', builtin.find_files, {})
vim.keymap.set('n', '<leader>g', builtin.live_grep, {})
local config = require("nvim-treesitter.configs")
config.setup({
ensure_installed = {"lua", "cpp", "rust", "javascript", "python"},
auto_install = true,
highlight = { enable = true},
indent = { enable = true},
})
vim.keymap.set('n', '<leader>f', ':Neotree . toggle left<CR>', {})
-- import nvim-cmp plugin safely
local cmp_status, cmp = pcall(require, "cmp")
if not cmp_status then
return
end
-- import luasnip plugin safely
local luasnip_status, luasnip = pcall(require, "luasnip")
if not luasnip_status then
return
end
vim.opt.completeopt = "menu,menuone,noselect"
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-k>"] = cmp.mapping.select_prev_item(), -- previous suggestion
["<C-j>"] = cmp.mapping.select_next_item(), -- next suggestion
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(), -- show completion suggestions
["<C-e>"] = cmp.mapping.abort(), -- close completion window
["<tab>"] = cmp.mapping.confirm({ select = true }),
}),
-- sources for autocompletion
sources = cmp.config.sources({
{ name = "nvim_lsp" }, -- LSP
{ name = "luasnip" }, -- snippets
{ name = "buffer" }, -- text within the current buffer
{ name = "path" }, -- file system paths
}),
})
-- Setup language servers.
local lspconfig = require('lspconfig')
2024-02-22 00:13:31 +08:00
lspconfig.clangd.setup {
cmd = {
"clangd",
"--header-insertion=never"
}
}
2024-02-21 23:47:12 +08:00
lspconfig.pyright.setup {}
lspconfig.tsserver.setup {}
lspconfig.rust_analyzer.setup {
-- Server-specific settings. See `:help lspconfig-setup`
settings = {
['rust-analyzer'] = {},
},
}
-- Global mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
end,
})
require("lsp-inlayhints").setup()
require("lsp_signature").setup({})
vim.keymap.set('n', '<C-z>', ':u<CR>')
vim.keymap.set('i', '<C-z>', '<ESC>:u<CR>i')
vim.keymap.set('i', '<C-c>', '<ESC>yyi')
vim.keymap.set('i', '<C-v>', '<ESC>PA')
vim.keymap.set('i', '<C-x>', '<ESC>ddi')
vim.keymap.set('i', '<C-a>', '<ESC>ggVG')
vim.keymap.set('n', '<leader>`', ':split<CR>:terminal<CR>i')
vim.keymap.set('n', '<leader>l', ':vsplit std.in<CR>:split std.out<CR>')
vim.keymap.set('n', '<leader>n', ':tabnew')
require("overseer").setup({
templates = { "builtin", "user.cpp_cp" },
})
vim.api.nvim_create_autocmd("FileType", {
pattern = "cpp",
callback = function()
vim.api.nvim_buf_set_keymap(0, 'n', "<leader>b", ":vsplit<CR>:te g++ -std=c++17 -Wall -Ofast -fsanitize=address % && ./a.out < std.in > std.out<CR>i", {
silent = true,
noremap = true
})
end,
})