Refac
This commit is contained in:
parent
a0407fd9e2
commit
e5b6b47c64
1 changed files with 87 additions and 154 deletions
241
init.lua
241
init.lua
|
|
@ -16,57 +16,37 @@ require("packer").init({
|
||||||
})
|
})
|
||||||
|
|
||||||
require("packer").startup(function(use)
|
require("packer").startup(function(use)
|
||||||
-- Packer can manage itself
|
|
||||||
use("wbthomason/packer.nvim")
|
use("wbthomason/packer.nvim")
|
||||||
|
|
||||||
use("lewis6991/fileline.nvim")
|
use("lewis6991/fileline.nvim")
|
||||||
|
use("mfussenegger/nvim-dap")
|
||||||
use {
|
use({
|
||||||
'stevearc/stickybuf.nvim',
|
"stevearc/stickybuf.nvim",
|
||||||
config = function() require('stickybuf').setup() end
|
config = function()
|
||||||
}
|
require("stickybuf").setup()
|
||||||
|
end,
|
||||||
-- use {"akinsho/toggleterm.nvim", tag = '*', config = function()
|
})
|
||||||
-- require("toggleterm").setup()
|
use("famiu/bufdelete.nvim")
|
||||||
-- end}
|
|
||||||
|
|
||||||
use 'famiu/bufdelete.nvim'
|
|
||||||
|
|
||||||
use("neovim/nvim-lspconfig")
|
use("neovim/nvim-lspconfig")
|
||||||
use('jose-elias-alvarez/null-ls.nvim')
|
use("jose-elias-alvarez/null-ls.nvim")
|
||||||
|
use({ "TimUntersberger/neogit", requires = "nvim-lua/plenary.nvim" })
|
||||||
use { 'TimUntersberger/neogit', requires = 'nvim-lua/plenary.nvim' }
|
|
||||||
|
|
||||||
use("tiagovla/scope.nvim")
|
use("tiagovla/scope.nvim")
|
||||||
|
|
||||||
use({
|
use({
|
||||||
"folke/which-key.nvim",
|
"folke/which-key.nvim",
|
||||||
config = function()
|
config = function()
|
||||||
vim.o.timeout = true
|
vim.o.timeout = true
|
||||||
vim.o.timeoutlen = 300
|
vim.o.timeoutlen = 300
|
||||||
require("which-key").setup({
|
require("which-key").setup({})
|
||||||
-- your configuration comes here
|
|
||||||
-- or leave it empty to use the default settings
|
|
||||||
-- refer to the configuration section below
|
|
||||||
})
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
use({
|
use({
|
||||||
"folke/trouble.nvim",
|
"folke/trouble.nvim",
|
||||||
requires = "nvim-tree/nvim-web-devicons",
|
requires = "nvim-tree/nvim-web-devicons",
|
||||||
config = function()
|
config = function()
|
||||||
require("trouble").setup({
|
require("trouble").setup({
|
||||||
auto_open = true
|
auto_open = true,
|
||||||
-- your configuration comes here
|
|
||||||
-- or leave it empty to use the default settings
|
|
||||||
-- refer to the configuration section below
|
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Collection of common configurations for the Nvim LSP client
|
|
||||||
-- Visualize lsp progress
|
|
||||||
use({
|
use({
|
||||||
"j-hui/fidget.nvim",
|
"j-hui/fidget.nvim",
|
||||||
config = function()
|
config = function()
|
||||||
|
|
@ -75,9 +55,7 @@ require("packer").startup(function(use)
|
||||||
})
|
})
|
||||||
use("terrortylor/nvim-comment")
|
use("terrortylor/nvim-comment")
|
||||||
use({ "akinsho/bufferline.nvim", tag = "*", requires = "nvim-tree/nvim-web-devicons" })
|
use({ "akinsho/bufferline.nvim", tag = "*", requires = "nvim-tree/nvim-web-devicons" })
|
||||||
|
|
||||||
use("petertriho/nvim-scrollbar")
|
use("petertriho/nvim-scrollbar")
|
||||||
|
|
||||||
use({
|
use({
|
||||||
"nvim-tree/nvim-tree.lua",
|
"nvim-tree/nvim-tree.lua",
|
||||||
requires = {
|
requires = {
|
||||||
|
|
@ -87,34 +65,21 @@ require("packer").startup(function(use)
|
||||||
require("nvim-tree").setup({})
|
require("nvim-tree").setup({})
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Autocompletion framework
|
|
||||||
use("hrsh7th/nvim-cmp")
|
use("hrsh7th/nvim-cmp")
|
||||||
use({
|
use({
|
||||||
-- cmp LSP completion
|
|
||||||
"hrsh7th/cmp-nvim-lsp",
|
"hrsh7th/cmp-nvim-lsp",
|
||||||
"hrsh7th/cmp-nvim-lsp-signature-help",
|
"hrsh7th/cmp-nvim-lsp-signature-help",
|
||||||
|
|
||||||
-- cmp Snippet completion
|
|
||||||
"hrsh7th/cmp-vsnip",
|
"hrsh7th/cmp-vsnip",
|
||||||
-- cmp Path completion
|
|
||||||
"hrsh7th/cmp-path",
|
"hrsh7th/cmp-path",
|
||||||
"hrsh7th/cmp-buffer",
|
"hrsh7th/cmp-buffer",
|
||||||
after = { "hrsh7th/nvim-cmp" },
|
after = { "hrsh7th/nvim-cmp" },
|
||||||
requires = { "hrsh7th/nvim-cmp" },
|
requires = { "hrsh7th/nvim-cmp" },
|
||||||
})
|
})
|
||||||
-- See hrsh7th other plugins for more great completion sources!
|
|
||||||
-- Snippet engine
|
|
||||||
use("hrsh7th/vim-vsnip")
|
use("hrsh7th/vim-vsnip")
|
||||||
-- Adds extra functionality over rust analyzer
|
|
||||||
use("simrat39/rust-tools.nvim")
|
use("simrat39/rust-tools.nvim")
|
||||||
|
|
||||||
-- Optional
|
|
||||||
use("nvim-lua/popup.nvim")
|
use("nvim-lua/popup.nvim")
|
||||||
use("nvim-lua/plenary.nvim")
|
use("nvim-lua/plenary.nvim")
|
||||||
use("nvim-telescope/telescope.nvim")
|
use("nvim-telescope/telescope.nvim")
|
||||||
|
|
||||||
-- Some color scheme other then default
|
|
||||||
use({ "ellisonleao/gruvbox.nvim" })
|
use({ "ellisonleao/gruvbox.nvim" })
|
||||||
use("rebelot/kanagawa.nvim")
|
use("rebelot/kanagawa.nvim")
|
||||||
end)
|
end)
|
||||||
|
|
@ -125,27 +90,20 @@ if packer_bootstrap then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.o.background = "dark" -- or "light" for light mode
|
|
||||||
vim.cmd([[colorscheme kanagawa]])
|
|
||||||
|
|
||||||
-- Set completeopt to have a better completion experience
|
|
||||||
-- :help completeopt
|
|
||||||
-- menuone: popup even when there's only one match
|
|
||||||
-- noinsert: Do not insert text until a selection is made
|
|
||||||
-- noselect: Do not auto-select, nvim-cmp plugin will handle this for us.
|
|
||||||
vim.o.completeopt = "menuone,noinsert,noselect"
|
|
||||||
|
|
||||||
-- Avoid showing extra messages when using completion
|
|
||||||
vim.opt.shortmess = vim.opt.shortmess + "c"
|
|
||||||
|
|
||||||
local function on_attach(client, buffer)
|
local function on_attach(client, buffer)
|
||||||
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
if client.supports_method("textDocument/formatting") then
|
||||||
buffer = buffer,
|
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
||||||
callback = function()
|
buffer = buffer,
|
||||||
vim.lsp.buf.format()
|
callback = function()
|
||||||
|
vim.lsp.buf.format({
|
||||||
end,
|
async = false,
|
||||||
})
|
filter = function(client)
|
||||||
|
return client.name ~= "tsserver"
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
local keymap_opts = { buffer = buffer }
|
local keymap_opts = { buffer = buffer }
|
||||||
-- Code navigation and shortcuts
|
-- Code navigation and shortcuts
|
||||||
|
|
@ -175,16 +133,10 @@ local function on_attach(client, buffer)
|
||||||
vim.keymap.set("n", "g]", vim.diagnostic.goto_next, keymap_opts)
|
vim.keymap.set("n", "g]", vim.diagnostic.goto_next, keymap_opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.keymap.set("n", "<c-c>", function()
|
|
||||||
if vim.bo.buftype ~= "nofile" and vim.bo.buftype ~= "terminal" then
|
|
||||||
require('bufdelete').bufdelete(0, false)
|
|
||||||
end
|
|
||||||
end, keymap_opts)
|
|
||||||
|
|
||||||
-- Configure LSP through rust-tools.nvim plugin.
|
-- Configure LSP through rust-tools.nvim plugin.
|
||||||
-- rust-tools will configure and enable certain LSP features for us.
|
-- rust-tools will configure and enable certain LSP features for us.
|
||||||
-- See https://github.com/simrat39/rust-tools.nvim#configuration
|
-- See https://github.com/simrat39/rust-tools.nvim#configuration
|
||||||
local opts = {
|
require("rust-tools").setup({
|
||||||
tools = {
|
tools = {
|
||||||
runnables = {
|
runnables = {
|
||||||
use_telescope = true,
|
use_telescope = true,
|
||||||
|
|
@ -214,9 +166,7 @@ local opts = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
require("rust-tools").setup(opts)
|
|
||||||
|
|
||||||
-- Setup Completion
|
-- Setup Completion
|
||||||
-- See https://github.com/hrsh7th/nvim-cmp#basic-configuration
|
-- See https://github.com/hrsh7th/nvim-cmp#basic-configuration
|
||||||
|
|
@ -253,44 +203,43 @@ cmp.setup({
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- have a fixed column for the diagnostics to appear in
|
|
||||||
-- this removes the jitter when warnings/errors flow in
|
|
||||||
vim.wo.signcolumn = "yes"
|
|
||||||
|
|
||||||
-- " Set updatetime for CursorHold
|
|
||||||
-- " 300ms of no cursor movement to trigger CursorHold
|
|
||||||
-- set updatetime=300
|
|
||||||
vim.opt.updatetime = 100
|
|
||||||
|
|
||||||
local function open_nvim_tree(data)
|
local function open_nvim_tree(data)
|
||||||
|
-- buffer is a directory
|
||||||
|
local directory = vim.fn.isdirectory(data.file) == 1
|
||||||
|
|
||||||
-- buffer is a directory
|
if not directory then
|
||||||
local directory = vim.fn.isdirectory(data.file) == 1
|
return
|
||||||
|
end
|
||||||
|
-- change to the directory
|
||||||
|
vim.cmd.cd(data.file)
|
||||||
|
|
||||||
if not directory then
|
-- open the tree
|
||||||
return
|
require("nvim-tree.api").tree.open()
|
||||||
end
|
|
||||||
|
|
||||||
-- change to the directory
|
|
||||||
vim.cmd.cd(data.file)
|
|
||||||
|
|
||||||
-- open the tree
|
|
||||||
require("nvim-tree.api").tree.open()
|
|
||||||
end
|
end
|
||||||
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
|
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
|
||||||
|
|
||||||
|
-- Comments
|
||||||
require("nvim_comment").setup()
|
require("nvim_comment").setup()
|
||||||
|
|
||||||
|
-- Buffer line
|
||||||
require("bufferline").setup({
|
require("bufferline").setup({
|
||||||
options = {
|
options = {
|
||||||
close_command = function (bufnum)
|
close_command = function(bufnum)
|
||||||
require('bufdelete').bufdelete(bufnum)
|
require("bufdelete").bufdelete(bufnum)
|
||||||
end
|
end,
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Scrollbar
|
||||||
require("scrollbar").setup()
|
require("scrollbar").setup()
|
||||||
|
|
||||||
vim.g.mapleader = ","
|
-- Scope
|
||||||
|
require("scope").setup({
|
||||||
|
restore_state = false,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Keybinds
|
||||||
|
vim.keymap.set("n", "<leader><leader>", ":luafile $MYVIMRC<CR>", {}) -- reload nvim config
|
||||||
local builtin = require("telescope.builtin")
|
local builtin = require("telescope.builtin")
|
||||||
vim.keymap.set("n", "<c-p>", builtin.find_files, {})
|
vim.keymap.set("n", "<c-p>", builtin.find_files, {})
|
||||||
vim.keymap.set("n", "<leader>ff", builtin.find_files, {})
|
vim.keymap.set("n", "<leader>ff", builtin.find_files, {})
|
||||||
|
|
@ -300,61 +249,45 @@ vim.keymap.set("n", "<leader>fh", builtin.help_tags, {})
|
||||||
vim.keymap.set("n", "<leader>t", require("nvim-tree.api").tree.toggle, {})
|
vim.keymap.set("n", "<leader>t", require("nvim-tree.api").tree.toggle, {})
|
||||||
vim.keymap.set("n", "<leader>g", require("neogit").open, {})
|
vim.keymap.set("n", "<leader>g", require("neogit").open, {})
|
||||||
vim.keymap.set("n", "<leader>tr", vim.diagnostic.reset, {})
|
vim.keymap.set("n", "<leader>tr", vim.diagnostic.reset, {})
|
||||||
|
vim.keymap.set("n", "<c-c>", function()
|
||||||
vim.wo.number = true
|
if vim.bo.buftype ~= "nofile" and vim.bo.buftype ~= "terminal" then
|
||||||
|
require("bufdelete").bufdelete(0, false)
|
||||||
vim.keymap.set("n", "<leader><leader>", ":luafile $MYVIMRC<CR>", {})
|
|
||||||
|
|
||||||
require("scope").setup({
|
|
||||||
restore_state = false, -- experimental
|
|
||||||
})
|
|
||||||
|
|
||||||
require'lspconfig'.tsserver.setup {}
|
|
||||||
require'lspconfig'.ruby_ls.setup {
|
|
||||||
cmd = { 'bundle', 'exec', 'ruby-lsp' },
|
|
||||||
on_attach = function(client,bufnr)
|
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
||||||
group = augroup,
|
|
||||||
buffer = bufnr,
|
|
||||||
callback = function()
|
|
||||||
vim.lsp.buf.format {
|
|
||||||
async = false,
|
|
||||||
}
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
}
|
end, keymap_opts)
|
||||||
require'lspconfig'.solargraph.setup{
|
|
||||||
|
-- LSP Config
|
||||||
|
require("lspconfig").tsserver.setup({})
|
||||||
|
require("lspconfig").ruby_ls.setup({
|
||||||
|
cmd = { "bundle", "exec", "ruby-lsp" },
|
||||||
|
on_attach = on_attach,
|
||||||
|
})
|
||||||
|
require("lspconfig").solargraph.setup({
|
||||||
cmd = { "bundle", "exec", "solargraph", "stdio" },
|
cmd = { "bundle", "exec", "solargraph", "stdio" },
|
||||||
on_attach = on_attach
|
on_attach = on_attach,
|
||||||
}
|
})
|
||||||
|
|
||||||
local null_ls = require("null-ls")
|
local null_ls = require("null-ls")
|
||||||
|
|
||||||
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
|
||||||
null_ls.setup({
|
null_ls.setup({
|
||||||
sources = {
|
sources = {
|
||||||
null_ls.builtins.formatting.prettierd,
|
null_ls.builtins.formatting.prettierd,
|
||||||
null_ls.builtins.formatting.rubocop
|
null_ls.builtins.formatting.rubocop,
|
||||||
},
|
null_ls.builtins.formatting.stylua,
|
||||||
-- you can reuse a shared lspconfig on_attach callback here
|
},
|
||||||
on_attach = function(client, bufnr)
|
on_attach = on_attach,
|
||||||
if client.supports_method("textDocument/formatting") then
|
|
||||||
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
||||||
group = augroup,
|
|
||||||
buffer = bufnr,
|
|
||||||
callback = function()
|
|
||||||
-- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead
|
|
||||||
-- on later neovim version, you should use vim.lsp.buf.format({ async = false }) instead
|
|
||||||
vim.lsp.buf.format {
|
|
||||||
async = false,
|
|
||||||
filter = function(client) return client.name ~= "tsserver" end
|
|
||||||
}
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Vim options
|
||||||
|
vim.wo.number = true
|
||||||
vim.o.wrap = false
|
vim.o.wrap = false
|
||||||
|
vim.g.mapleader = ","
|
||||||
|
vim.wo.signcolumn = "yes" -- prevents jitter
|
||||||
|
vim.opt.updatetime = 100
|
||||||
|
vim.o.background = "dark" -- or "light" for light mode
|
||||||
|
vim.cmd([[colorscheme kanagawa]])
|
||||||
|
-- Set completeopt to have a better completion experience
|
||||||
|
-- :help completeopt
|
||||||
|
-- menuone: popup even when there's only one match
|
||||||
|
-- noinsert: Do not insert text until a selection is made
|
||||||
|
-- noselect: Do not auto-select, nvim-cmp plugin will handle this for us.
|
||||||
|
vim.o.completeopt = "menuone,noinsert,noselect"
|
||||||
|
-- Avoid showing extra messages when using completion
|
||||||
|
vim.opt.shortmess = vim.opt.shortmess + "c"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue