Personalize and format

This commit is contained in:
Barry Moore 2023-01-23 12:24:49 -05:00
parent 32744c3f66
commit 6c23c54be5
1 changed files with 255 additions and 273 deletions

262
init.lua
View File

@ -1,9 +1,13 @@
-- Install packer -- Install packer
local install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim' local install_path = vim.fn.stdpath 'data' ..
'/site/pack/packer/start/packer.nvim'
local is_bootstrap = false local is_bootstrap = false
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
is_bootstrap = true is_bootstrap = true
vim.fn.system { 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path } vim.fn.system {
'git', 'clone', '--depth', '1',
'https://github.com/wbthomason/packer.nvim', install_path
}
vim.cmd [[packadd packer.nvim]] vim.cmd [[packadd packer.nvim]]
end end
@ -15,32 +19,34 @@ require('packer').startup(function(use)
'neovim/nvim-lspconfig', 'neovim/nvim-lspconfig',
requires = { requires = {
-- Automatically install LSPs to stdpath for neovim -- Automatically install LSPs to stdpath for neovim
'williamboman/mason.nvim', 'williamboman/mason.nvim', 'williamboman/mason-lspconfig.nvim',
'williamboman/mason-lspconfig.nvim',
-- Useful status updates for LSP -- Useful status updates for LSP
'j-hui/fidget.nvim', 'j-hui/fidget.nvim',
-- Additional lua configuration, makes nvim stuff amazing -- Additional lua configuration, makes nvim stuff amazing
'folke/neodev.nvim', 'folke/neodev.nvim'
}, }
} }
use { -- Autocompletion use { -- Autocompletion
'hrsh7th/nvim-cmp', 'hrsh7th/nvim-cmp',
requires = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' }, requires = {
'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip',
'saadparwaiz1/cmp_luasnip'
}
} }
use { -- Highlight, edit, and navigate code use { -- Highlight, edit, and navigate code
'nvim-treesitter/nvim-treesitter', 'nvim-treesitter/nvim-treesitter',
run = function() run = function()
pcall(require('nvim-treesitter.install').update { with_sync = true }) pcall(require('nvim-treesitter.install').update {with_sync = true})
end, end
} }
use { -- Additional text objects via treesitter use { -- Additional text objects via treesitter
'nvim-treesitter/nvim-treesitter-textobjects', 'nvim-treesitter/nvim-treesitter-textobjects',
after = 'nvim-treesitter', after = 'nvim-treesitter'
} }
-- Git related plugins -- Git related plugins
@ -48,27 +54,33 @@ require('packer').startup(function(use)
use 'tpope/vim-rhubarb' use 'tpope/vim-rhubarb'
use 'lewis6991/gitsigns.nvim' use 'lewis6991/gitsigns.nvim'
use 'navarasu/onedark.nvim' -- Theme inspired by Atom use 'ellisonleao/gruvbox.nvim'
use 'nvim-lualine/lualine.nvim' -- Fancier statusline use 'nvim-lualine/lualine.nvim' -- Fancier statusline
use 'lukas-reineke/indent-blankline.nvim' -- Add indentation guides even on blank lines use 'lukas-reineke/indent-blankline.nvim' -- Add indentation guides even on blank lines
use 'numToStr/Comment.nvim' -- "gc" to comment visual regions/lines use 'numToStr/Comment.nvim' -- "gc" to comment visual regions/lines
use 'tpope/vim-sleuth' -- Detect tabstop and shiftwidth automatically use 'tpope/vim-sleuth' -- Detect tabstop and shiftwidth automatically
-- Fuzzy Finder (files, lsp, etc) -- Fuzzy Finder (files, lsp, etc)
use { 'nvim-telescope/telescope.nvim', branch = '0.1.x', requires = { 'nvim-lua/plenary.nvim' } } use {
'nvim-telescope/telescope.nvim',
branch = '0.1.x',
requires = {'nvim-lua/plenary.nvim'}
}
-- Fuzzy Finder Algorithm which requires local dependencies to be built. Only load if `make` is available -- Fuzzy Finder Algorithm which requires local dependencies to be built. Only load if `make` is available
use { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make', cond = vim.fn.executable 'make' == 1 } use {
'nvim-telescope/telescope-fzf-native.nvim',
run = 'make',
cond = vim.fn.executable 'make' == 1
}
use 'LnL7/vim-nix'
-- Add custom plugins to packer from ~/.config/nvim/lua/custom/plugins.lua -- Add custom plugins to packer from ~/.config/nvim/lua/custom/plugins.lua
local has_plugins, plugins = pcall(require, 'custom.plugins') local has_plugins, plugins = pcall(require, 'custom.plugins')
if has_plugins then if has_plugins then plugins(use) end
plugins(use)
end
if is_bootstrap then if is_bootstrap then require('packer').sync() end
require('packer').sync()
end
end) end)
-- When we are bootstrapping a configuration, it doesn't -- When we are bootstrapping a configuration, it doesn't
@ -85,11 +97,11 @@ if is_bootstrap then
end end
-- Automatically source and re-compile packer whenever you save this init.lua -- Automatically source and re-compile packer whenever you save this init.lua
local packer_group = vim.api.nvim_create_augroup('Packer', { clear = true }) local packer_group = vim.api.nvim_create_augroup('Packer', {clear = true})
vim.api.nvim_create_autocmd('BufWritePost', { vim.api.nvim_create_autocmd('BufWritePost', {
command = 'source <afile> | silent! LspStop | silent! LspStart | PackerCompile', command = 'source <afile> | silent! LspStop | silent! LspStart | PackerCompile',
group = packer_group, group = packer_group,
pattern = vim.fn.expand '$MYVIMRC', pattern = vim.fn.expand '$MYVIMRC'
}) })
-- [[ Setting options ]] -- [[ Setting options ]]
@ -120,7 +132,7 @@ vim.wo.signcolumn = 'yes'
-- Set colorscheme -- Set colorscheme
vim.o.termguicolors = true vim.o.termguicolors = true
vim.cmd [[colorscheme onedark]] vim.cmd [[colorscheme gruvbox]]
-- Set completeopt to have a better completion experience -- Set completeopt to have a better completion experience
vim.o.completeopt = 'menuone,noselect' vim.o.completeopt = 'menuone,noselect'
@ -131,24 +143,26 @@ vim.o.completeopt = 'menuone,noselect'
-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) -- NOTE: Must happen before plugins are required (otherwise wrong leader will be used)
vim.g.mapleader = ' ' vim.g.mapleader = ' '
vim.g.maplocalleader = ' ' vim.g.maplocalleader = ' '
vim.keymap.set({'n'}, ';', ':', {silent = true})
-- Keymaps for better default experience -- Keymaps for better default experience
-- See `:help vim.keymap.set()` -- See `:help vim.keymap.set()`
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true }) vim.keymap.set({'n', 'v'}, '<Space>', '<Nop>', {silent = true})
-- Remap for dealing with word wrap -- Remap for dealing with word wrap
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'",
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) {expr = true, silent = true})
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'",
{expr = true, silent = true})
-- [[ Highlight on yank ]] -- [[ Highlight on yank ]]
-- See `:help vim.highlight.on_yank()` -- See `:help vim.highlight.on_yank()`
local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) local highlight_group = vim.api.nvim_create_augroup('YankHighlight',
{clear = true})
vim.api.nvim_create_autocmd('TextYankPost', { vim.api.nvim_create_autocmd('TextYankPost', {
callback = function() callback = function() vim.highlight.on_yank() end,
vim.highlight.on_yank()
end,
group = highlight_group, group = highlight_group,
pattern = '*', pattern = '*'
}) })
-- Set lualine as statusline -- Set lualine as statusline
@ -158,8 +172,8 @@ require('lualine').setup {
icons_enabled = false, icons_enabled = false,
theme = 'onedark', theme = 'onedark',
component_separators = '|', component_separators = '|',
section_separators = '', section_separators = ''
}, }
} }
-- Enable Comment.nvim -- Enable Comment.nvim
@ -169,70 +183,74 @@ require('Comment').setup()
-- See `:help indent_blankline.txt` -- See `:help indent_blankline.txt`
require('indent_blankline').setup { require('indent_blankline').setup {
char = '', char = '',
show_trailing_blankline_indent = false, show_trailing_blankline_indent = false
} }
-- Gitsigns -- Gitsigns
-- See `:help gitsigns.txt` -- See `:help gitsigns.txt`
require('gitsigns').setup { require('gitsigns').setup {
signs = { signs = {
add = { text = '+' }, add = {text = '+'},
change = { text = '~' }, change = {text = '~'},
delete = { text = '_' }, delete = {text = '_'},
topdelete = { text = '' }, topdelete = {text = ''},
changedelete = { text = '~' }, changedelete = {text = '~'}
}, }
} }
-- [[ Configure Telescope ]] -- [[ Configure Telescope ]]
-- See `:help telescope` and `:help telescope.setup()` -- See `:help telescope` and `:help telescope.setup()`
require('telescope').setup { require('telescope').setup {
defaults = { defaults = {mappings = {i = {['<C-u>'] = false, ['<C-d>'] = false}}}
mappings = {
i = {
['<C-u>'] = false,
['<C-d>'] = false,
},
},
},
} }
-- Enable telescope fzf native, if installed -- Enable telescope fzf native, if installed
pcall(require('telescope').load_extension, 'fzf') pcall(require('telescope').load_extension, 'fzf')
-- See `:help telescope.builtin` -- See `:help telescope.builtin`
vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles,
vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' }) {desc = '[?] Find recently opened files'})
vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers,
{desc = '[ ] Find existing buffers'})
vim.keymap.set('n', '<leader>/', function() vim.keymap.set('n', '<leader>/', function()
-- You can pass additional configuration to telescope to change theme, layout, etc. -- You can pass additional configuration to telescope to change theme, layout, etc.
require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { require('telescope.builtin').current_buffer_fuzzy_find(require(
'telescope.themes').get_dropdown {
winblend = 10, winblend = 10,
previewer = false, previewer = false
}) })
end, { desc = '[/] Fuzzily search in current buffer]' }) end, {desc = '[/] Fuzzily search in current buffer]'})
vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files,
vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) {desc = '[S]earch [F]iles'})
vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags,
vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) {desc = '[S]earch [H]elp'})
vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string,
{desc = '[S]earch current [W]ord'})
vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep,
{desc = '[S]earch by [G]rep'})
vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics,
{desc = '[S]earch [D]iagnostics'})
-- [[ Configure Treesitter ]] -- [[ Configure Treesitter ]]
-- See `:help nvim-treesitter` -- See `:help nvim-treesitter`
require('nvim-treesitter.configs').setup { require('nvim-treesitter.configs').setup {
-- Add languages to be installed here that you want installed for treesitter -- Add languages to be installed here that you want installed for treesitter
ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'typescript', 'help', 'vim' }, ensure_installed = {
'c', 'cpp', 'go', 'lua', 'python', 'rust', 'typescript', 'help', 'vim',
'haskell'
},
highlight = { enable = true }, highlight = {enable = true},
indent = { enable = true, disable = { 'python' } }, indent = {enable = true, disable = {'python'}},
incremental_selection = { incremental_selection = {
enable = true, enable = true,
keymaps = { keymaps = {
init_selection = '<c-space>', init_selection = '<c-space>',
node_incremental = '<c-space>', node_incremental = '<c-space>',
scope_incremental = '<c-s>', scope_incremental = '<c-s>',
node_decremental = '<c-backspace>', node_decremental = '<c-backspace>'
}, }
}, },
textobjects = { textobjects = {
select = { select = {
@ -245,39 +263,35 @@ require('nvim-treesitter.configs').setup {
['af'] = '@function.outer', ['af'] = '@function.outer',
['if'] = '@function.inner', ['if'] = '@function.inner',
['ac'] = '@class.outer', ['ac'] = '@class.outer',
['ic'] = '@class.inner', ['ic'] = '@class.inner'
}, }
}, },
move = { move = {
enable = true, enable = true,
set_jumps = true, -- whether to set jumps in the jumplist set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = { goto_next_start = {
[']m'] = '@function.outer', [']m'] = '@function.outer',
[']]'] = '@class.outer', [']]'] = '@class.outer'
}, },
goto_next_end = { goto_next_end = {
[']M'] = '@function.outer', [']M'] = '@function.outer',
[']['] = '@class.outer', [']['] = '@class.outer'
}, },
goto_previous_start = { goto_previous_start = {
['[m'] = '@function.outer', ['[m'] = '@function.outer',
['[['] = '@class.outer', ['[['] = '@class.outer'
}, },
goto_previous_end = { goto_previous_end = {
['[M'] = '@function.outer', ['[M'] = '@function.outer',
['[]'] = '@class.outer', ['[]'] = '@class.outer'
}, }
}, },
swap = { swap = {
enable = true, enable = true,
swap_next = { swap_next = {['<leader>a'] = '@parameter.inner'},
['<leader>a'] = '@parameter.inner', swap_previous = {['<leader>A'] = '@parameter.inner'}
}, }
swap_previous = { }
['<leader>A'] = '@parameter.inner',
},
},
},
} }
-- Diagnostic keymaps -- Diagnostic keymaps
@ -296,22 +310,24 @@ local on_attach = function(_, bufnr)
-- In this case, we create a function that lets us more easily define mappings specific -- In this case, we create a function that lets us more easily define mappings specific
-- for LSP related items. It sets the mode, buffer and description for us each time. -- for LSP related items. It sets the mode, buffer and description for us each time.
local nmap = function(keys, func, desc) local nmap = function(keys, func, desc)
if desc then if desc then desc = 'LSP: ' .. desc end
desc = 'LSP: ' .. desc
end
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) vim.keymap.set('n', keys, func, {buffer = bufnr, desc = desc})
end end
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction') nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') nmap('gr', require('telescope.builtin').lsp_references,
'[G]oto [R]eferences')
nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition') nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols,
nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') '[D]ocument [S]ymbols')
nmap('<leader>ws',
require('telescope.builtin').lsp_dynamic_workspace_symbols,
'[W]orkspace [S]ymbols')
-- See `:help K` for why this keymap -- See `:help K` for why this keymap
nmap('K', vim.lsp.buf.hover, 'Hover Documentation') nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
@ -319,38 +335,21 @@ local on_attach = function(_, bufnr)
-- Lesser used LSP functionality -- Lesser used LSP functionality
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') nmap('<leader>wa', vim.lsp.buf.add_workspace_folder,
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') '[W]orkspace [A]dd Folder')
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder,
'[W]orkspace [R]emove Folder')
nmap('<leader>wl', function() nmap('<leader>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders())) print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, '[W]orkspace [L]ist Folders') end, '[W]orkspace [L]ist Folders')
-- Create a command `:Format` local to the LSP buffer -- Create a command `:Format` local to the LSP buffer
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) vim.api.nvim_buf_create_user_command(bufnr, 'Format',
vim.lsp.buf.format() function(_) vim.lsp.buf.format() end, {
end, { desc = 'Format current buffer with LSP' }) desc = 'Format current buffer with LSP'
})
end end
-- Enable the following language servers
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
--
-- Add any additional override configuration in the following tables. They will be passed to
-- the `settings` field of the server config. You must look up that documentation yourself.
local servers = {
-- clangd = {},
-- gopls = {},
-- pyright = {},
-- rust_analyzer = {},
-- tsserver = {},
sumneko_lua = {
Lua = {
workspace = { checkThirdParty = false },
telemetry = { enable = false },
},
},
}
-- Setup neovim lua configuration -- Setup neovim lua configuration
require('neodev').setup() require('neodev').setup()
-- --
@ -358,25 +357,15 @@ require('neodev').setup()
local capabilities = vim.lsp.protocol.make_client_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
-- Setup mason so it can manage external tooling local haskell_cmd
require('mason').setup() if os.getenv('USE_HALFSP') then
haskell_cmd = {'halfsp'}
-- Ensure the servers above are installed else
local mason_lspconfig = require 'mason-lspconfig' haskell_cmd = {'haskell-language-server-wrapper', '--lsp'}
end
mason_lspconfig.setup { require('lspconfig')['hls'].setup {cmd = haskell_cmd, on_attach = on_attach}
ensure_installed = vim.tbl_keys(servers), -- nix lsp
} require('lspconfig')['nil_ls'].setup {}
mason_lspconfig.setup_handlers {
function(server_name)
require('lspconfig')[server_name].setup {
capabilities = capabilities,
on_attach = on_attach,
settings = servers[server_name],
}
end,
}
-- Turn on lsp status information -- Turn on lsp status information
require('fidget').setup() require('fidget').setup()
@ -386,18 +375,14 @@ local cmp = require 'cmp'
local luasnip = require 'luasnip' local luasnip = require 'luasnip'
cmp.setup { cmp.setup {
snippet = { snippet = {expand = function(args) luasnip.lsp_expand(args.body) end},
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert { mapping = cmp.mapping.preset.insert {
['<C-d>'] = cmp.mapping.scroll_docs(-4), ['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4), ['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(), ['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm { ['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace, behavior = cmp.ConfirmBehavior.Replace,
select = true, select = true
}, },
['<Tab>'] = cmp.mapping(function(fallback) ['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
@ -407,7 +392,7 @@ cmp.setup {
else else
fallback() fallback()
end end
end, { 'i', 's' }), end, {'i', 's'}),
['<S-Tab>'] = cmp.mapping(function(fallback) ['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
@ -416,12 +401,9 @@ cmp.setup {
else else
fallback() fallback()
end end
end, { 'i', 's' }), end, {'i', 's'})
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
}, },
sources = {{name = 'nvim_lsp'}, {name = 'luasnip'}}
} }
-- The line beneath this is called `modeline`. See `:help modeline` -- The line beneath this is called `modeline`. See `:help modeline`