Created
April 25, 2024 21:03
-
-
Save chartjes/3547d86884b9dee5d72769c8be780aa2 to your computer and use it in GitHub Desktop.
My Grumpy NeoVim Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- main NeoVim | |
" | |
" MAIN CUSTOMIZATION FILE | |
" | |
" | |
set nocompatible | |
syntax on | |
set encoding=utf8 | |
filetype on | |
" Load our plugins | |
"lua require('plugins') | |
lua require('lazy-plugins') | |
filetype plugin indent on | |
" Do smart autoindenting | |
set smartindent | |
set autoindent | |
" I like linenumbers, thanks | |
set number | |
" set search case to a good configuration http://vim.wikia.com/wiki/Searching | |
set ignorecase | |
set smartcase | |
" I like pretty colours in my terminal | |
set t_Co=256 | |
" Let's get some good colours in our terminal | |
let $NVM_TUI_ENABLE_TRUE_COLOR=1 | |
set termguicolors | |
color dracula | |
" We want to use ripgrep for any grep commands | |
set grepprg='rg' | |
" Basic configuration options | |
set tabstop=4 | |
set shiftwidth=4 | |
set softtabstop=0 | |
set smarttab | |
set expandtab | |
set wildmenu | |
set wildmode=list:longest,full | |
set ttyfast | |
set showmatch | |
set hlsearch | |
set incsearch | |
set backspace=indent,eol,start | |
" Make sure we are using the version of Python we want | |
let g:python3_host_prog = "/opt/homebrew/bin/python3" | |
" We always want to use UTF-8 | |
set encoding=UTF-8 | |
set fileencoding=UTF-8 | |
" Load other configuration files | |
lua require('lsp-installer') | |
lua require('lsp-config') | |
lua require('nvm-cmp') | |
lua require('dap-cfg') | |
lua require('vgit-config') | |
" Turn on Telescope | |
lua require('telescope').setup() | |
lua require('telescope').load_extension('fzf') | |
" Enable our new status line | |
lua require('lualine').setup() | |
" Show GIT info | |
set statusline+=%{get(b:,'vgit_status','')} | |
" Load our keyboard mappings | |
source ~/.config/nvim/mappings.vim | |
lua require('dap-mappings') | |
lua require('telescope-mappings') | |
" we want our tests to run in a popup window | |
let test#strategy = "floaterm" | |
-- keyboard bindings | |
" ------------------------------------------------------------------------------ | |
" # Mappings | |
" ------------------------------------------------------------------------------ | |
" # All of your mappings go in this file! Don't worry about your mappings | |
" # being separate from related config. Sourcery provides mappings to | |
" # easily jump between plugin definitions, mappings, and configs. | |
" # | |
" # More info: https://github.com/jesseleite/vim-sourcery#jumping-between-files | |
" ------------------------------------------------------------------------------ | |
" # Example | |
" ------------------------------------------------------------------------------ | |
" easily switch between vsplit windows | |
map <Leader>j <C-w>j | |
map <Leader>k <C-w>k | |
map <Leader>h <c-w>h | |
map <Leader>l <c-w>l | |
" Remove highlighing of search terms | |
nnoremap <leader><space> :nohlsearch<CR> | |
" Mappings for EasyAlign | |
xmap ga <Plug>(EasyAlign) | |
nmap ga <Plug>(EasyAlign) | |
" Use <Tab> and <S-Tab> to navigate through popup menu | |
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>" | |
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>" | |
" Telescope Trouble bindings | |
nnoremap <leader>xx <cmd>TroubleToggle<cr> | |
nnoremap <leader>xw <cmd>TroubleToggle workspace_diagnostics<cr> | |
nnoremap <leader>xd <cmd>TroubleToggle document_diagnostics<cr> | |
nnoremap <leader>xq <cmd>TroubleToggle quickfix<cr> | |
nnoremap <leader>xl <cmd>TroubleToggle loclist<cr> | |
nnoremap gR <cmd>TroubleToggle lsp_references<cr> | |
-- All my Lua config values | |
local dap = require('dap') | |
require('telescope').load_extension('dap') | |
dap.adapters.php = { | |
type = "executable", | |
command = "node", | |
args = { os.getenv("HOME") .. "/vscode-php-debug/out/phpDebug.js" } | |
} | |
dap.configurations.php = { | |
{ | |
type = "php", | |
request = "launch", | |
name = "Listen for Xdebug", | |
port = 9003, | |
} | |
} | |
vim.keymap.set('n', '<F5>', function() require('dap').continue() end) | |
vim.keymap.set('n', '<F10>', function() require('dap').step_over() end) | |
vim.keymap.set('n', '<F11>', function() require('dap').step_into() end) | |
vim.keymap.set('n', '<F12>', function() require('dap').step_out() end) | |
vim.keymap.set('n', '<Leader>b', function() require('dap').toggle_breakpoint() end) | |
vim.keymap.set('n', '<Leader>B', function() require('dap').set_breakpoint() end) | |
vim.keymap.set('n', '<Leader>lp', function() require('dap').set_breakpoint(nil, nil, vim.fn.input('Log point message: ')) end) | |
vim.keymap.set('n', '<Leader>dr', function() require('dap').repl.open() end) | |
vim.keymap.set('n', '<Leader>dl', function() require('dap').run_last() end) | |
vim.keymap.set({'n', 'v'}, '<Leader>dh', function() | |
require('dap.ui.widgets').hover() | |
end) | |
vim.keymap.set({'n', 'v'}, '<Leader>dp', function() | |
require('dap.ui.widgets').preview() | |
end) | |
vim.keymap.set('n', '<Leader>df', function() | |
local widgets = require('dap.ui.widgets') | |
widgets.centered_float(widgets.frames) | |
end) | |
vim.keymap.set('n', '<Leader>ds', function() | |
local widgets = require('dap.ui.widgets') | |
widgets.centered_float(widgets.scopes) | |
end) | |
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" | |
if not vim.loop.fs_stat(lazypath) then | |
vim.fn.system({ | |
"git", | |
"clone", | |
"--filter=blob:none", | |
"https://github.com/folke/lazy.nvim.git", | |
"--branch=stable", -- latest stable release | |
lazypath, | |
}) | |
end | |
vim.opt.rtp:prepend(lazypath) | |
require("lazy").setup({ | |
-- General plugins | |
"neovim/nvim-lspconfig", | |
"williamboman/nvim-lsp-installer", | |
"dracula/vim", | |
{"nvim-treesitter/nvim-treesitter", build = ':TSUpdate'}, | |
"mhinz/vim-startify", | |
"nvim-lualine/lualine.nvim", | |
"ray-x/lsp_signature.nvim", | |
"litao91/lsp_lines", | |
"editorconfig/editorconfig-vim", | |
-- See the git status of the current line in the gutter | |
"tanvirtin/vgit.nvim", | |
-- PHP plugins | |
"lumiliet/vim-twig", | |
-- Telescope support | |
'nvim-lua/plenary.nvim', | |
'nvim-telescope/telescope.nvim', | |
'sharkdp/fd', | |
{'nvim-telescope/telescope-fzf-native.nvim', build = 'make' }, | |
-- nvim-cmp support | |
'hrsh7th/nvim-cmp', | |
'hrsh7th/cmp-nvim-lsp', | |
'L3MON4D3/LuaSnip', | |
'saadparwaiz1/cmp_luasnip', | |
-- Xdebug support | |
-- https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#PHP | |
'mfussenegger/nvim-dap', | |
'nvim-telescope/telescope-dap.nvim', | |
{ | |
"folke/trouble.nvim", | |
dependencies = {"nvim-tree/nvim-web-devicons"} | |
}, | |
{"prettier/vim-prettier", build="yarn install --frozen-lockfile --production"}, | |
"vim-test/vim-test", | |
"voldikss/vim-floaterm", | |
}) | |
--- Configuration for LSP, formatters, and linters. | |
local nvim_lsp = require("lspconfig") | |
-- nvm-cmp support | |
local lsp_defaults = nvim_lsp.util.default_config | |
lsp_defaults.capabilities = vim.tbl_deep_extend( | |
'force', | |
lsp_defaults.capabilities, | |
require('cmp_nvim_lsp').default_capabilities() | |
) | |
-- short cut methods. | |
local t = function(str) | |
return vim.api.nvim_replace_termcodes(str, true, true, true) | |
end | |
local opts = { noremap=true, silent=true } | |
vim.api.nvim_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts) | |
vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts) | |
vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts) | |
vim.api.nvim_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts) | |
vim.api.nvim_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts) | |
local on_attach = function(client, bufnr) | |
-- 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 | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts) | |
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) | |
end | |
-- PHP | |
nvim_lsp.intelephense.setup({ | |
cmd = { "intelephense", "--stdio" }, | |
filetypes = { "php" }, | |
settings = { | |
intelephense = { | |
stubs = { | |
"wordpress", | |
"wordpress-globals", | |
"wp-cli" | |
}, | |
environment = { | |
includePaths = { | |
'/Users/chartjes/.composer/vendor/php-stubs/', | |
'/Users/chartjes/ibl.dev/scripts', | |
} | |
} | |
} | |
} | |
}) | |
-- Python | |
nvim_lsp.pyright.setup {} | |
--- Linter setup | |
local filetypes = { | |
typescript = "eslint", | |
typescriptreact = "eslint", | |
php = {"phpcs", "psalm"}, | |
} | |
local linters = { | |
phpcs = { | |
command = "vendor/bin/phpcs", | |
sourceName = "phpcs", | |
debounce = 300, | |
rootPatterns = {"composer.lock", "vendor", ".git"}, | |
args = {"--report=emacs", "-s", "-"}, | |
offsetLine = 0, | |
offsetColumn = 0, | |
sourceName = "phpcs", | |
formatLines = 1, | |
formatPattern = { | |
"^.*:(\\d+):(\\d+):\\s+(.*)\\s+-\\s+(.*)(\\r|\\n)*$", | |
{ | |
line = 1, | |
column = 2, | |
message = 4, | |
security = 3 | |
} | |
}, | |
securities = { | |
error = "error", | |
warning = "warning", | |
}, | |
requiredFiles = {"vendor/bin/phpcs"} | |
}, | |
psalm = { | |
command = "./vendor/bin/psalm", | |
sourceName = "psalm", | |
debounce = 100, | |
rootPatterns = {"composer.lock", "vendor", ".git"}, | |
args = {"--output-format=emacs", "--no-progress"}, | |
offsetLine = 0, | |
offsetColumn = 0, | |
sourceName = "psalm", | |
formatLines = 1, | |
formatPattern = { | |
"^[^ =]+ =(\\d+) =(\\d+) =(.*)\\s-\\s(.*)(\\r|\\n)*$", | |
{ | |
line = 1, | |
column = 2, | |
message = 4, | |
security = 3 | |
} | |
}, | |
securities = { | |
error = "error", | |
warning = "warning" | |
}, | |
requiredFiles = {"vendor/bin/psalm"} | |
} | |
} | |
nvim_lsp.diagnosticls.setup { | |
on_attach = on_attach, | |
filetypes = vim.tbl_keys(filetypes), | |
init_options = { | |
filetypes = filetypes, | |
linters = linters, | |
}, | |
} | |
require("nvim-lsp-installer").setup {} | |
local lspconfig = require("lspconfig") | |
local buf_map = function(bufnr, mode, lhs, rhs, opts) | |
vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts or { | |
silent = true, | |
}) | |
end | |
local on_attach = function(client, bufnr) | |
vim.cmd("command! LspDef lua vim.lsp.buf.definition()") | |
vim.cmd("command! LspFormatting lua vim.lsp.buf.formatting()") | |
vim.cmd("command! LspCodeAction lua vim.lsp.buf.code_action()") | |
vim.cmd("command! LspHover lua vim.lsp.buf.hover()") | |
vim.cmd("command! LspRename lua vim.lsp.buf.rename()") | |
vim.cmd("command! LspRefs lua vim.lsp.buf.references()") | |
vim.cmd("command! LspTypeDef lua vim.lsp.buf.type_definition()") | |
vim.cmd("command! LspImplementation lua vim.lsp.buf.implementation()") | |
vim.cmd("command! LspDiagPrev lua vim.lsp.diagnostic.goto_prev()") | |
vim.cmd("command! LspDiagNext lua vim.lsp.diagnostic.goto_next()") | |
vim.cmd("command! LspDiagLine lua vim.lsp.diagnostic.show_line_diagnostics()") | |
vim.cmd("command! LspSignatureHelp lua vim.lsp.buf.signature_help()") buf_map(bufnr, "n", "gd", ":LspDef<CR>") | |
buf_map(bufnr, "n", "gr", ":LspRename<CR>") | |
buf_map(bufnr, "n", "gy", ":LspTypeDef<CR>") | |
buf_map(bufnr, "n", "K", ":LspHover<CR>") | |
buf_map(bufnr, "n", "[a", ":LspDiagPrev<CR>") | |
buf_map(bufnr, "n", "]a", ":LspDiagNext<CR>") | |
buf_map(bufnr, "n", "ga", ":LspCodeAction<CR>") | |
buf_map(bufnr, "n", "<Leader>a", ":LspDiagLine<CR>") | |
buf_map(bufnr, "i", "<C-x><C-x>", "<cmd> LspSignatureHelp<CR>") | |
if client.resolved_capabilities.document_formatting then | |
vim.cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()") | |
end | |
end | |
lspconfig.tsserver.setup({ | |
on_attach = function(client, bufnr) | |
client.resolved_capabilities.document_formatting = false | |
client.resolved_capabilities.document_range_formatting = false local ts_utils = require("nvim-lsp-ts-utils") | |
ts_utils.setup({ | |
eslint_bin = "eslint_d", | |
eslint_enable_diagnostics = true, | |
eslint_enable_code_actions = true, | |
enable_formatting = true, | |
formatter = "prettier", | |
}) | |
ts_utils.setup_client(client) buf_map(bufnr, "n", "gs", ":TSLspOrganize<CR>") | |
buf_map(bufnr, "n", "gi", ":TSLspRenameFile<CR>") | |
buf_map(bufnr, "n", "go", ":TSLspImportAll<CR>") on_attach(client, bufnr) | |
end, | |
}) | |
local capabilities = vim.lsp.protocol.make_client_capabilities() | |
local lspconfig = require('lspconfig') | |
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp | |
local servers = { 'intelephense', 'tsserver' } | |
for _, lsp in ipairs(servers) do | |
lspconfig[lsp].setup { | |
-- on_attach = my_custom_on_attach, | |
capabilities = capabilities, | |
} | |
end | |
-- Luasnip support | |
local luasnip = require 'luasnip' | |
-- nvim-cmp setup | |
local cmp = require 'cmp' | |
cmp.setup { | |
mapping = { | |
['<C-p>'] = cmp.mapping.select_prev_item(), | |
['<C-n>'] = 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.Replace, | |
select = true, | |
}, | |
['<Tab>'] = function(fallback) | |
if cmp.visible() then | |
cmp.select_next_item() | |
elseif luasnip.expand_or_jumpable() then | |
luasnip.expand_or_jump() | |
else | |
fallback() | |
end | |
end, | |
['<S-Tab>'] = function(fallback) | |
if cmp.visible() then | |
cmp.select_prev_item() | |
elseif luasnip.jumpable(-1) then | |
luasnip.jump(-1) | |
else | |
fallback() | |
end | |
end, | |
}, | |
sources = { | |
{ name = 'nvim_lsp' }, | |
}, | |
} | |
return require('packer').startup(function() | |
use 'wbthomason/packer.nvim' | |
-- General plugins | |
use 'neovim/nvim-lspconfig' | |
use 'williamboman/nvim-lsp-installer' | |
use 'dracula/vim' | |
use { | |
'nvim-treesitter/nvim-treesitter', | |
run = ':TSUpdate' | |
} | |
use 'mhinz/vim-startify' | |
use 'nvim-lualine/lualine.nvim' | |
use 'ray-x/lsp_signature.nvim' | |
use 'litao91/lsp_lines' | |
-- See the git status of the current line in the gutter | |
use 'tanvirtin/vgit.nvim' | |
-- PHP plugins | |
use 'tpope/vim-dispatch' | |
use 'StanAngeloff/php.vim' | |
use 'stephpy/vim-php-cs-fixer' | |
use 'lumiliet/vim-twig' | |
-- Respect .editorconfig files for a project | |
use 'editorconfig/editorconfig-vim' | |
-- Telescope support | |
use 'nvim-lua/plenary.nvim' | |
use 'nvim-telescope/telescope.nvim' | |
use 'sharkdp/fd' | |
use {'nvim-telescope/telescope-fzf-native.nvim', run = 'make' } | |
-- nvim-cmp support | |
use 'hrsh7th/nvim-cmp' | |
use 'hrsh7th/cmp-nvim-lsp' | |
use 'L3MON4D3/LuaSnip' | |
use 'saadparwaiz1/cmp_luasnip' | |
-- Xdebug support | |
-- https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#PHP | |
use 'mfussenegger/nvim-dap' | |
use 'nvim-telescope/telescope-dap.nvim' | |
-- shows diagnostics and other errors | |
use { | |
"folke/trouble.nvim", | |
requires = "nvim-tree/nvim-web-devicons", | |
config = function () | |
require("trouble").setup { | |
} | |
end | |
} | |
-- support for neotest | |
use({ | |
"nvim-neotest/neotest", | |
requires = { | |
"nvim-lua/plenary.nvim", | |
"nvim-treesitter/nvim-treesitter", | |
"antoinemadec/FixCursorHold.nvim", | |
"olimorris/neotest-phpunit", | |
}, | |
config = function() | |
require("neotest").setup({ | |
adapters = { | |
require("neotest-phpunit"), | |
} | |
}) | |
end | |
}) | |
end) | |
local builtin = require('telescope.builtin') | |
vim.keymap.set('n', '<leader>ff', builtin.find_files, {}) | |
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {}) | |
vim.keymap.set('n', '<leader>fb', builtin.buffers, {}) | |
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {}) | |
require'nvim-treesitter.configs'.setup { | |
ensure_installed = "maintained", | |
highlight = { | |
enable = true, | |
additional_vim_regex_highlighting=true, | |
}, | |
indent = { | |
enable = false | |
}, | |
} | |
require('vgit').setup() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment