dotfiles/neovim/init.lua

164 lines
6.3 KiB
Lua
Raw Normal View History

2022-04-25 23:52:08 +02:00
local set = vim.opt
2022-04-27 00:24:23 +02:00
local cmd = vim.api.nvim_command
local au = vim.api.nvim_create_autocmd
local plug = vim.fn['plug#']
2022-04-25 23:52:08 +02:00
vim.call('plug#begin', '~/.config/nvim/plugged')
2022-05-14 04:00:52 +02:00
-- You can use my custom melange build, un-comment here.
-- plug('https://gitlab.com/rawleyIfowler/melange')
-- Yeah I use gruvbox now :L
plug('morhetz/gruvbox')
2022-04-30 03:11:27 +02:00
plug('ap/vim-css-color')
2022-04-30 18:24:31 +02:00
plug('ap/vim-buftabline')
2022-05-04 04:20:15 +02:00
plug('dag/vim-fish')
2022-05-21 22:33:15 +02:00
plug('kassio/neoterm')
plug('tpope/vim-dispatch')
plug('radenling/vim-dispatch-neovim')
2022-04-28 05:31:41 +02:00
plug('clojure-vim/clojure.vim', {['for'] = 'clojure'})
2022-05-21 22:33:15 +02:00
plug('Olical/conjure', {['for'] = 'clojure'})
plug('tpope/vim-fireplace', {['for'] = 'clojure'})
plug('guns/vim-clojure-highlight', {['for'] = 'clojure'})
plug('guns/vim-clojure-static', {['for'] = 'clojure'})
plug('clojure-vim/vim-jack-in', {['for'] = 'clojure'})
plug('luochen1990/rainbow')
2022-04-30 03:11:27 +02:00
plug('scrooloose/nerdtree', { on = 'NERDTreeToggle'})
plug('fatih/vim-go', { ['for'] = 'go' })
plug('tree-sitter/tree-sitter')
2022-04-27 00:24:23 +02:00
plug('tpope/vim-surround')
plug('neovim/nvim-lsp')
plug('neovim/nvim-lspconfig')
2022-05-27 22:52:29 +02:00
plug('williamboman/nvim-lsp-installer')
plug('mfussenegger/nvim-jdtls')
2022-04-27 00:24:23 +02:00
plug('junegunn/goyo.vim', {['for'] = 'markdown'})
plug('junegunn/fzf', {['dir'] = '~/.fzf', ['do'] = './install --all'})
plug('junegunn/fzf.vim')
2022-04-28 05:31:41 +02:00
plug('jiangmiao/auto-pairs')
2022-04-27 00:24:23 +02:00
plug('docunext/closetag.vim')
2022-04-29 21:17:58 +02:00
plug('norcalli/nvim_utils')
2022-04-30 03:11:27 +02:00
plug('hrsh7th/nvim-cmp')
plug('hrsh7th/cmp-buffer')
plug('hrsh7th/cmp-nvim-lsp')
2022-05-21 22:33:15 +02:00
plug('saadparwaiz1/cmp_luasnip')
2022-04-30 03:11:27 +02:00
plug('l3mon4d3/luasnip')
2022-05-04 04:20:15 +02:00
plug('leafgarland/typescript-vim', {['for'] = 'typescript'})
2022-04-25 23:52:08 +02:00
vim.call('plug#end')
2022-05-27 22:52:29 +02:00
pcall(require, 'nvim_utils')
2022-04-30 03:11:27 +02:00
local cmp = require('cmp')
2022-04-25 23:52:08 +02:00
-- Basic editor configurations
set.tabstop = 4
set.shiftwidth = 4
set.expandtab = true
set.number = true
set.termguicolors = true
set.autoindent = true
set.autowrite = true
set.ai = true
set.wildignore = {'*/cache/*', '*/tmp*'}
-- Keybindings
2022-04-30 03:11:27 +02:00
function map(mode, lhs, rhs, opts)
options = {}
2022-04-29 21:17:58 +02:00
if opts then
options = vim.tbl_extend("force", options, opts)
end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
2022-04-30 18:26:44 +02:00
---- Cycling through buffers
map('n', '<C-h>', ':bprev<cr>', { noremap = true })
map('n', '<C-l>', ':bnext<cr>', { noremap = true })
2022-04-25 23:52:08 +02:00
---- NERDTree
2022-04-30 03:11:27 +02:00
map('n', '<S-w>', ':NERDTreeToggle<cr>', { noremap = true })
map('n', '<S-q>', ':NERDTreeClose<cr>', { noremap = true })
2022-04-25 23:52:08 +02:00
---- Ripgrep
2022-04-30 03:11:27 +02:00
map('n', '<C-f>', ':Rg<cr>')
---- Auto-complete
cmp.setup({
snippet = {
expand = function(a)
-- Enable the lua snips engine
require('luasnip').lsp_expand(a.body)
end
},
mapping = cmp.mapping.preset.insert({
['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }),
['<CR>'] = cmp.mapping.confirm({ select = true }),
['<C-Space>'] = cmp.mapping.complete()
}),
sources = {
-- Get completions from these sources
{ name = 'buffer' },
{ name = 'nvim_lsp' },
{ name = 'luasnip' }
}
})
2022-04-25 23:52:08 +02:00
-- Colors
vim.cmd('syntax enable')
2022-05-14 04:00:52 +02:00
vim.cmd('colo gruvbox')
vim.o.background = 'light'
2022-05-21 22:33:15 +02:00
-- Rainbow Parens for Clojure, and Lisp
2022-04-29 21:17:58 +02:00
vim.cmd([[
2022-05-27 22:52:29 +02:00
filetype on
filetype plugin on
filetype plugin indent on
autocmd Filetype clojure,clj,lisp,lsp,cl,l :RainbowToggle
2022-04-29 21:17:58 +02:00
]])
2022-05-21 22:33:15 +02:00
-- Auto complete
local opts = { noremap=true, silent=true }
map('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
map('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
map('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
map('n', '<space>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
local on_attach = function(client, bufnr)
2022-05-27 22:52:29 +02:00
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
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)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
2022-05-21 22:33:15 +02:00
end
local cmp_capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
local servers = { 'clojure_lsp', 'gopls', 'clangd', 'tsserver' }
2022-05-27 22:52:29 +02:00
for _, lsp in pairs(servers) do
2022-05-21 22:33:15 +02:00
require('lspconfig')[lsp].setup {
on_attach = on_attach,
capabilities = cmp_capabilities,
flags = {
debounce_text_changes = 150,
}
}
end
2022-05-27 22:52:29 +02:00
-- Java auto complete/LSP
local jdtls_cfg = {
cmd = {
'java',
'-Declipse.application=org.eclipse.jdt.ls.core.id1',
'-Dosgi.bundles.defaultStartLevel=4',
'-Declipse.product=org.eclipse.jdt.ls.core.product',
'-Dlog.protocol=true',
'-Dlog.level=ALL',
'-Xms1g',
'--add-modules=ALL-SYSTEM',
'--add-opens', 'java.base/java.util=ALL-UNNAMED',
'--add-opens', 'java.base/java.lang=ALL-UNNAMED',
'-jar', '~/.local/share/nvim/lsp_servers/jdtls/plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.2.400.v20211117-0650.jar',
'-configuration', '~/.local/share/nvim/lsp_servers/jdtls/config_mac'
},
root_dir = require('jdtls.setup').find_root({'.git', 'mvnw', 'gradlew'})
}
if vim.bo.filetype == 'java' then
require('jdtls').start_or_attach(jdtls_cfg)
end
2022-05-04 04:20:15 +02:00
-- 2 Tab space standard languages
2022-05-21 22:33:15 +02:00
-- Clojure and Common Lisp style is 2 space indent
2022-05-04 04:20:15 +02:00
vim.cmd([[
2022-05-27 22:52:29 +02:00
autocmd Filetype clojure,clj,lisp,lsp,cl,l,javascript,js,typescript,ts setlocal tabstop=2 shiftwidth=2
2022-05-04 04:20:15 +02:00
]])