Refactor neovim config (#2)
Changes include: - [x] Use init.lua instead of init.vim - Some keybindings are still to be converted - [x] Use packer as a package manager instead of vim-plug - [ ] Use built-in lsp instead of coc.nvim - [x] Set up language servers - [x] Completion - [x] Formatting (previously coc-prettier, now neoformat) - [ ] Snippets - [ ] Replace fzf with telescope.nvim - [x] Implement treesitter syntax highlighting - More info: https://github.com/nvim-treesitter/nvim-treesitter Note that this requires neovim nightly until 0.5 is released Reviewed-on: #2 Co-authored-by: Marko Korhonen <marko@korhonen.cc> Co-committed-by: Marko Korhonen <marko@korhonen.cc>
This commit is contained in:
parent
b4f2b57060
commit
95a99aa1bf
24 changed files with 492 additions and 525 deletions
7
home/.config/nvim/lua/autocmd.lua
Normal file
7
home/.config/nvim/lua/autocmd.lua
Normal file
|
@ -0,0 +1,7 @@
|
|||
local cmd = vim.cmd
|
||||
|
||||
-- Remap exit terminal mode to esc
|
||||
cmd('au TermOpen * tnoremap <buffer> <Esc> <c-\\><c-n>')
|
||||
|
||||
-- Fix YAML indentation
|
||||
cmd('au FileType yaml setlocal ts=2 sts=2 sw=2 expandtab')
|
27
home/.config/nvim/lua/keybinds.lua
Normal file
27
home/.config/nvim/lua/keybinds.lua
Normal file
|
@ -0,0 +1,27 @@
|
|||
local function map(mode, lhs, rhs, opts)
|
||||
local options = {noremap = true}
|
||||
if opts then options = vim.tbl_extend('force', options, opts) end
|
||||
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
|
||||
end
|
||||
|
||||
-- Open/close tree browser
|
||||
map('n', '<C-Tab>', '<cmd>NvimTreeToggle<CR>')
|
||||
|
||||
-- Telescope
|
||||
map('n', '<C-f>', '<cmd>Telescope find_files find_command=fd,-Ht,f<CR>')
|
||||
map('n', '<C-g>', '<cmd>Telescope live_grep<CR>')
|
||||
|
||||
-- Completion
|
||||
-- Navigate completions with tab and shift tab
|
||||
map('i', '<S-Tab>', 'pumvisible() ? "\\<C-p>" : "\\<Tab>"', {expr = true})
|
||||
map('i', '<Tab>', 'pumvisible() ? "\\<C-n>" : "\\<Tab>"', {expr = true})
|
||||
|
||||
-- Navigate between buffers
|
||||
map('n', '<C-N>', ':bn<CR>', {silent = true})
|
||||
map('n', '<C-B>', ':bp<CR>', {silent = true})
|
||||
|
||||
-- Navigate between splits
|
||||
map('n', '<C-H>', '<C-W><C-H>')
|
||||
map('n', '<C-J>', '<C-W><C-J>')
|
||||
map('n', '<C-K>', '<C-W><C-K>')
|
||||
map('n', '<C-L>', '<C-W><C-L>')
|
1
home/.config/nvim/lua/pluginconf/bufferline.lua
Normal file
1
home/.config/nvim/lua/pluginconf/bufferline.lua
Normal file
|
@ -0,0 +1 @@
|
|||
require("bufferline").setup{}
|
4
home/.config/nvim/lua/pluginconf/completion.lua
Normal file
4
home/.config/nvim/lua/pluginconf/completion.lua
Normal file
|
@ -0,0 +1,4 @@
|
|||
vim.o.completeopt = 'menuone,noinsert,noselect'
|
||||
|
||||
-- Enable for all buffers (for now)
|
||||
vim.api.nvim_command('autocmd BufEnter * lua require\'completion\'.on_attach()')
|
1
home/.config/nvim/lua/pluginconf/indent-blankline.lua
Normal file
1
home/.config/nvim/lua/pluginconf/indent-blankline.lua
Normal file
|
@ -0,0 +1 @@
|
|||
require('indent_blankline').setup {filetype_exclude = {'help'}}
|
143
home/.config/nvim/lua/pluginconf/lsp.lua
Normal file
143
home/.config/nvim/lua/pluginconf/lsp.lua
Normal file
|
@ -0,0 +1,143 @@
|
|||
-- List of servers to install
|
||||
local required_servers = {
|
||||
"css", "html", "java", "json", "lua", "rust", "yaml", "dockerfile", "latex",
|
||||
"bash", "typescript", "php"
|
||||
}
|
||||
|
||||
-- keymaps
|
||||
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
|
||||
|
||||
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||
|
||||
-- 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('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', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
||||
buf_set_keymap('n', '<space>e',
|
||||
'<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>',
|
||||
opts)
|
||||
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>',
|
||||
opts)
|
||||
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>',
|
||||
opts)
|
||||
buf_set_keymap('n', '<space>q',
|
||||
'<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
|
||||
|
||||
-- Set some keybinds conditional on server capabilities
|
||||
if client.resolved_capabilities.document_formatting then
|
||||
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>",
|
||||
opts)
|
||||
elseif client.resolved_capabilities.document_range_formatting then
|
||||
buf_set_keymap("n", "<space>f",
|
||||
"<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
|
||||
end
|
||||
|
||||
-- Set autocommands conditional on server_capabilities
|
||||
if client.resolved_capabilities.document_highlight then
|
||||
vim.api.nvim_exec([[
|
||||
augroup lsp_document_highlight
|
||||
autocmd! * <buffer>
|
||||
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
|
||||
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
||||
augroup END
|
||||
]], false)
|
||||
end
|
||||
end
|
||||
|
||||
-- Configure lua language server for neovim development
|
||||
local lua_settings = {
|
||||
Lua = {
|
||||
runtime = {
|
||||
-- LuaJIT in the case of Neovim
|
||||
version = 'LuaJIT',
|
||||
path = vim.split(package.path, ';')
|
||||
},
|
||||
diagnostics = {
|
||||
-- Get the language server to recognize the `vim` global
|
||||
globals = {'vim'}
|
||||
},
|
||||
workspace = {
|
||||
-- Make the server aware of Neovim runtime files
|
||||
library = {
|
||||
[vim.fn.expand('$VIMRUNTIME/lua')] = true,
|
||||
[vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-- config that activates keymaps and enables snippet support
|
||||
local function make_config()
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
return {
|
||||
-- enable snippet support
|
||||
capabilities = capabilities,
|
||||
-- map buffer local keybindings when the language server attaches
|
||||
on_attach = on_attach
|
||||
}
|
||||
end
|
||||
|
||||
-- lsp-install
|
||||
local function setup_servers()
|
||||
require'lspinstall'.setup()
|
||||
|
||||
-- get all installed servers
|
||||
local servers = require'lspinstall'.installed_servers()
|
||||
|
||||
-- install server if not already installed but required
|
||||
-- for _, server in pairs(required_servers) do
|
||||
-- if not vim.tbl_contains(servers) then
|
||||
-- require'lspinstall'.install_server(server)
|
||||
-- end
|
||||
-- end
|
||||
|
||||
-- Refresh servers list in case of newly installed servers
|
||||
servers = require'lspinstall'.installed_servers()
|
||||
|
||||
for _, server in pairs(servers) do
|
||||
local config = make_config()
|
||||
|
||||
-- language specific config
|
||||
if server == "lua" then config.settings = lua_settings end
|
||||
require'lspconfig'[server].setup(config)
|
||||
|
||||
-- Java LSP client is started by the plugin nvim-jdtls
|
||||
if server == "java" then return end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
setup_servers()
|
||||
|
||||
require('jdtls').start_or_attach({
|
||||
cmd = {'java-lsp.sh'},
|
||||
root_dir = require('jdtls.setup').find_root({'gradle.build', 'pom.xml'})
|
||||
})
|
||||
|
||||
-- Automatically reload after `:LspInstall <server>` so we don't have to restart neovim
|
||||
require'lspinstall'.post_install_hook = function()
|
||||
setup_servers() -- reload installed servers
|
||||
vim.cmd("bufdo e") -- this triggers the FileType autocmd that starts the server
|
||||
end
|
3
home/.config/nvim/lua/pluginconf/lualine.lua
Normal file
3
home/.config/nvim/lua/pluginconf/lualine.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
require'lualine'.setup {
|
||||
options = {theme = 'onedark'},
|
||||
}
|
36
home/.config/nvim/lua/pluginconf/telescope.lua
Normal file
36
home/.config/nvim/lua/pluginconf/telescope.lua
Normal file
|
@ -0,0 +1,36 @@
|
|||
require('telescope').setup {
|
||||
defaults = {
|
||||
vimgrep_arguments = {
|
||||
'rg', '--hidden', '--color=never', '--no-heading',
|
||||
'--with-filename', '--line-number', '--column', '--smart-case'
|
||||
},
|
||||
prompt_prefix = "> ",
|
||||
selection_caret = "> ",
|
||||
entry_prefix = " ",
|
||||
initial_mode = "insert",
|
||||
selection_strategy = "reset",
|
||||
sorting_strategy = "descending",
|
||||
layout_strategy = "horizontal",
|
||||
layout_config = {
|
||||
horizontal = {mirror = false},
|
||||
vertical = {mirror = false}
|
||||
},
|
||||
file_sorter = require'telescope.sorters'.get_fuzzy_file,
|
||||
file_ignore_patterns = {},
|
||||
generic_sorter = require'telescope.sorters'.get_generic_fuzzy_sorter,
|
||||
winblend = 0,
|
||||
border = {},
|
||||
borderchars = {'─', '│', '─', '│', '╭', '╮', '╯', '╰'},
|
||||
color_devicons = true,
|
||||
use_less = true,
|
||||
path_display = {},
|
||||
set_env = {['COLORTERM'] = 'truecolor'}, -- default = nil,
|
||||
file_previewer = require'telescope.previewers'.vim_buffer_cat.new,
|
||||
grep_previewer = require'telescope.previewers'.vim_buffer_vimgrep.new,
|
||||
qflist_previewer = require'telescope.previewers'.vim_buffer_qflist.new,
|
||||
|
||||
-- Developer configurations: Not meant for general override
|
||||
buffer_previewer_maker = require'telescope.previewers'.buffer_previewer_maker
|
||||
},
|
||||
pickers = {find_files = {find_command = {"fd", "-Ht", "f"}}}
|
||||
}
|
6
home/.config/nvim/lua/pluginconf/treesitter.lua
Normal file
6
home/.config/nvim/lua/pluginconf/treesitter.lua
Normal file
|
@ -0,0 +1,6 @@
|
|||
require'nvim-treesitter.configs'.setup {
|
||||
ensure_installed = 'maintained',
|
||||
highlight = {enable = true},
|
||||
indent = {enable = true},
|
||||
incremental_selection = {enable = true}
|
||||
}
|
90
home/.config/nvim/lua/pluginmanager.lua
Normal file
90
home/.config/nvim/lua/pluginmanager.lua
Normal file
|
@ -0,0 +1,90 @@
|
|||
local fn = vim.fn
|
||||
local cmd = vim.cmd
|
||||
|
||||
-- Install packer if it's not yet installed
|
||||
local install_path = fn.stdpath('data') .. '/site/pack/packer/opt/packer.nvim'
|
||||
local packer_not_installed = fn.empty(fn.glob(install_path))
|
||||
|
||||
if packer_not_installed > 0 then
|
||||
print('Packer is not installed, cloning it now...')
|
||||
cmd('silent !git clone https://github.com/wbthomason/packer.nvim ' ..
|
||||
install_path)
|
||||
end
|
||||
|
||||
-- Configure packer
|
||||
cmd 'packadd packer.nvim'
|
||||
local use = require('packer').use
|
||||
require('packer').startup(function()
|
||||
|
||||
-- The plugin manager itself
|
||||
use {'wbthomason/packer.nvim', opt = true}
|
||||
|
||||
-- Colorscheme
|
||||
use 'monsonjeremy/onedark.nvim'
|
||||
|
||||
-- Statusline
|
||||
use {
|
||||
'hoob3rt/lualine.nvim',
|
||||
requires = {'kyazdani42/nvim-web-devicons', opt = true}
|
||||
}
|
||||
|
||||
-- Tabline/bufferline
|
||||
use {
|
||||
'akinsho/nvim-bufferline.lua',
|
||||
requires = 'kyazdani42/nvim-web-devicons'
|
||||
}
|
||||
|
||||
-- Indent characters
|
||||
--use "lukas-reineke/indent-blankline.nvim"
|
||||
|
||||
-- Tree explorer
|
||||
use {'kyazdani42/nvim-tree.lua', requires = 'kyazdani42/nvim-web-devicons'}
|
||||
|
||||
-- Telescope
|
||||
use {
|
||||
'nvim-telescope/telescope.nvim',
|
||||
requires = {{'nvim-lua/popup.nvim'}, {'nvim-lua/plenary.nvim'}}
|
||||
}
|
||||
|
||||
-- Do stuff as sudo
|
||||
use 'lambdalisue/suda.vim'
|
||||
|
||||
-- Read editorconfig settings
|
||||
use 'editorconfig/editorconfig-vim'
|
||||
|
||||
-- Configs for built-in LSP
|
||||
use 'neovim/nvim-lspconfig'
|
||||
|
||||
-- Install LSP executables
|
||||
use 'kabouzeid/nvim-lspinstall'
|
||||
|
||||
-- Extensions for eclipse.jdt.ls
|
||||
use 'mfussenegger/nvim-jdtls'
|
||||
|
||||
-- Completion framework
|
||||
use 'nvim-lua/completion-nvim'
|
||||
|
||||
-- treesitter syntax highlight
|
||||
use {
|
||||
'nvim-treesitter/nvim-treesitter',
|
||||
branch = '0.5-compat',
|
||||
run = ':TSUpdate'
|
||||
}
|
||||
|
||||
-- Syntax highlighting for languages
|
||||
-- that are not supported by treesitter
|
||||
use 'sheerun/vim-polyglot'
|
||||
|
||||
-- Formatter plugin
|
||||
use 'sbdchd/neoformat'
|
||||
|
||||
-- Make editing passwords safer
|
||||
use {
|
||||
'https://git.zx2c4.com/password-store',
|
||||
rtp = 'contrib/vim/redact_pass.vim'
|
||||
}
|
||||
|
||||
end)
|
||||
|
||||
-- Install plugins if packer was not installed
|
||||
if packer_not_installed > 0 then cmd 'PackerInstall' end
|
61
home/.config/nvim/lua/settings.lua
Normal file
61
home/.config/nvim/lua/settings.lua
Normal file
|
@ -0,0 +1,61 @@
|
|||
local o = vim.o
|
||||
local g = vim.g
|
||||
local cmd = vim.cmd
|
||||
|
||||
------ Appearance ------
|
||||
|
||||
-- Set colorscheme
|
||||
require('onedark').setup()
|
||||
|
||||
-- True colors
|
||||
o.termguicolors = true
|
||||
|
||||
-- Floating window transparency
|
||||
o.winblend = 10
|
||||
|
||||
-- Remove extra line
|
||||
o.cmdheight = 1
|
||||
|
||||
-- Always show signcolumn
|
||||
o.signcolumn = 'yes'
|
||||
|
||||
-- Blinking cursor
|
||||
cmd 'set guicursor=i:ver1'
|
||||
cmd 'set guicursor+=a:blinkon1'
|
||||
|
||||
-- Gutter and cursoline bg transparent
|
||||
cmd 'highlight CursorLineNr guibg=transparent'
|
||||
cmd 'highlight SignColumn guibg=transparent'
|
||||
|
||||
------ Misc -------
|
||||
|
||||
-- Use suda by default
|
||||
g.suda_smart_edit = 1
|
||||
|
||||
|
||||
-- Split direction
|
||||
o.splitbelow = true
|
||||
o.splitright = true
|
||||
|
||||
|
||||
-- Case insensitive search
|
||||
o.ignorecase = true
|
||||
o.smartcase = true
|
||||
|
||||
-- Use mouse
|
||||
o.mouse = 'a'
|
||||
|
||||
-- Use system clipboard
|
||||
o.clipboard = 'unnamedplus'
|
||||
|
||||
-- Autoindent and syntax higlight
|
||||
o.autoindent = true
|
||||
o.smartindent = true
|
||||
o.tabstop = 4
|
||||
o.shiftwidth = 4
|
||||
cmd 'syntax on'
|
||||
cmd 'filetype on'
|
||||
cmd 'filetype plugin indent on'
|
||||
|
||||
-- Disable auto commenting
|
||||
o.formatoptions = 'cro'
|
Loading…
Add table
Add a link
Reference in a new issue