Switch to new Lua-based config & treesitter in nvim

This commit is contained in:
Felix Suchert 2023-06-06 20:53:32 +02:00
parent e66af64c89
commit 7790fbdf0f
Signed by: feliix42
GPG key ID: 24363525EA0E8A99
6 changed files with 278 additions and 43 deletions

45
tycho/nvim/init.lua Normal file
View file

@ -0,0 +1,45 @@
require('plugins')
-- comma as leader
vim.g.mapleader = ","
-- load legacy options
vim.cmd([[
so ~/.config/nvim/legacy.vim
]])
require('completion')
require('lsp-setup')
-- nvim-treesitter
require('nvim-treesitter.configs').setup {
ensure_installed = {
"c", "lua", "vim", "help", "query",
"gitattributes", "gitcommit", "gitignore",
"json", "markdown", "yaml", "toml",
"make", "nix", "bash",
"php", "html", "css",
"python", "rust",
},
highlight = {
enable = true,
},
}
-- lualine theme
require('lualine').setup {
options = {
theme = 'gruvbox',
-- no separators between lualine elements
section_separators = '',
component_separators = ''
}
}
vim.opt.termguicolors = true
require("bufferline").setup{}
-- settings for neovide
if vim.g.neovide then
vim.o.guifont = "Iosevka Term Medium:h12"
end

View file

