Skip to content

Instantly share code, notes, and snippets.

@scull7
Last active March 2, 2023 03:13
Show Gist options
  • Save scull7/d2c493339aa7833eefca2f8c2d3a8d81 to your computer and use it in GitHub Desktop.
Save scull7/d2c493339aa7833eefca2f8c2d3a8d81 to your computer and use it in GitHub Desktop.
Neovim configuration
-- https://github.com/mhartington/formatter.nvim#format-on-save
vim.api.nvim_exec([[
augroup FormatAutogroup
autocmd!
autocmd BufWritePost *.js,*.mjs,*.rs,*.lua,*.elm FormatWrite
augroup END
]], true)
require('formatter').setup({
filetype = {
dhall = {
-- brew install dhall
function()
return {
exe = "dhall format",
args = {},
stdin = true
}
end
},
elm = {
-- prettier
function()
return {
exe = "elm-format",
args = { "--stdin" },
stdin = true
}
end
},
html = {
-- prettier
function()
return {
exe = "prettier",
args = {"--stdin-filepath", vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)), '--double-quote'},
stdin = true
}
end
},
javascript = {
-- prettier
function()
return {
exe = "prettier",
args = {"--stdin-filepath", vim.fn.fnameescape(vim.api.nvim_buf_get_name(0))},
stdin = true
}
end
},
json = {
-- prettier
function()
return {
exe = "prettier",
args = {"--stdin-filepath", vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)), '--double-quote'},
stdin = true
}
end
},
rust = {
-- Rustfmt
function()
return {
exe = "rustfmt",
args = {"--emit=stdout", "--edition=2021"},
stdin = true
}
end
},
typescript = {
-- prettier
function()
return {
exe = "prettier",
args = {"--stdin-filepath", vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)), '--single-quote'},
stdin = true
}
end
},
typescriptreact = {
-- prettier
function()
return {
exe = "prettier",
args = {"--stdin-filepath", vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)), '--single-quote'},
stdin = true
}
end
}
}
})
local lsp = require('lsp-zero')
lsp.preset('recommended')
lsp.ensure_installed({
'tsserver',
'eslint',
'sumneko_lua',
})
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(),
})
lsp.nvim_workspace()
lsp.setup_nvim_cmp({
mapping = cmp_mappings
})
lsp.on_attach(function(client, bufnr)
local opts = { buffer = bufnr, remap = false }
if client.name == "eslint" then
vim.cmd.LspStop('eslint')
return
end
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "<leader>vws", vim.lsp.buf.workspace_symbol, opts)
vim.keymap.set("n", "<leader>vd", vim.diagnostic.open_float, opts)
vim.keymap.set("n", "[d", vim.diagnostic.goto_next, opts)
vim.keymap.set("n", "]d", vim.diagnostic.goto_prev, opts)
vim.keymap.set("n", "<leader>vca", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "<leader>vrr", vim.lsp.buf.references, opts)
vim.keymap.set("i", "<C-h>", vim.lsp.buf.signature_help, opts)
end)
lsp.setup()
vim.diagnostic.config({
virtual_text = true
})
-- Automatically reload packer when plugins.lua is updated
vim.cmd([[
augroup packer_user_config
autocmd!
autocmd BufWritePost plugins.lua source <afile> | PackerSync
augroup end
]])
-- Use a protected call so we don't error out on first use
local status_ok, packer = pcall(require, 'packer')
if not status_ok then
return
end
-- Have packaer use a popup window
packer.init({
display = {
open_fn = function()
return require('packer.util').float({ border = 'rounded' })
end
}
})
return require('packer').startup(function(use)
-- Local plugins go here
use 'wbthomason/packer.nvim' -- packer manages itself
use 'nvim-lua/popup.nvim' -- An implementation of the pop-up API from vim to Neovim
use 'nvim-lua/plenary.nvim' -- Useful lua functions used by lots of plugins
-- Git
use {
'lewis6991/gitsigns.nvim',
requires = {
'nvim-lua/plenary.nvim'
},
-- tag = 'release' -- to use the latest release
config = function()
require('gitsigns').setup()
end
}
-- default Dracula config complains without this installed
use {
'TimUntersberger/neogit',
requires = {
'nvim-lua/plenary.nvim'
},
config = function()
require('neogit').setup()
end
}
-- Telescope (fuzzy finder)
use {
'nvim-telescope/telescope.nvim',
requires = {
'nvim-lua/plenary.nvim'
},
}
-- Treesitter
use {
'nvim-treesitter/nvim-treesitter',
run = ':TSUpdate',
}
-- Code Formatter
use {
'mhartington/formatter.nvim',
}
-- LSP Zero
use {
'VonHeikemen/lsp-zero.nvim',
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'},
}
}
-- Status Line
use {
'nvim-lualine/lualine.nvim',
requires = {
'kyazdani42/nvim-web-devicons',
opt = true
}
}
-- Color schemes
use 'Mofiqul/dracula.nvim'
use 'EdenEast/nightfox.nvim'
use 'folke/tokyonight.nvim'
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment