1
0
Fork 0
chezmoi/dot_config/nvim/init.lua
2022-05-27 10:24:53 +02:00

498 lines
16 KiB
Lua

--- PACKAGES {{{
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
local packer_bootstrap = fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path })
end
require('packer').startup(function(use)
use 'wbthomason/packer.nvim'
use 'neovim/nvim-lspconfig'
-- use 'glepnir/lspsaga.nvim'
use { 'hrsh7th/nvim-cmp', requires = { 'neovim/nvim-lspconfig' } }
use { 'hrsh7th/cmp-nvim-lsp', requires = { 'hrsh7th/nvim-cmp' } }
use { 'hrsh7th/cmp-buffer', requires = { 'hrsh7th/nvim-cmp' } }
use { 'hrsh7th/cmp-path', requires = { 'hrsh7th/nvim-cmp' } }
use { 'hrsh7th/cmp-nvim-lua', requires = { 'hrsh7th/nvim-cmp' } }
use 'hrsh7th/vim-vsnip'
use 'hrsh7th/cmp-nvim-lsp-signature-help'
use { 'hrsh7th/cmp-vsnip', requires = { 'hrsh7th/nvim-cmp', 'hrsh7th/vim-vsnip' } }
use { 'onsails/lspkind.nvim' }
use { 'simrat39/symbols-outline.nvim', cmd = 'SymbolsOutline' }
use { 'jose-elias-alvarez/null-ls.nvim', requires = { "nvim-lua/plenary.nvim" } }
use {
'folke/trouble.nvim',
requires = "kyazdani42/nvim-web-devicons",
cmd = 'TroubleToggle',
keys = { 'n', '<space>t <Cmd>TroubleToggle<CR>' }
-- config = require('trouble').setup()
}
use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }
use 'nvim-treesitter/playground'
use 'David-Kunz/treesitter-unit'
use({ "yioneko/nvim-yati", requires = "nvim-treesitter/nvim-treesitter" })
use { 'nvim-telescope/telescope.nvim', requires = { 'nvim-lua/popup.nvim', 'nvim-lua/plenary.nvim' } }
use { 'nvim-telescope/telescope-fzf-native.nvim',
run = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build'
}
-- use {"ellisonleao/gruvbox.nvim", requires = {"rktjmp/lush.nvim"}}
use 'morhetz/gruvbox'
-- use 'lifepillar/vim-solarized8'
use { 'chrisbra/Colorizer', cmd = 'ColorToggle', keys = { 'n', '<space>c <Cmd>ColorToggle<CR>' } }
-- #aaaaaa
use { 'kdheepak/lazygit.nvim', keys = { 'n', '<space>g <Cmd>LazyGit<CR>' }, cmd = 'LazyGit' }
use { 'lewis6991/gitsigns.nvim', requires = { 'nvim-lua/plenary.nvim' } }
use { 'hoob3rt/lualine.nvim', requires = { 'kyazdani42/nvim-web-devicons', opt = true } }
use { 'AndrewRadev/linediff.vim', cmd = 'LineDiffAdd' }
use "lukas-reineke/indent-blankline.nvim"
use 'b3nj5m1n/kommentary'
use 'airblade/vim-rooter'
use { 'vlada-dudr/vim-php-cs-fixer', ft = 'php' }
use 'editorconfig/editorconfig-vim'
use { 'scrooloose/nerdtree', disable = true }
use { 'kyazdani42/nvim-tree.lua',
requires = 'kyazdani42/nvim-web-devicons',
config = 'require"nvim-tree".setup()',
cmd = { 'NvimTreeToggle', 'NvimTreeFindFile' },
keys = {
{ 'n', '<F3> <Cmd>NvimTreeToggle<CR>' },
{ 'n', '<F4> <Cmd>NvimTreeFindFile<CR>' },
} }
use { 'vim-vdebug/vdebug', ft = php }
use { 'dyng/ctrlsf.vim', cmd = 'CtrlSF' }
use { 'fpob/nette.vim', ft = nette }
use { 'ziglang/zig.vim', ft = 'zig' }
use { 'folke/lua-dev.nvim' }
use {'AndrewRadev/tagalong.vim'}
use {'andymass/vim-matchup'}
if packer_bootstrap then
require('packer').sync()
end
end)
--- PACKAGES }}}
--- OPTIONS {{{
vim.o.ruler = true
vim.o.mouse = ''
vim.o.showcmd = true
vim.o.scrolloff = 3
vim.o.ignorecase = true
vim.o.smartcase = true
vim.o.incsearch = true
vim.o.inccommand = 'split'
vim.o.hidden = true
vim.o.autoread = true
vim.o.completeopt = 'menuone,noinsert,noselect'
vim.o.tabstop = 4
vim.o.softtabstop = 4
vim.o.swapfile = true
vim.o.undofile = true
vim.o.expandtab = true
vim.o.shiftwidth = 4
vim.o.number = true
--vim.o.colorcolumn=0
--vim.o.foldmethod='marker'
vim.o.foldcolumn = 'auto:1'
vim.o.signcolumn = 'yes'
vim.o.list = false
vim.o.relativenumber = false
vim.o.foldenable = true
vim.o.cursorline = true
vim.o.autoindent = true
vim.o.smartindent = true
vim.o.fileencodings = 'ucs-bom,utf-8,default,cp852,latin1'
vim.o.path = '**'
--vim.o.clipboard = "unnamedplus"
-- Buffer
vim.cmd([[
augroup forceRecheck
au FocusGained,BufEnter * :silent! !
augroup END
]])
-- vim.env.EDITOR = 'nvr'
--- OPTIONS }}}
--- LSP {{{
-- local saga = require('lspsaga').init_lsp_saga()
local nvim_lsp = require('lspconfig')
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
-- require'completion'.on_attach()
-- Mappings.
local opts = { noremap = true, silent = true }
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('i', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('v', '<space>ca', '<cmd>lua vim.lsp.buf.range_code_action()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
buf_set_keymap("n", "<space>gf", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
buf_set_keymap("v", "<space>gf", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
end
-- Use a loop to conveniently both setup defined servers
-- and map buffer local keybindings when the language server attaches
local servers = { 'phpactor', 'gopls', 'clangd', 'zls', 'hls', 'tsserver', 'sumneko_lua' }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
}
end
require 'lspconfig'.omnisharp.setup {
cmd = { '/usr/bin/omnisharp', '--languageserver', '--hostPID', tostring(pid) },
on_attach = on_attach,
capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
}
require 'lspconfig'.powershell_es.setup {
bundle_path = '/home/sogun/devel/PowerShellEditorServices',
capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
}
--vim.lsp.set_log_level("debug")
--- LSP }}}
--- CMP {{{
local cmp = require 'cmp'
cmp.setup({
-- documentation = true,
sources = {
{ name = 'nvim_lsp' },
{ name = 'nvim_lua' },
{ name = 'buffer' },
{ name = 'path' },
{ name = 'nvim_lsp_signature_help' },
},
formatting = {
format = require 'lspkind'.cmp_format({
-- mode = 'symbol',
}),
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<CR>'] = cmp.mapping.confirm({ select = false })
}),
snippet = {
expand = function(args)
-- For `vsnip` user.
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` user.
end
}
})
--- CMP }}}
-- vsnip {{{
vim.cmd 'imap <expr> <Tab> vsnip#jumpable(1) ? \'<Plug>(vsnip-jump-next)\' : \'<Tab>\''
vim.cmd 'smap <expr> <Tab> vsnip#jumpable(1) ? \'<Plug>(vsnip-jump-next)\' : \'<Tab>\''
vim.cmd 'imap <expr> <S-Tab> vsnip#jumpable(-1) ? \'<Plug>(vsnip-jump-prev)\' : \'<S-Tab>\''
vim.cmd 'smap <expr> <S-Tab> vsnip#jumpable(-1) ? \'<Plug>(vsnip-jump-prev)\' : \'<S-Tab>\''
-- vsnip }}}
--- gitsigns {{{
require 'gitsigns'.setup {}
--- gitsigns }}}
-- lualine {{{
require 'lualine'.setup {
options = {
icons_enabled = true,
theme = vim.env.TERM ~= 'linux' and 'gruvbox' or nil,
component_separators = { '', '' },
section_separators = { '', '' },
disabled_filetypes = {}
},
sections = {
lualine_a = { 'mode' },
lualine_b = { 'branch' },
lualine_c = { { 'filename', path = 1 } },
lualine_x = { 'encoding', 'fileformat', 'filetype' },
lualine_y = { 'progress' },
lualine_z = { 'location' }
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = { 'filename' },
lualine_x = { 'location' },
lualine_y = {},
lualine_z = {}
},
tabline = {},
extensions = { 'nerdtree' }
}
-- lualine }}}
-- NerdTree {{{
--vim.api.nvim_set_keymap('n', '<F3>', [[<Cmd>NERDTreeToggle<CR>]], { noremap = true, silent = true })
--vim.api.nvim_set_keymap('n', '<F4>', [[<Cmd>NERDTreeFind %<CR>]], { noremap = true, silent = true })
-- NerdTree }}}
-- NvimTree {{{
vim.g.nvim_tree_add_trailing = 1
vim.g.nvim_tree_special_files = ''
vim.cmd([[
let g:nvim_tree_show_icons = {
\ 'git': 0,
\ 'folders': 0,
\ 'files': 0,
\ 'folder_arrows': 0,
\ }
]])
-- vim.api.nvim_set_keymap('n', '<F3>', '<Cmd>NvimTreeToggle<CR>', { noremap = true, silent = true })
-- vim.api.nvim_set_keymap('n', '<F4>', '<Cmd>NvimTreeFindFile<CR>', { noremap = true, silent = true })
-- }}} NvimTree
-- Telescope {{{
vim.api.nvim_set_keymap('n', '<Space>b', [[<Cmd>Telescope buffers<CR>]], { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<Space>f', [[<Cmd>Telescope fd<CR>]], { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<Space>T', [[<Cmd>Telescope<CR>]], { noremap = true, silent = true })
require("telescope").setup {
defaults = {
preview = {
hide_on_startup = true
},
--[[ mappings = {
i = {
["<c-h>"] = actions.toggle_preview,
},
n = {
["<c-h>"] = actions.toggle_preview,
},
}, ]]
},
pickers = {
buffers = {
show_all_buffers = true,
sort_lastused = false,
sort_mru = true,
-- theme = "dropdown",
mappings = {
i = {
["<c-d>"] = "delete_buffer",
},
n = {
["<c-d>"] = "delete_buffer",
}
}
}
}
}
require('telescope').load_extension('fzf')
--[[ local telescope_ag = vim.api.nvim_create_augroup('Telescope')
nvim.nvim_create_autocmd('FileType', { pattern='TelescopePrompt', command = nvim.nvim_buf_set_keymap('n', '' ]]
vim.cmd 'augroup Telescope'
vim.cmd 'autocmd FileType TelescopePrompt inoremap <buffer> <C-b> <cmd>Telescope buffers initial_mode=insert<cr>'
vim.cmd 'autocmd FileType TelescopePrompt inoremap <buffer> <C-f> <cmd>Telescope fd initial_mode=insert<cr>'
vim.cmd 'autocmd FileType TelescopePrompt nnoremap <buffer> <C-b> <cmd>Telescope buffers initial_mode=insert<cr>'
vim.cmd 'autocmd FileType TelescopePrompt nnoremap <buffer> <C-f> <cmd>Telescope fd initial_mode=insert<cr>'
vim.cmd 'autocmd FileType TelescopePrompt inoremap <buffer> <C-a> <cmd>Telescope builtin initial_mode=insert<cr>'
vim.cmd 'autocmd FileType TelescopePrompt nnoremap <buffer> <C-a> <cmd>Telescope builtin initial_mode=insert<cr>'
vim.cmd 'augroup END'
-- Telescope }}}
-- Tree sitter {{{
require 'nvim-treesitter.configs'.setup {
ensure_installed = 'all', -- one of "all", "maintained" (parsers with maintainers), or a list of languages
highlight = { enable = true, },
playground = { enable = true, },
yati = { enable = true, },
incremental_selection = {
enable = true,
keymaps = {
init_selection = "gnn",
node_incremental = "+",
scope_incremental = "grc",
node_decremental = "-",
},
},
indent = {
-- disable = { "php" },-- php indent SUCKS A LOT
enable = false,
},
}
vim.api.nvim_set_keymap('x', 'iu', ':lua require"treesitter-unit".select()<CR>', { noremap = true })
vim.api.nvim_set_keymap('x', 'au', ':lua require"treesitter-unit".select(true)<CR>', { noremap = true })
vim.api.nvim_set_keymap('o', 'iu', ':<c-u>lua require"treesitter-unit".select()<CR>', { noremap = true })
vim.api.nvim_set_keymap('o', 'au', ':<c-u>lua require"treesitter-unit".select(true)<CR>', { noremap = true })
--[[ vim.o.foldmethod = 'expr'
vim.o.foldexpr = 'nvim_treesitter#foldexpr()' ]]
--- Tree sitter }}}
-- Indent lines {{{
vim.g.indent_blankline_filetype_exclude = { 'help', 'NvimTree', 'TelescopePrompt', 'lspinfo' }
vim.g.indent_blankline_buftype_exclude = { 'terminal', 'nofile', 'prompt' }
-- indent lines }}}
-- PHP CS FIXER {{{
vim.g.php_cs_fixer_rules = [[
{
"@Symfony":true,
"array_syntax":{"syntax":"short"},
"binary_operator_spaces":{"default":"align_single_space_minimal"},
"fully_qualified_strict_types":false
}
]]
--vim.g.php_cs_fixer_php_path = 'php7' -- Path to PHP
vim.g.php_cs_fixer_path = '/usr/bin/php-cs-fixer' -- Path to PHP
vim.g.php_cs_fixer_enable_default_mapping = 1 -- Enable the mapping by default (<leader>pcd)
vim.g.php_cs_fixer_dry_run = 0 -- Call command with dry-run option
vim.g.php_cs_fixer_verbose = 0
vim.g.php_cs_fixer_version = 3
-- }}}
-- kommentary {{{
kommentary_config = require('kommentary.config')
kommentary_config.configure_language("php", { prefer_single_line_comments = true, })
-- kommentary }}}
-- NEORAY {{{
vim.cmd [[
if exists('g:neoray')
set guifont=Go_Mono:h11
NeoraySet CursorAnimTime 0
NeoraySet Transparency 0.95
NeoraySet TargetTPS 120
NeoraySet ContextMenuOn FALSE
NeoraySet BoxDrawingOn TRUE
NeoraySet WindowSize 100x40
NeoraySet WindowState none
NeoraySet KeyZoomIn <>
NeoraySet KeyZoomOut <>
endif ]]
-- }}}
-- rooter {{{
vim.g.rooter_manual_only = 1
-- }}}
-- null-ls {{{
nls = require "null-ls"
nls.setup({
on_attach = on_attach,
debug = true,
sources = {
nls.builtins.formatting.xmllint,
nls.builtins.diagnostics.sqlfluff,
nls.builtins.diagnostics.phpstan.with({
cwd = function(params)
-- falls back to root if return value is nil
return params.root:match("jopixel") and "www";
end
}),
nls.builtins.formatting.phpcsfixer.with({
extra_args = { "--rules", '{ "@Symfony":true, "nullable_type_declaration_for_default_null_value":true, "array_syntax":{"syntax":"short"}, "binary_operator_spaces":{"default":"align_single_space_minimal"}, "fully_qualified_strict_types":false }' }
}),
nls.builtins.diagnostics.shellcheck,
nls.builtins.formatting.eslint,
-- nls.builtins.diagnostics.eslint,
nls.builtins.code_actions.eslint,
nls.builtins.diagnostics.yamllint,
}
})
-- }}}
-- color handling {{{
term = vim.env.TERM
if (term ~= 'linux' or vim.g.neoray)
then
vim.cmd('set termguicolors')
vim.g.gruvbox_contrast_dark = 'hard'
vim.cmd('colorscheme gruvbox')
vim.cmd 'highlight link Directory GruvboxGreen'
vim.cmd 'highlight link Function GruvboxFg1'
vim.cmd 'highlight link Operator GruvboxFg1'
end
vim.cmd 'highlight link TSVariable Identifier'
vim.cmd 'highlight link TSVariableBuiltin Identifier'
-- }}}
-- {{{ LAYA
vim.cmd [[
augroup layaAbbrevs
autocmd BufRead,BufNewFile ~/jopixel/**/*.php iabbrev <buffer> T $this->obtainer()->translator()->t();<Left><Left>
autocmd BufRead,BufNewFile ~/jopixel/**/*.php iabbrev <buffer> TI $this->obtainer()->translator()->t()<Left>
autocmd BufRead,BufNewFile ~/jopixel/**/*.php iabbrev <buffer> LOG $this->obtainer()->logger()->log();<Left><Left>
autocmd BufRead,BufNewFile ~/jopixel/**/*.php iabbrev <buffer> DEBUG $this->obtainer()->logger()->log('debug', 'debug',);<Left><Left>
autocmd BufRead,BufNewFile ~/jopixel/**/*.php iabbrev <buffer> PROD $this->producer()
autocmd BufRead,BufNewFile ~/jopixel/**/*.php iabbrev <buffer> VIEW \laya\view\view
autocmd BufRead,BufNewFile ~/jopixel/**/*.php iabbrev <buffer> FORM \layalib\view\form\form
autocmd BufRead,BufNewFile ~/jopixel/**/*.php iabbrev <buffer> FILE $this->producer()->file()<Left>
autocmd BufRead,BufNewFile ~/jopixel/**/*.php iabbrev <buffer> LINK $this->producer()->link($this, '')<Left><Left>
autocmd BufRead,BufNewFile ~/jopixel/**/*.php iabbrev <buffer> NOTIF $this->obtainer()->notifications()
augroup END
]]
-- }}} LAYA
-- vim: sw=2: ts=2: fdm=marker: