Add nvim config based on kickstart

main
Buddy Sandidge 1 year ago
parent 6009b41350
commit acf86e8285

@ -0,0 +1,14 @@
# chezmoi:template:left-delimiter=#{{
#{{- /* vim: set filetype=toml: */ -}}
[".local/share/nvim/lazy/lazy.nvim"]
type = "archive"
url = "https://github.com/folke/lazy.nvim/archive/refs/tags/v10.15.1.tar.gz"
exact = true
stripComponents = 1
#{{ if eq .chezmoi.os "linux" }}
[".local/bin/nvim.appimage"]
type = "file"
url = "https://github.com/neovim/neovim/releases/download/v0.9.4/nvim.appimage"
executable = true
#{{ end }}

@ -0,0 +1,5 @@
require 'core.config'
require 'core.commands'
require 'core.keymaps'
vim.opt.runtimepath:prepend(vim.fn.stdpath('data') .. '/lazy/lazy.nvim')
require 'lazy' .setup('plugins', {})

@ -0,0 +1,2 @@
vim.api.nvim_create_user_command('W', 'write', {})
vim.api.nvim_create_user_command('Q', 'qall!', {})

@ -0,0 +1,38 @@
vim.g.mapleader = ','
vim.g.maplocalleader = ','
vim.opt.fileformats = { 'unix', 'dos', 'mac' }
vim.opt.autochdir = true
-- Tabs
vim.opt.shiftwidth = 4
vim.opt.softtabstop = 4
vim.opt.tabstop = 4
-- UI
vim.opt.matchtime = 2
vim.opt.number = true
vim.opt.numberwidth = 4
vim.opt.relativenumber = true
vim.opt.showmatch = true
vim.opt.spelllang = 'en_us'
vim.opt.wildmode = 'list:longest'
-- Indent
vim.opt.copyindent = true
vim.opt.preserveindent = true
vim.opt.smartindent = true
vim.opt.shiftround = true
-- Text Formatting/Layout
vim.opt.ignorecase = true
vim.opt.list = true
vim.opt.smartcase = true
vim.opt.wrap = false
vim.opt.whichwrap:append {
['<'] = true,
['>'] = true,
['['] = true,
[']'] = true,
}

