You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dotfiles/nvim/init.lua

483 lines
15 KiB

-- some basic options
local vim = vim
2 years ago
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.softtabstop = 2
vim.opt.expandtab = true
vim.opt.termguicolors = true
2 years ago
vim.opt.autoindent = true
vim.opt.smartindent = true
2 years ago
vim.opt.smarttab = true
vim.opt.number = true
vim.o.hidden = true
vim.o.signcolumn = 'auto'
2 years ago
vim.o.breakindent = true
vim.o.smarttab = true
2 years ago
vim.o.errorbells = true
vim.o.clipboard = "unnamedplus"
vim.g.noswapfile = true
vim.cmd [[set mouse=a]] -- enable mouse
vim.wo.cursorline = true
2 years ago
vim.opt.hlsearch = false
vim.opt.wrap = true
vim.opt.showmatch = true
vim.opt.completeopt = { 'menu', 'menuone', 'noselect', 'noinsert' }
vim.opt.shortmess = vim.opt.shortmess + "c"
2 years ago
1 year ago
vim.g.python3_host_prog = '/home/frosty/.dotfiles/nvim/env/bin/python'
2 years ago
vim.api.nvim_create_user_command('W', 'write', {})
vim.opt.foldmethod = "expr"
vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
-- hit zc to enable folding
vim.o.foldenable = false
2 years ago
vim.g.neomake_open_list = 2
function map(mode, shortcut, command)
2 years ago
vim.api.nvim_set_keymap(mode, shortcut, command, { noremap = true, silent = true })
end
-- normal mode map
function nmap(shortcut, command)
2 years ago
map('n', shortcut, command)
end
-- insert mode map
function imap(shortcut, command)
2 years ago
map('i', shortcut, command)
end
vim.opt.guifont = "Hack Nerd Font:h12"
1 year ago
if vim.g.neovide then
vim.g.neovide_refresh_rate = 140
-- change to whatever font you prefer
-- can check font with fc-cache on linux
vim.g.neovide_hide_mouse_when_typing = true
vim.g.neovide_refresh_rate_idle = 140
vim.g.neovide_scale_factor = 1.0
1 year ago
-- zoom with CTRL - and CTRL +
local change_scale_factor = function(delta)
vim.g.neovide_scale_factor = vim.g.neovide_scale_factor * delta
end
vim.keymap.set("n", "<C-=>", function()
change_scale_factor(1.25)
end)
vim.keymap.set("n", "<C-->", function()
change_scale_factor(1 / 1.25)
end)
end
1 year ago
-- <leader> is leader key; default is \
2 years ago
nmap("<leader>v", "<cmd>NvimTreeToggle<cr>")
nmap("<leader>ec", "<cmd>e ~/.config/nvim/init.lua<cr>")
nmap("<leader>sc", "<cmd>source ~/.config/nvim/init.lua<cr><cmd>PackerClean<cr><cmd>PackerCompile<cr>")
-- buffer commands
nmap("<leader>b", "<cmd>BufferLineCyclePrev<cr>")
nmap("<leader>n", "<cmd>BufferLineCycleNext<cr>")
nmap("<leader>gb", "<cmd>BufferLinePick<cr>")
nmap("<leader>w", "<cmd>bdelete!<cr>")
nmap("<leader>f", "<cmd>Telescope live_grep<cr>")
2 years ago
-- toggle terminal in both modes
nmap("<leader>t", "<cmd>FloatermToggle<cr>")
map("t", "<leader>t", "<cmd>FloatermToggle<cr>")
nmap("<leader>dd", "<cmd> lua vim.diagnostic.open_float() <CR>")
local augroup = vim.api.nvim_create_augroup("Lspformatting", {})
-- lsp on_attach mappings
local on_attach = function(client, bufnr)
1 year ago
if (not bufnr) then
return
end
2 years ago
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, bufopts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
1 year ago
vim.keymap.set('n', '<space>f', '<cmd>lua vim.lsp.buf.format({ async = true })<CR>', bufopts)
2 years ago
-- require "coq".lsp_ensure_capabilities {}
2 years ago
require 'illuminate'.on_attach(client)
1 year ago
-- format on save does not work for python for some reason
if client.supports_method("textDocument/formatting") then
1 year ago
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({
bufnr = bufnr,
})
end
})
end
end
2 years ago
local lsp = require "lspconfig"
local lsp_defaults = lsp.util.default_config
2 years ago
lsp.hls.setup { on_attach = on_attach } -- haskell language server
lsp.pyright.setup { on_attach = on_attach }
lsp.svelte.setup { on_attach = on_attach }
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.offsetEncoding = { "utf-16" }
lsp.clangd.setup { on_attach = on_attach, capabilities = capabilities }
lsp.ts_ls.setup { on_attach = on_attach }
1 year ago
lsp.marksman.setup { on_attach = on_attach }
lsp.rust_analyzer.setup { on_attach = on_attach,
settings = {
["rust-analyzer"] = {
checkOnSave = true,
check = {
enable = true,
command = "clippy",
features = "all"
}
}
}
}
1 year ago
lsp.lua_ls.setup { on_attach = on_attach,
2 years ago
settings = {
Lua = {
diagnostics = {
globals = { 'vim' }
}
}
}
}
lsp.tailwindcss.setup { on_attach = on_attach }
lsp.julials.setup {
on_new_config = function(new_config, _)
local julia = vim.fn.expand("~/.julia/environments/nvim-lspconfig/bin/julia")
if lsp.util.path.is_file(julia) then
vim.notify("running julials")
new_config.cmd[1] = julia
end
end,
on_attach = on_attach
}
1 year ago
-- kill eslint_d on exit
local on_leave_group = vim.api.nvim_create_augroup("OnLeaveGroup", {})
vim.api.nvim_create_autocmd("VimLeave", {
group = on_leave_group,
command = "silent !killall -q eslint_d",
})
-- packer boilerplate
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
2 years ago
packer_bootstrap = fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim',
install_path })
end
-- add code actions listeners?
--lua/code_action_utils.lua
--[[local M = {}
local lsp_util = vim.lsp.util
function M.code_action_listener()
local context = { diagnostics = vim.lsp.diagnostic.get_line_diagnostics() }
local params = lsp_util.make_range_params()
params.context = context
vim.lsp.buf_request(0, 'textDocument/codeAction', params, function(err, result, ctx, config)
-- do something with result - e.g. check if empty and show some indication such as a sign
end)
end
return M]]
--
vim.cmd("colorscheme carbonfox")
return require('packer').startup(function(use)
2 years ago
use 'wbthomason/packer.nvim'
use 'nvim-lua/plenary.nvim'
use 'neovim/nvim-lspconfig'
use {
'nvim-treesitter/nvim-treesitter',
run = ':TSUpdate',
1 year ago
config = function()
require('nvim-treesitter.configs').setup {
2 years ago
highlight = {
enable = true
},
}
end
}
use {
'nvim-tree/nvim-web-devicons',
}
use {
'nvim-tree/nvim-tree.lua',
after = "nvim-web-devicons",
requires = "nvim-tree/nvim-web-devicons",
config = function() require('nvim-tree').setup {} end
}
use {
"hrsh7th/nvim-cmp",
2 years ago
requires = {
"hrsh7th/cmp-buffer", "hrsh7th/cmp-nvim-lsp",
"L3MON4D3/LuaSnip", "rafamadriz/friendly-snippets",
'hrsh7th/cmp-nvim-lua', 'octaltree/cmp-look', 'hrsh7th/cmp-path', 'hrsh7th/cmp-calc',
'f3fora/cmp-spell', 'hrsh7th/cmp-emoji'
},
config = function()
local cmp = require("cmp")
local luasnip = require('luasnip')
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end
},
sources = {
{ name = 'path' },
{ name = 'nvim_lsp', keyword_length = 1 },
{ name = 'buffer', keyword_length = 3 },
{ name = 'luasnip', keyword_length = 2 },
},
window = {
documentation = cmp.config.window.bordered()
},
formatting = {
fields = { 'menu', 'abbr', 'kind' },
format = function(entry, item)
local menu_icon = {
nvim_lsp = 'λ',
luasnip = '',
buffer = 'Ω',
path = '🖫',
}
item.menu = menu_icon[entry.source.name]
return item
end,
},
mapping = {
['<Up>'] = cmp.mapping.select_prev_item(select_opts),
['<Down>'] = cmp.mapping.select_next_item(select_opts),
['<C-p>'] = cmp.mapping.select_prev_item(select_opts),
['<C-n>'] = cmp.mapping.select_next_item(select_opts),
['<C-u>'] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-e>'] = cmp.mapping.abort(),
['<C-y>'] = cmp.mapping.confirm({ select = true }),
['<CR>'] = cmp.mapping.confirm({ select = false }),
['<C-f>'] = cmp.mapping(function(fallback)
if luasnip.jumpable(1) then
luasnip.jump(1)
else
fallback()
end
end, { 'i', 's' }),
['<C-b>'] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}
})
end
2 years ago
}
use {
'nvimtools/none-ls.nvim',
1 year ago
config = function()
local null_ls = require("null-ls")
local lsp_conf = require("lspconfig")
-- util.root_pattern returns a function
local find_pyproject = lsp_conf.util.root_pattern('pyproject.toml')
local find_flake8 = lsp_conf.util.root_pattern('.flake8')
-- local find_eslint = lsp_conf.util.root_pattern('eslint.config.js')
1 year ago
local isort = null_ls.builtins.formatting.isort.with({
cwd = function(params)
return find_pyproject(params.root) or params.root
end
})
1 year ago
local black = null_ls.builtins.formatting.black.with({
cwd = function(params)
return find_pyproject(params.root) or params.root
end
})
local flake8 = require("none-ls.diagnostics.flake8").with({
1 year ago
cwd = function(params)
return find_flake8(params.root) or params.root
end
})
local eslint_format = require("none-ls.formatting.eslint_d").with({
extra_filetypes = { "svelte" },
})
local eslint_diag = require("none-ls.diagnostics.eslint_d").with({
extra_filetypes = { "svelte" },
})
local eslint_code_actions = require("none-ls.code_actions.eslint_d").with({
extra_filetypes = { "svelte" },
})
local spellcheck = null_ls.builtins.completion.spell.with({
filetypes = { "markdown" }
})
1 year ago
null_ls.setup {
on_attach = on_attach,
sources = {
eslint_format,
eslint_diag,
eslint_code_actions,
null_ls.builtins.code_actions.gitsigns,
null_ls.builtins.completion.luasnip,
null_ls.builtins.completion.tags,
spellcheck,
flake8,
isort,
black,
flake8
}
}
2 years ago
end,
requires = { "nvim-lua/plenary.nvim",
"nvimtools/none-ls-extras.nvim"
},
2 years ago
}
use {
'folke/trouble.nvim',
1 year ago
config = function()
require("trouble").setup {
nmap("<leader>xx", "<cmd>Trouble<cr>"),
}
2 years ago
end
}
use {
"hedyhli/outline.nvim",
config = function()
nmap("<leader>o", "<cmd>Outline<CR>")
require("outline").setup {
-- Your setup opts here (leave empty to use defaults)
}
end,
}
2 years ago
use {
'akinsho/bufferline.nvim',
tag = "*",
requires = 'nvim-tree/nvim-web-devicons',
1 year ago
config = function()
require("bufferline").setup {
2 years ago
options = {
diagnostics = "nvim_lsp",
}
}
end
}
use {
"nvim-lualine/lualine.nvim",
event = "VimEnter",
config = function()
require("lualine").setup {
options = { theme = 'auto', globalstatus = true },
sections = { lualine_x = { 'filetype' } }
}
end,
requires = { 'nvim-tree/nvim-web-devicons', opt = true }
2 years ago
}
use {
"startup-nvim/startup.nvim",
after = "nvim-web-devicons",
requires = { "nvim-tree/nvim-web-devicons", "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim" },
2 years ago
config = function()
require "startup".setup()
end
}
use 'RRethy/vim-illuminate'
use {
'nvim-telescope/telescope.nvim',
requires = { 'nvim-lua/plenary.nvim' },
config = function()
require("telescope").setup {}
end
}
use {
'j-hui/fidget.nvim',
config = function()
require('fidget').setup {}
end
}
use 'voldikss/vim-floaterm'
use {
'kkoomen/vim-doge',
run = ':call doge#install()'
}
use { 'norcalli/nvim-colorizer.lua',
1 year ago
config = function()
require('colorizer').setup {
'css',
'javascript',
'toml'
2 years ago
}
end,
}
use { 'lewis6991/gitsigns.nvim',
config = function()
require('gitsigns').setup {
on_attach = function()
nmap('<leader>hd', '<cmd>Gitsigns diffthis<cr>')
nmap('<leader>hr', '<cmd>Gitsigns reset_hunk<cr>')
nmap('<leader>td', '<cmd>Gitsigns toggle_deleted<cr>')
end
}
2 years ago
end
}
use { 'sudormrfbin/cheatsheet.nvim',
-- default toggle is <leader>?
requires = {
{ 'nvim-telescope/telescope.nvim' },
{ 'nvim-lua/popup.nvim' },
{ 'nvim-lua/plenary.nvim' },
}
}
use { 'stevearc/dressing.nvim' }
2 years ago
if packer_bootstrap then
require('packer').sync()
end
use "EdenEast/nightfox.nvim"
end)