@ -3,61 +3,61 @@
" syntax on " syntax on
" enable autocompletion of ale " enable autocompletion of ale
let g:ale_completion_enabled = 1 "let g:ale_completion_enabled = 1
" disable latex linting from ale as i've got my own plugin for that " disable latex linting from ale as i've got my own plugin for that
let g:ale_linters = {'rust': ['analyzer'], 'tex': []} "let g:ale_linters = {'rust': ['analyzer'], 'tex': []}
let g:ale_fixers = {'c': ['clang-format']} "let g:ale_fixers = {'c': ['clang-format']}
" Initialize plugin system "" Initialize plugin system
call plug#begin(stdpath('data') . '/plugged') "call plug#begin(stdpath('data') . '/plugged')
" Make sure you use single quotes "" Make sure you use single quotes
" Shorthand notation; fetches https://github.com/morhetz/gruvbox "" Shorthand notation; fetches https://github.com/morhetz/gruvbox
" Plug 'morhetz/gruvbox' "" Plug 'morhetz/gruvbox'
Plug 'drewtempelmeyer/palenight.vim' "Plug 'drewtempelmeyer/palenight.vim'
" Any valid git URL is allowed "" Any valid git URL is allowed
Plug 'https://github.com/scrooloose/nerdcommenter.git' "Plug 'https://github.com/scrooloose/nerdcommenter.git'
" On-demand loading for languages "" On-demand loading for languages
Plug 'rust-lang/rust.vim', { 'for': 'rust' } "Plug 'rust-lang/rust.vim', { 'for': 'rust' }
Plug 'cespare/vim-toml', { 'for': 'toml' } "Plug 'cespare/vim-toml', { 'for': 'toml' }
Plug 'keith/swift.vim', { 'for': 'swift' } "Plug 'keith/swift.vim', { 'for': 'swift' }
" Plug 'neovimhaskell/haskell-vim', { 'for': 'haskell' } "" Plug 'neovimhaskell/haskell-vim', { 'for': 'haskell' }
Plug 'vim-syntastic/syntastic' "Plug 'vim-syntastic/syntastic'
Plug 'vim-airline/vim-airline' "Plug 'vim-airline/vim-airline'
Plug 'tpope/vim-fugitive' "Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter' "Plug 'airblade/vim-gitgutter'
Plug 'justinmk/vim-sneak' "Plug 'justinmk/vim-sneak'
Plug 'lervag/vimtex' "Plug 'lervag/vimtex'
Plug 'editorconfig/editorconfig-vim' "Plug 'editorconfig/editorconfig-vim'
Plug 'LnL7/vim-nix' "Plug 'LnL7/vim-nix'
Plug 'xevz/vim-squirrel' "Plug 'xevz/vim-squirrel'
Plug 'preservim/nerdtree' "Plug 'preservim/nerdtree'
" Plugin outside ~/.vim/plugged with post-update hook "" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } "Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim' "Plug 'junegunn/fzf.vim'
" ale language server client "" ale language server client
Plug 'dense-analysis/ale' "Plug 'dense-analysis/ale'
" Initialize plugin system "" Initialize plugin system
call plug#end() "call plug#end()
" open fzf files in new tab instead of new buffer " open fzf files in new tab instead of new buffer
"command! -bang -nargs=? -complete=dir Files "command! -bang -nargs=? -complete=dir Files
"\ call fzf#vim#files(<q-args>, {'sink': 'tabedit', 'options': ['--info=inline', '--preview', '~/.vim/plugged/fzf.vim/bin/preview.sh {}']}, <bang>0) "\ call fzf#vim#files(<q-args>, {'sink': 'tabedit', 'options': ['--info=inline', '--preview', '~/.vim/plugged/fzf.vim/bin/preview.sh {}']}, <bang>0)
set laststatus=2 "set laststatus=2
let g:airline#extensions#tabline#enabled = 1 "let g:airline#extensions#tabline#enabled = 1
"let g:airline_powerline_fonts = 1 "let g:airline_powerline_fonts = 1
" window switching by # " window switching by #
let g:airline_section_c = '[%{winnr()}] %t' "let g:airline_section_c = '[%{winnr()}] %t'
nnoremap <space>1 1<C-w>w nnoremap <space>1 1<C-w>w
nnoremap <space>2 2<C-w>w nnoremap <space>2 2<C-w>w
nnoremap <space>3 3<C-w>w nnoremap <space>3 3<C-w>w
@ -74,9 +74,6 @@ nnoremap <space>0 10<C-w>w
set backspace=indent,eol,start set backspace=indent,eol,start
" map the leader key to ,
let mapleader=","
let $FZF_DEFAULT_COMMAND = 'rg --files --hidden' let $FZF_DEFAULT_COMMAND = 'rg --files --hidden'
" Cycling through windows and tabs " Cycling through windows and tabs
@ -110,8 +107,8 @@ set hidden
" tex configuration " tex configuration
let g:tex_flavor='latex' let g:tex_flavor='latex'
" Optics " Optics
colorscheme palenight "gruvbox "colorscheme palenight "gruvbox
set background=dark " Setting dark mode "set background=dark " Setting dark mode
set number set number
set relativenumber set relativenumber

View file