@ -0,0 +1,6 @@
vim.keymap.set('n', '<leader>l', ':nohlsearch<CR>')
vim.keymap.set('n', '<leader>ts', [[:%s/\s\s*$//g<CR>]])
vim.keymap.set('n', '<leader>ss', ':setlocal spell!<CR>')
vim.keymap.set('n', '<leader>p', ':set paste!<CR>')
vim.keymap.set('n', '<leader>nn', ':set nonumber norelativenumber<CR>')
vim.keymap.set('n', '<leader>rn', ':set number relativenumber<CR>')

@ -0,0 +1,61 @@
local function config()
local cmp = require 'cmp'
local luasnip = require 'luasnip'
local function expand(args)
luasnip.lsp_expand(args.body)
end
local function tab_mapping(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end
local function back_tab_mapping(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end
cmp.setup {
enabled = true,
snippet = { expand = expand },
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
mapping = cmp.mapping.preset.insert {
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete({}),
['<Tab>'] = cmp.mapping(tab_mapping, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(back_tab_mapping, { 'i', 's' }),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
},
}
end
return {
'hrsh7th/nvim-cmp',
config = config,
dependencies = {
'saadparwaiz1/cmp_luasnip',
'hrsh7th/cmp-nvim-lsp',
},
}

@ -0,0 +1,22 @@
local config = function()
local wk = require 'which-key'
wk.setup()
wk.register {
['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' },
['<leader>g'] = { name = '[G]it', _ = 'which_key_ignore' },
['<leader>h'] = { name = 'More git', _ = 'which_key_ignore' },
['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' },
['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' },
['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' },
}
end
return {
'folke/which-key.nvim',
config = config,
dependencies = {
{ 'tpope/vim-sleuth', tag = 'v2.0' },
{ 'tpope/vim-surround', tag = 'v2.2' },
},
}

@ -0,0 +1,93 @@
local function on_attach(_, bufnr)
local nmap = function(keys, func, desc)
if desc then
desc = 'LSP: ' .. desc
end
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
end
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
nmap('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[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
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
-- Lesser used LSP functionality
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>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
nmap('<leader>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, '[W]orkspace [L]ist Folders')
-- Create a command `:Format` local to the LSP buffer
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
vim.lsp.buf.format()
end, { desc = 'Format current buffer with LSP' })
end
local function config()
local mason = require 'mason'
local mason_lspconfig = require 'mason-lspconfig'
local neodev = require 'neodev'
mason.setup()
neodev.setup()
local servers = {
-- clangd = {},
-- pyright = {},
-- rust_analyzer = {},
-- tsserver = {},
-- html = { filetypes = { 'html', 'twig', 'hbs'} },
gopls = {},
lua_ls = {
Lua = {
workspace = { checkThirdParty = false },
telemetry = { enable = false },
},
},
}
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
mason_lspconfig.setup {
ensure_installed = vim.tbl_keys(servers),
}
mason_lspconfig.setup_handlers {
function(server_name)
require('lspconfig')[server_name].setup {
capabilities = capabilities,
on_attach = on_attach,
settings = servers[server_name],
filetypes = (servers[server_name] or {}).filetypes,
}
end,
}
end
return {
-- LSP Configuration & Plugins
'neovim/nvim-lspconfig',
config = config,
dependencies = {
-- Automatically install LSPs to stdpath for neovim
'williamboman/mason.nvim',
'williamboman/mason-lspconfig.nvim',
-- Useful status updates for LSP
{ 'j-hui/fidget.nvim', tag = 'legacy', opts = {} },
-- Additional lua configuration, makes nvim stuff amazing!
'folke/neodev.nvim',
'folke/trouble.nvim',
},
}

@ -0,0 +1,12 @@
local function config()
local luasnip = require 'luasnip'
luasnip.setup()
luasnip.config.setup({})
end
return {
'L3MON4D3/LuaSnip',
config = config,
tag = 'v2.*',
dependencies = {},
}

@ -0,0 +1,97 @@
-- Telescope live_grep in git root
-- Function to find the git root directory based on the current buffer's path
local function find_git_root()
-- Use the current buffer's path as the starting point for the git search
local current_file = vim.api.nvim_buf_get_name(0)
local current_dir
local cwd = vim.fn.getcwd()
-- If the buffer is not associated with a file, return nil
if current_file == '' then
current_dir = cwd
else
-- Extract the directory from the current file's path
current_dir = vim.fn.fnamemodify(current_file, ':h')
end
-- Find the Git root directory from the current file's path
local git_root = vim.fn.systemlist('git -C ' .. vim.fn.escape(current_dir, ' ') .. ' rev-parse --show-toplevel')[1]
if vim.v.shell_error ~= 0 then
print('Not a git repository. Searching on current working directory')
return cwd
end
return git_root
end
-- Custom live_grep function to search in git root
local function live_grep_git_root()
local git_root = find_git_root()
if git_root then
require('telescope.builtin').live_grep({
search_dirs = { git_root },
})
end
end
vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {})
local telescope_setup = {
defaults = {
mappings = {
i = {
['<C-u>'] = false,
['<C-d>'] = false,
},
},
},
}
local function config()
-- See `:help telescope` and `:help telescope.setup()`
local telescope = require('telescope')
local builtin = require('telescope.builtin')
local themes = require('telescope.themes')
telescope.setup(telescope_setup)
-- Enable telescope fzf native, if installed
pcall(telescope.load_extension, 'fzf')
local fuzzy_find = function()
-- You can pass additional configuration to telescope to change theme, layout, etc.
builtin.current_buffer_fuzzy_find(themes.get_dropdown({
winblend = 10,
previewer = false,
}))
end
-- See `:help telescope.builtin`
vim.keymap.set('n', '<leader>?', builtin.oldfiles, { desc = '[?] Find recently opened files' })
vim.keymap.set('n', '<leader><space>', builtin.buffers, { desc = '[ ] Find existing buffers' })
vim.keymap.set('n', '<leader>/', fuzzy_find, { desc = '[/] Fuzzily search in current buffer' })
vim.keymap.set('n', '<leader>gf', builtin.git_files, { desc = 'Search [G]it [F]iles' })
vim.keymap.set('n', '<leader>sf', builtin.find_files, { desc = '[S]earch [F]iles' })
vim.keymap.set('n', '<leader>sh', builtin.help_tags, { desc = '[S]earch [H]elp' })
vim.keymap.set('n', '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' })
vim.keymap.set('n', '<leader>sg', builtin.live_grep, { desc = '[S]earch by [G]rep' })
vim.keymap.set('n', '<leader>sG', live_grep_git_root, { desc = '[S]earch by [G]rep on Git Root' })
vim.keymap.set('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' })
vim.keymap.set('n', '<leader>sr', builtin.resume, { desc = '[S]earch [R]esume' })
end
local is_make_installed = function()
return vim.fn.executable('make') == 1
end
return {
'nvim-telescope/telescope.nvim',
branch = '0.1.x',
config = config,
dependencies = {
'nvim-lua/plenary.nvim',
{
'nvim-telescope/telescope-fzf-native.nvim',
cond = is_make_installed,
build = 'make',
},
},
}

@ -0,0 +1,17 @@
local function config()
vim.cmd.colorscheme 'gruvbox'
end
return {
'morhetz/gruvbox',
priority = 1000,
config = config,
dependencies = {
'nvim-lualine/lualine.nvim',
opts = {
options = {
theme = 'gruvbox',
},
},
},
}

@ -0,0 +1,60 @@
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.opt.termguicolors = true
local function handle_closed(window)
local tab = vim.api.nvim_win_get_tabpage(window)
local buffer = vim.api.nvim_win_get_buf(window)
local info = vim.fn.getbufinfo(buffer)[1]
local filter_window = function(w)
return w ~= window
end
local windows = vim.tbl_filter(filter_window, vim.api.nvim_tabpage_list_wins(tab))
local buffers = vim.tbl_map(vim.api.nvim_win_get_buf, windows)
if info.name:match('.*NvimTree_%d*$') then
if not vim.tbl_isempty(buffers) then
require('nvim-tree.api').tree.close()
end
return
end
if #buffers ~= 1 then
return
end
local last_info = vim.fn.getbufinfo(buffers[1])[1]
if last_info.name:match('.*NvimTree_%d*$') then
vim.schedule(function()
if #vim.api.nvim_list_wins() == 1 then
vim.cmd 'quit'
else
vim.api.nvim_win_close(windows[1], true)
end
end)
end
end
local config = function()
require('nvim-tree').setup()
vim.api.nvim_create_autocmd('WinClosed', {
nested = true,
callback = function()
local window = tonumber(vim.fn.expand('<amatch>'))
vim.schedule_wrap(handle_closed(window))
end,
})
end
return {
'nvim-tree/nvim-tree.lua',
config = config,
keys = {
{ '<leader>nt', ':NvimTreeToggle<CR>', desc = 'toggle nvim tree' }
},
dependencies = {
'nvim-tree/nvim-web-devicons', opts = {}
},
}

@ -0,0 +1,93 @@
local treesitter_config_setup = {
-- Add languages to be installed here that you want installed for treesitter
ensure_installed = {
'bash', 'c', 'cpp', 'go', 'lua', 'python', 'rust',
'tsx', 'javascript', 'typescript', 'vimdoc', 'vim',
},
auto_install = true,
sync_install = false,
modules = {},
ignore_install = {},
highlight = { enable = true },
indent = { enable = true },
incremental_selection = {
enable = true,
keymaps = {
init_selection = '<c-space>',
node_incremental = '<c-space>',
scope_incremental = '<c-s>',
node_decremental = '<M-space>',
},
},
textobjects = {
select = {
enable = true,
-- Automatically jump forward to textobj, similar to targets.vim
lookahead = true,
keymaps = {
-- You can use the capture groups defined in textobjects.scm
['aa'] = '@parameter.outer',
['ia'] = '@parameter.inner',
['af'] = '@function.outer',
['if'] = '@function.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
},
},
swap = {
enable = true,
swap_next = {
['<leader>a'] = '@parameter.inner',
},
swap_previous = {
['<leader>A'] = '@parameter.inner',
},
},
move = {
enable = true,
-- whether to set jumps in the jumplist
set_jumps = true,
goto_next_start = {
[']m'] = '@function.outer',
[']]'] = '@class.outer',
},
goto_next_end = {
[']M'] = '@function.outer',
[']['] = '@class.outer',
},
goto_previous_start = {
['[m'] = '@function.outer',
['[['] = '@class.outer',
},
goto_previous_end = {
['[M'] = '@function.outer',
['[]'] = '@class.outer',
},
},
},
}
local function treesitter_configs()
require('nvim-treesitter.configs').setup(treesitter_config_setup)
end
local function config()
vim.defer_fn(treesitter_configs, 0)
end
return {
-- Highlight, edit, and navigate code
'nvim-treesitter/nvim-treesitter',
config = config,
build = ':TSUpdate',
dependencies = {
'nvim-treesitter/nvim-treesitter-textobjects',
},
}

@ -38,8 +38,3 @@ NPM_CONFIG_USERCONFIG="${XDG_CONFIG_HOME}/npm/npmrc"
#{{ if lookPath "rg" -}}#
RIPGREP_CONFIG_PATH="${XDG_CONFIG_HOME}/ripgrep/config"
#{{ end -}}#
#{{ if or (lookPath "vim") (lookPath "nvim") -}}#
VIMINIT='source $XDG_CONFIG_HOME/vim/vimrc'
MYVIMRC='$XDG_CONFIG_HOME/vim/vimrc'
#{{- end }}#

@ -39,7 +39,6 @@ set colorcolumn=81
" Have tab complete work more like bash
set wildmode=list:longest
set whichwrap+=<,>,[,]
set magic
" Turn on omni completion. Must have `filetype plugin on` to use.
" To use, in insert mode press ctrl+x ctrl+o
@ -60,7 +59,8 @@ set list
" UI
set showcmd
set number relativenumber
set number
set relativenumber
set numberwidth=4
set hidden

@ -3,7 +3,7 @@
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" fzf
"{{ if lookPath "fzf" }}
Plug 'junegunn/fzf', { 'tag': '0.40.0' }
Plug 'junegunn/fzf', { 'tag': '0.43.0' }
Plug 'junegunn/fzf.vim'
map <leader>fz :GFiles<CR>

@ -1,6 +1,3 @@
" use XDG
if empty($MYVIMRC) | let $MYVIMRC = expand('%:p') | endif
if empty($XDG_CACHE_HOME) | let $XDG_CACHE_HOME = $HOME.'/.cache' | endif
if empty($XDG_CONFIG_HOME) | let $XDG_CONFIG_HOME = $HOME.'/.config' | endif
if empty($XDG_DATA_HOME) | let $XDG_DATA_HOME = $HOME.'/.local/share' | endif

Loading…
Cancel
Save