mirror of
https://codeberg.org/qwjyh/dotfiles.git
synced 2025-06-26 19:29:20 +09:00
217 lines
6.7 KiB
Lua
217 lines
6.7 KiB
Lua
-----------------------------------------------------------
|
|
-- Installing plugin manager 'lazy.nvim'
|
|
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)
|
|
|
|
-- Installing plugins
|
|
require('lazy').setup({
|
|
-- fzf
|
|
{ 'ibhagwan/fzf-lua',
|
|
-- optional icon
|
|
--requires = { 'kyazdan142/nvim-web/devicons' } -- not found
|
|
},
|
|
-- lualine(statusline)
|
|
{
|
|
'nvim-lualine/lualine.nvim',
|
|
dependencies = { 'kyazdani42/nvim-web-devicons', lazy = true }
|
|
},
|
|
'neovim/nvim-lspconfig',
|
|
{
|
|
'hrsh7th/nvim-cmp',
|
|
event = "InsertEnter",
|
|
dependencies = {
|
|
'hrsh7th/cmp-nvim-lsp', -- LSP
|
|
'L3MON4D3/LuaSnip', -- snippets
|
|
'saadparwaiz1/cmp_luasnip',
|
|
'kdheepak/cmp-latex-symbols', -- latex math
|
|
},
|
|
},
|
|
})
|
|
|
|
|
|
-----------------------------------------------------------
|
|
-- basic configurations
|
|
vim.o.number = true
|
|
vim.o.relativenumber = true
|
|
vim.cmd([[
|
|
highlight LineNr cterm=none ctermfg=243
|
|
highlight CursorLineNr cterm=none ctermfg=250
|
|
]])
|
|
vim.o.expandtab = true
|
|
vim.o.tabstop = 4
|
|
vim.o.shiftwidth = 4
|
|
vim.o.autoindent = true
|
|
vim.o.cursorcolumn = true
|
|
vim.o.cursorline = true
|
|
vim.cmd([[
|
|
highlight cursorline term=reverse cterm=none ctermbg=239
|
|
highlight cursorcolumn ctermbg=235
|
|
]])
|
|
vim.o.mouse = 'a'
|
|
vim.o.signcolumn = 'yes'
|
|
vim.o.ignorecase = true
|
|
vim.o.smartcase = true
|
|
|
|
-----------------------------------------------------------
|
|
-- to use PowerShell on Windows
|
|
-- original code from :h powershell
|
|
-- vim script func returns 1/0, while lua evals false only if gets false or nil
|
|
-- so be sure to compare with 1/0
|
|
if vim.fn.has('win32') == 1 then
|
|
if vim.fn.executable('pwsh') == 1 then
|
|
vim.opt.shell = 'pwsh'
|
|
else
|
|
vim.opt.shell = 'powershell'
|
|
end
|
|
vim.opt.shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;'
|
|
vim.opt.shellredir = '-RedirectStandardOutput %s -NoNewWindow -Wait'
|
|
vim.opt.shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
|
|
vim.opt.shellquote = ''
|
|
vim.opt.shellxquote = ''
|
|
end
|
|
|
|
-----------------------------------------------------------
|
|
-- lualine
|
|
require('lualine_setup')
|
|
|
|
-----------------------------------------------------------
|
|
-- LSP config
|
|
|
|
local lspconfig = require 'lspconfig'
|
|
|
|
-- Mapping for language server
|
|
-- See `:help vim.diagnostic.* for documentation on any of the below functions
|
|
local opts = { noremap = true, silent = true }
|
|
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
|
|
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
|
|
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
|
|
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, 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 function
|
|
local bufopts = { noremap = true, silent = true, buffer = bufnr }
|
|
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
|
|
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
|
|
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
|
|
vim.keymap.set('n', 'g1', vim.lsp.buf.implementation, bufopts)
|
|
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
|
|
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
|
|
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
|
|
vim.keymap.set('n', '<space>wl', function()
|
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
end, bufopts)
|
|
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
|
|
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
|
|
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
|
|
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
|
|
vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, bufopts)
|
|
end
|
|
|
|
-- cmp_nvim_lsp supports additional LSP completion capabilities
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
|
|
|
|
|
|
-- Lua
|
|
lspconfig.lua_ls.setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
settings = {
|
|
Lua = {
|
|
runtime = {
|
|
version = 'LuaJIT',
|
|
},
|
|
diagnostics = {
|
|
globals = {'vim'},
|
|
},
|
|
workspace = {
|
|
library = vim.api.nvim_get_runtime_file("", true),
|
|
},
|
|
telemetry = {
|
|
enable = false,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
-- Julia
|
|
lspconfig.julials.setup {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
}
|
|
|
|
-- nvim-cmp setup
|
|
local cmp = require 'cmp'
|
|
local luasnip = require 'luasnip'
|
|
luasnip.config.setup {}
|
|
|
|
cmp.setup {
|
|
snippet = {
|
|
expand = function(args)
|
|
luasnip.lsp_expand(args.body)
|
|
end,
|
|
},
|
|
mapping = cmp.mapping.preset.insert({
|
|
['<C-u>'] = cmp.mapping.scroll_docs(-4), -- Up
|
|
['<C-d>'] = cmp.mapping.scroll_docs(4), -- Down
|
|
['<C-Space>'] = cmp.mapping.complete(),
|
|
['<CR>'] = cmp.mapping.confirm {
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
select = true,
|
|
},
|
|
['<Tab>'] = cmp.mapping(function(fallback)
|
|
if cmp.visible() then
|
|
cmp.select_next_item()
|
|
elseif luasnip.expand_or_jumpable() then
|
|
luasnip.expand_or_jump()
|
|
else
|
|
fallback()
|
|
end
|
|
end, { 'i', 's' }),
|
|
['<S-Tab>'] = cmp.mapping(function(fallback)
|
|
if cmp.visible() then
|
|
cmp.select_prev_item()
|
|
elseif luasnip.jumpable(-1) then
|
|
luasnip.jump(-1)
|
|
else
|
|
fallback()
|
|
end
|
|
end, { 'i', 's' }),
|
|
}),
|
|
sources = {
|
|
{ name = 'nvim_lsp' },
|
|
{ name = 'luasnip' },
|
|
{
|
|
name = 'latex_symbols',
|
|
option = {
|
|
strategy = 0, -- mixed (show the comand and insert the symbol)
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
|
|
-----------------------------------------------------------
|
|
-- Ctrl + P to invoke fzf file search
|
|
vim.api.nvim_set_keymap('n', '<c-P>',
|
|
"<cmd>lua require('fzf-lua').files()<CR>",
|
|
{ noremap = true, silent = true })
|
|
|
|
|
|
|