@ -0,0 +1,67 @@
-- Set up nvim-cmp.
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
end,
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }),
['<S-Tab>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c' }),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
['<CR>'] = cmp.mapping.confirm({ select = false }), -- Accept currently elected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'vsnip' }, -- For vsnip users.
}, {
{ name = 'buffer' },
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
-- Set up lspconfig.
--local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
--require('lspconfig')['<YOUR_LSP_SERVER>'].setup {
--capabilities = capabilities
--}

View file

@ -0,0 +1,71 @@
-- Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap=true, silent=true }
vim.api.nvim_set_keymap('n', ',e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
vim.api.nvim_set_keymap('n', 'ge', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
vim.api.nvim_set_keymap('n', 'gE', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
vim.api.nvim_set_keymap('n', ',q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
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', 's', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'i', ',s', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', ',wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', ',wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', ',wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', ',D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', ',rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', ',qf', '<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)
vim.api.nvim_buf_set_keymap(bufnr, 'n', ',F', '<cmd>lua vim.lsp.buf.format { async = true }<CR>', opts)
end
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { 'clangd', 'rust_analyzer', 'nil_ls' }
for _, lsp in pairs(servers) do
require('lspconfig')[lsp].setup {
on_attach = on_attach,
flags = {
-- This will be the default in neovim 0.7+
debounce_text_changes = 150,
}
}
end
require('lspconfig').clangd.setup{
on_attach = on_attach,
cmd = {
"clangd",
"--background-index",
"--pch-storage=memory",
"--clang-tidy",
"--suggest-missing-includes",
"--all-scopes-completion",
"--pretty",
"--header-insertion=never",
"-j=4",
"--inlay-hints",
"--header-insertion-decorators",
},
filetypes = {"c", "cpp", "objc", "objcpp"},
-- root_dir = utils.root_pattern("compile_commands.json", "compile_flags.txt", ".git")
init_option = { fallbackFlags = { "-std=c++2a" } }
}
local capabilities = require('cmp_nvim_lsp').default_capabilities()
require('lspconfig').pyright.setup {
on_attach = on_attach,
capabilities = capabilities
}

View file

@ -0,0 +1,54 @@
return require('packer').startup(function(use)
-- Packer can manage itself
use 'wbthomason/packer.nvim'
-- theme
-- use {'morhetz/gruvbox', config = function() vim.cmd.colorscheme("gruvbox") end }
use {'luisiacc/gruvbox-baby', config = function() vim.cmd.colorscheme("gruvbox-baby") end }
-- use 'drewtempelmeyer/palenight.vim'
use {
'nvim-lualine/lualine.nvim',
requires = { 'nvim-tree/nvim-web-devicons', opt = true }
}
use {'akinsho/bufferline.nvim', tag = "*", requires = 'nvim-tree/nvim-web-devicons'}
use 'scrooloose/nerdcommenter'
use 'sbdchd/neoformat'
-- fuzzy file finder
use { 'junegunn/fzf', run = function() vim.fn['fzf#install'](0) end }
use 'junegunn/fzf.vim'
-- -- On-demand loading for languages
use 'rust-lang/rust.vim'
-- use 'cespare/vim-toml
-- use 'keith/swift.vim'
-- use 'neovimhaskell/haskell-vim'
-- Post-install/update hook with neovim command
use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }
-- LSP plugins
use 'neovim/nvim-lspconfig'
use 'hrsh7th/cmp-nvim-lsp'
use 'hrsh7th/cmp-buffer'
use 'hrsh7th/cmp-path'
use 'hrsh7th/cmp-cmdline'
use 'hrsh7th/nvim-cmp'
-- snippet engine
use 'hrsh7th/vim-vsnip'
use 'tpope/vim-fugitive'
-- use 'vim-syntastic/syntastic'
-- use 'vim-airline/vim-airline'
-- use 'airblade/vim-gitgutter'
-- use 'justinmk/vim-sneak'
-- use 'lervag/vimtex'
-- use 'editorconfig/editorconfig-vim'
-- use 'LnL7/vim-nix'
-- use 'xevz/vim-squirrel'
-- use 'preservim/nerdtree'
--
-- -- ale language server client
-- use 'dense-analysis/ale'
end)

View file

@ -105,7 +105,7 @@ font:
# - (macOS) Menlo # - (macOS) Menlo
# - (Linux) monospace # - (Linux) monospace
# - (Windows) Consolas # - (Windows) Consolas
family: "Iosevka Term Medium" family: "IosevkaTerm NFM Medium"
#family: "Hack Nerd Font" #family: "Hack Nerd Font"
#family: "Menlo" #family: "Menlo"
@ -341,7 +341,8 @@ working_directory: None
enable_experimental_conpty_backend: false enable_experimental_conpty_backend: false
# Send ESC (\x1b) before characters when alt is pressed. # Send ESC (\x1b) before characters when alt is pressed.
alt_send_esc: true #alt_send_esc: true
# window.option_as_alt is the new option for this!
debug: debug:
# Display the time it takes to redraw each frame. # Display the time it takes to redraw each frame.