Skip to content

Instantly share code, notes, and snippets.

@idoleat
Last active November 10, 2022 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idoleat/d8f9392845b63ef96e981297362afc0c to your computer and use it in GitHub Desktop.
Save idoleat/d8f9392845b63ef96e981297362afc0c to your computer and use it in GitHub Desktop.
Change init.vim to init.lua
vim.cmd("set encoding=UTF-8")
vim.cmd("set number")
vim.cmd("set ruler")
vim.cmd("set visualbell")
vim.cmd("set wrap")
vim.cmd("set tabstop=4")
vim.cmd("set shiftwidth=4")
vim.cmd("set expandtab")
-- make sure the packer plugin manager is installed
local ensure_packer = function()
local fn = vim.fn
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path })
vim.cmd([[packadd packer.nvim]])
return true
end
return false
end
local packer_bootstrap = ensure_packer()
require("packer").startup(function(use)
-- Packer can manage itself
use("wbthomason/packer.nvim")
-- Collection of common configurations for the Nvim LSP client
use("neovim/nvim-lspconfig")
-- Visualize lsp progress
use({
"j-hui/fidget.nvim",
config = function()
require("fidget").setup()
end
})
-- Autocompletion framework
use("hrsh7th/nvim-cmp")
use({
-- cmp LSP completion
"hrsh7th/cmp-nvim-lsp",
-- cmp Snippet completion
"hrsh7th/cmp-vsnip",
-- cmp Path completion
"hrsh7th/cmp-path",
"hrsh7th/cmp-buffer",
after = { "hrsh7th/nvim-cmp" },
requires = { "hrsh7th/nvim-cmp" },
})
-- See hrsh7th other plugins for more great completion sources!
-- Snippet engine
use('hrsh7th/vim-vsnip')
-- Adds extra functionality over rust analyzer
use("simrat39/rust-tools.nvim")
-- Optional
use("nvim-lua/popup.nvim")
use("nvim-lua/plenary.nvim")
use("nvim-telescope/telescope.nvim")
-- Some color scheme other then default
use("sainnhe/gruvbox-material")
-- lualine
use {
'nvim-lualine/lualine.nvim',
requires = { 'kyazdani42/nvim-web-devicons', opt = true }
}
-- lua-tree
use {
'nvim-tree/nvim-tree.lua',
requires = {
'nvim-tree/nvim-web-devicons', -- optional, for file icons
}
}
end)
-- the first run will install packer and our plugins
if packer_bootstrap then
require("packer").sync()
return
end
vim.api.nvim_command('colorscheme gruvbox-material')
require('lualine').setup {
options = { theme = 'gruvbox-material' },
}
-- disable netrw at the very start of your init.lua (strongly advised)
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
-- set termguicolors to enable highlight groups
vim.opt.termguicolors = true
-- OR setup with some options
require("nvim-tree").setup({
respect_buf_cwd = true,
update_focused_file = {
enable = true,
update_root = true
},
open_on_setup = true,
open_on_setup_file = true,
open_on_tab = false,
view = {
side = "left",
width = 30,
auto_resize = true
},
sort_by = "case_sensitive",
view = {
adaptive_size = true,
mappings = {
list = {
{ key = "u", action = "dir_up" },
},
},
},
renderer = {
group_empty = true,
},
filters = {
dotfiles = false,
},
})
-- require("nvim-tree").toggle(false, true, vim.api.nvim_buf_get_name(0))
-- close if it's the last one
--vim.api.nvim_create_autocmd("BufEnter", {
-- nested = true,
-- callback = function()
-- if #vim.api.nvim_list_wins() == 1 and vim.api.nvim_buf_get_name(0):match("NvimTree_") ~= nil then
-- vim.cmd "quit"
-- end
-- end
--})
-- 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)
-- This callback is called when the LSP is atttached/enabled for this buffer
-- we could set keymaps related to LSP, etc here.
end
-- Configure LSP through rust-tools.nvim plugin.
-- rust-tools will configure and enable certain LSP features for us.
-- See https://github.com/simrat39/rust-tools.nvim#configuration
local opts = {
tools = {
runnables = {
use_telescope = true,
},
inlay_hints = {
auto = true,
show_parameter_hints = false,
parameter_hints_prefix = "",
other_hints_prefix = "",
},
},
-- all the opts to send to nvim-lspconfig
-- these override the defaults set by rust-tools.nvim
-- see https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer
server = {
-- on_attach is a callback called when the language server attachs to the buffer
on_attach = on_attach,
settings = {
-- to enable rust-analyzer settings visit:
-- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
["rust-analyzer"] = {
-- enable clippy on save
checkOnSave = {
command = "clippy",
},
},
},
},
}
require("rust-tools").setup(opts)
-- Setup Completion
-- See https://github.com/hrsh7th/nvim-cmp#basic-configuration
local cmp = require("cmp")
cmp.setup({
preselect = cmp.PreselectMode.None,
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
["<C-p>"] = cmp.mapping.select_prev_item(),
["<C-n>"] = cmp.mapping.select_next_item(),
-- Add tab support
["<S-Tab>"] = cmp.mapping.select_prev_item(),
["<Tab>"] = cmp.mapping.select_next_item(),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true,
}),
},
-- Installed sources
sources = {
{ name = "nvim_lsp" },
{ name = "vsnip" },
{ name = "path" },
{ name = "buffer" },
},
})
local keymap_opts = { buffer = buffer }
-- Code navigation and shortcuts
vim.keymap.set("n", "<c-]>", vim.lsp.buf.definition, keymap_opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, keymap_opts)
vim.keymap.set("n", "gD", vim.lsp.buf.implementation, keymap_opts)
vim.keymap.set("n", "<c-k>", vim.lsp.buf.signature_help, keymap_opts)
vim.keymap.set("n", "1gD", vim.lsp.buf.type_definition, keymap_opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, keymap_opts)
vim.keymap.set("n", "g0", vim.lsp.buf.document_symbol, keymap_opts)
vim.keymap.set("n", "gW", vim.lsp.buf.workspace_symbol, keymap_opts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, keymap_opts)
-- Set updatetime for CursorHold
-- 300ms of no cursor movement to trigger CursorHold
vim.opt.updatetime = 100
-- Show diagnostic popup on cursor hover
local diag_float_grp = vim.api.nvim_create_augroup("DiagnosticFloat", { clear = true })
vim.api.nvim_create_autocmd("CursorHold", {
callback = function()
vim.diagnostic.open_float(nil, { focusable = false })
end,
group = diag_float_grp,
})
-- Goto previous/next diagnostic warning/error
vim.keymap.set("n", "g[", vim.diagnostic.goto_prev, keymap_opts)
vim.keymap.set("n", "g]", vim.diagnostic.goto_next, keymap_opts)
-- have a fixed column for the diagnostics to appear in
-- this removes the jitter when warnings/errors flow in
vim.wo.signcolumn = "yes"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment