tidy, new packages

master
george 1 week ago
parent 49aa8c5316
commit 33b55eb463

@ -24,32 +24,52 @@ set signcolumn=yes
set colorcolumn=110
set list
autocmd BufWritePost *.tex !echo | pdflatex % >/dev/null
call plug#begin("~/.nvim/plugged")
Plug 'rust-lang/rust.vim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'neovim/nvim-lspconfig'
Plug 'mbbill/undotree'
Plug 'sbdchd/neoformat'
Plug 'folke/tokyonight.nvim', { 'branch': 'main' }
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-telescope/telescope-fzy-native.nvim'
Plug 'psliwka/vim-smoothie'
Plug 'darrikonn/vim-gofmt', { 'do': ':GoUpdateBinaries' }
"Plug 'fatih/vim-go'
Plug 'preservim/nerdtree'
Plug 'udalov/kotlin-vim'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/nvim-cmp'
Plug 'L3MON4D3/LuaSnip'
Plug 'EdenEast/nightfox.nvim'
Plug 'itchyny/lightline.vim'
Plug 'tpope/vim-fugitive'
Plug 'simrat39/rust-tools.nvim'
Plug 'rust-lang/rust.vim' " Rust filetype support
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " Tree-sitter highlighting
Plug 'neovim/nvim-lspconfig' " LSP client configs
Plug 'mbbill/undotree' " Undo history browser
Plug 'sbdchd/neoformat' " Formatter fallback
Plug 'folke/tokyonight.nvim', { 'branch': 'main' } " Active colour scheme
Plug 'nvim-lua/plenary.nvim' " Lua utility library
Plug 'nvim-telescope/telescope.nvim' " Fuzzy finder UI
Plug 'nvim-telescope/telescope-fzy-native.nvim' " Telescope sorter
Plug 'nvim-telescope/telescope-ui-select.nvim' " Telescope vim.ui.select bridge
Plug 'debugloop/telescope-undo.nvim' " Undo history picker
Plug 'psliwka/vim-smoothie' " Smooth scrolling
Plug 'darrikonn/vim-gofmt', { 'do': ':GoUpdateBinaries' } " Go formatting helpers
Plug 'stevearc/oil.nvim' " Primary file explorer
Plug 'nvim-tree/nvim-web-devicons' " Filetype icons
Plug 'udalov/kotlin-vim' " Kotlin syntax support
Plug 'hrsh7th/cmp-nvim-lsp' " LSP completion source
Plug 'hrsh7th/cmp-buffer' " Buffer completion source
Plug 'hrsh7th/cmp-path' " Path completion source
Plug 'hrsh7th/cmp-cmdline' " Command-line completion source
Plug 'hrsh7th/nvim-cmp' " Completion engine
Plug 'L3MON4D3/LuaSnip' " Snippet engine
Plug 'rafamadriz/friendly-snippets' " Community snippet pack
Plug 'lervag/vimtex' " LaTeX workflow plugin
Plug 'windwp/nvim-autopairs' " Auto-close brackets and quotes
Plug 'numToStr/Comment.nvim' " Comment toggles
Plug 'folke/flash.nvim' " Fast jump motions
Plug 'tpope/vim-surround' " Surround text objects
Plug 'itchyny/lightline.vim' " Statusline
Plug 'tpope/vim-fugitive' " Git commands
Plug 'simrat39/rust-tools.nvim' " Extra Rust tooling
let maplocalleader = ","
let g:tex_flavor = 'latex'
let g:vimtex_compiler_method = 'latexmk'
let g:vimtex_quickfix_method = 'latexlog'
if executable('zathura')
let g:vimtex_view_method = 'zathura'
elseif executable('xdg-open')
let g:vimtex_view_method = 'general'
let g:vimtex_view_general_viewer = 'xdg-open'
let g:vimtex_view_general_options = '@pdf'
endif
call plug#end()
@ -57,14 +77,4 @@ colorscheme tokyonight
let mapleader = " "
nnoremap <C-p> :lua require ('telescope.builtin').git_files()<CR>
nnoremap <C-f> :lua require ('telescope.builtin').find_files()<CR>
nnoremap <leader>f :lua require('telescope.builtin').live_grep()<CR>
nnoremap <leader><tab> :lua require('telescope.builtin').buffers()<CR>
nnoremap <leader>y "+y
nnoremap gd :lua vim.lsp.buf.definition()<CR>
nnoremap K :lua vim.lsp.buf.hover()<CR>
nnoremap L :lua vim.diagnostic.open_float()<CR>
nnoremap <C-n> :NERDTreeToggle<CR>
lua require("init")

@ -1,114 +1,276 @@
local cmp = require("cmp")
local luasnip = require("luasnip")
local cmp_nvim_lsp = require("cmp_nvim_lsp")
local telescope = require("telescope")
local builtin = require("telescope.builtin")
local themes = require("telescope.themes")
local map = vim.keymap.set
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
--vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end,
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
local ok_autopairs, autopairs = pcall(require, "nvim-autopairs")
local ok_cmp_autopairs, cmp_autopairs = pcall(require, "nvim-autopairs.completion.cmp")
local ok_comment, comment = pcall(require, "Comment")
local ok_flash, flash = pcall(require, "flash")
local ok_oil, oil = pcall(require, "oil")
vim.opt.completeopt = { "menu", "menuone", "noselect" }
local function format_tex_buffer()
local result = vim.system({ "latexindent" }, {
stdin = table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, false), "\n") .. "\n",
text = true,
}):wait()
if result.code ~= 0 then
vim.notify(result.stderr ~= "" and result.stderr or "latexindent failed", vim.log.levels.ERROR)
return
end
local formatted = vim.split(result.stdout or "", "\n", { plain = true, trimempty = false })
if formatted[#formatted] == "" then
table.remove(formatted, #formatted)
end
local view = vim.fn.winsaveview()
vim.api.nvim_buf_set_lines(0, 0, -1, false, formatted)
vim.fn.winrestview(view)
end
local function format_buffer()
if vim.bo.filetype == "tex" and vim.fn.executable("latexindent") == 1 then
format_tex_buffer()
return
end
vim.lsp.buf.format({ async = true })
end
luasnip.config.setup({})
require("luasnip.loaders.from_vscode").lazy_load()
if ok_autopairs then
autopairs.setup({})
end
if ok_comment then
comment.setup()
end
if ok_flash then
flash.setup()
end
if ok_oil then
oil.setup({
default_file_explorer = true,
skip_confirm_for_simple_edits = true,
view_options = {
show_hidden = true,
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<Tab>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
-- { name = 'vsnip' }, -- For vsnip users.
{ name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = 'buffer' },
})
})
vim.diagnostic.config({
virtual_text = true,
signs = true,
underline = true,
float = true,
end
telescope.setup({
extensions = {
["ui-select"] = themes.get_dropdown({}),
undo = {
layout_strategy = "vertical",
layout_config = {
preview_height = 0.6,
},
side_by_side = true,
},
},
})
vim.lsp.config('ts_ls', {})
vim.lsp.config('clangd', {})
vim.lsp.config('gopls', {
cmd = { "gopls", "serve" },
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
},
},
pcall(telescope.load_extension, "ui-select")
pcall(telescope.load_extension, "undo")
-- Completion shortcuts.
local cmp_insert_mappings = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<Tab>"] = cmp.mapping.confirm({ select = true }), -- Accept the selected completion.
})
vim.lsp.config('pyright', {})
vim.lsp.config('rust_analyzer', {
cmd = { "rust-analyzer" },
settings = {
['rust-analyzer'] = {
checkOnSave = {
allFeatures = true,
overrideCommand = {
'cargo', 'clippy', '--workspace', '--message-format=json',
'--all-targets', '--all-features'
}
}
}
}
local cmp_cmdline_mappings = cmp.mapping.preset.cmdline()
-- Search and buffers.
map("n", "<C-p>", builtin.git_files, { desc = "Search tracked files", silent = true })
map("n", "<C-f>", builtin.find_files, { desc = "Search all files", silent = true })
map("n", "<leader>f", builtin.live_grep, { desc = "Grep project", silent = true })
map("n", "<leader>/", function()
builtin.current_buffer_fuzzy_find(themes.get_dropdown({ previewer = false, winblend = 10 }))
end, { desc = "Search current buffer", silent = true })
map("n", "<leader>fh", builtin.help_tags, { desc = "Search help", silent = true })
map("n", "<leader>fr", builtin.oldfiles, { desc = "Recent files", silent = true })
map("n", "<leader>fu", "<CMD>Telescope undo<CR>", { desc = "Undo history", silent = true })
map("n", "<leader><tab>", builtin.buffers, { desc = "Switch buffers", silent = true })
-- File browsing.
map("n", "-", "<CMD>Oil<CR>", { desc = "Open parent directory", silent = true })
map("n", "<leader>e", "<CMD>Oil<CR>", { desc = "Open file explorer", silent = true })
map("n", "<leader>E", function()
require("oil").open(vim.fn.expand("%:p:h"))
end, { desc = "Open current file directory", silent = true })
-- LSP and diagnostics.
map("n", "gd", vim.lsp.buf.definition, { desc = "Go to definition", silent = true })
map("n", "gr", builtin.lsp_references, { desc = "List references", silent = true })
map("n", "gi", builtin.lsp_implementations, { desc = "List implementations", silent = true })
map("n", "K", vim.lsp.buf.hover, { desc = "Hover docs", silent = true })
map("n", "L", vim.diagnostic.open_float, { desc = "Show diagnostics", silent = true })
map({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, { desc = "Code action", silent = true })
map("n", "<leader>rn", vim.lsp.buf.rename, { desc = "Rename symbol", silent = true })
map("n", "[d", function()
vim.diagnostic.jump({ count = -1, float = true })
end, { desc = "Previous diagnostic", silent = true })
map("n", "]d", function()
vim.diagnostic.jump({ count = 1, float = true })
end, { desc = "Next diagnostic", silent = true })
map("n", "<leader>q", vim.diagnostic.setloclist, { desc = "Diagnostics list", silent = true })
map("n", "<leader>fm", format_buffer, { desc = "Format buffer", silent = true })
-- LaTeX workflow.
map("n", "<leader>tc", "<CMD>VimtexCompile<CR>", { desc = "Compile TeX", silent = true })
map("n", "<leader>tk", "<CMD>VimtexStop<CR>", { desc = "Stop TeX compile", silent = true })
map("n", "<leader>tv", "<CMD>VimtexView<CR>", { desc = "Open TeX PDF", silent = true })
map("n", "<leader>to", "<CMD>VimtexCompileOutput<CR>", { desc = "TeX compiler output", silent = true })
map("n", "<leader>tt", "<CMD>VimtexTocToggle<CR>", { desc = "TeX table of contents", silent = true })
map("n", "<leader>te", "<CMD>VimtexErrors<CR>", { desc = "TeX errors", silent = true })
map("n", "<leader>tl", "<CMD>VimtexClean<CR>", { desc = "Clean TeX build files", silent = true })
-- Editing and utility shortcuts.
map({ "n", "v" }, "<leader>y", '"+y', { desc = "Yank to clipboard", silent = true })
map("n", "<leader>u", "<CMD>UndotreeToggle<CR>", { desc = "Toggle undo tree", silent = true })
map({ "n", "x", "o" }, "s", function()
require("flash").jump()
end, { desc = "Flash jump", silent = true })
map({ "n", "x", "o" }, "S", function()
require("flash").treesitter()
end, { desc = "Flash Tree-sitter jump", silent = true })
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp_insert_mappings,
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "path" },
}, {
{ name = "buffer" },
}),
})
vim.lsp.config('kotlin-language-server', {
cmd = { "kotlin-language-server" },
filetypes = { "kotlin"} ,
cmp.setup.cmdline("/", {
mapping = cmp_cmdline_mappings,
sources = {
{ name = "buffer" },
},
})
vim.lsp.config('cmake', {})
vim.lsp.config('html', {})
vim.lsp.config('glsl_analyzer', {})
vim.lsp.config('zls', {})
cmp.setup.cmdline(":", {
mapping = cmp_cmdline_mappings,
sources = cmp.config.sources({
{ name = "path" },
}, {
{ name = "cmdline" },
}),
})
if ok_cmp_autopairs then
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
end
vim.diagnostic.config({
virtual_text = true,
signs = true,
underline = true,
update_in_insert = true,
})
require'nvim-treesitter.configs'.setup {
-- Install parsers synchronously (only applied to `ensure_installed`)
local capabilities = cmp_nvim_lsp.default_capabilities()
local servers = {
ts_ls = {},
clangd = {},
gopls = {
cmd = { "gopls", "serve" },
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
},
},
},
pyright = {},
texlab = {
settings = {
texlab = {
build = {
executable = "latexmk",
args = {
"-pdf",
"-interaction=nonstopmode",
"-synctex=1",
"-file-line-error",
"%f",
},
onSave = true,
forwardSearchAfter = false,
},
chktex = {
onOpenAndSave = false,
onEdit = false,
},
},
},
},
rust_analyzer = {
cmd = { "rust-analyzer" },
settings = {
["rust-analyzer"] = {
checkOnSave = {
allFeatures = true,
overrideCommand = {
"cargo",
"clippy",
"--workspace",
"--message-format=json",
"--all-targets",
"--all-features",
},
},
},
},
},
["kotlin-language-server"] = {
cmd = { "kotlin-language-server" },
filetypes = { "kotlin" },
},
cmake = {},
html = {},
glsl_analyzer = {},
lua_ls = {},
zls = {},
}
for server, config in pairs(servers) do
config.capabilities = capabilities
vim.lsp.config(server, config)
vim.lsp.enable(server)
end
require("nvim-treesitter.configs").setup({
sync_install = false,
highlight = {
-- `false` will disable the whole extension
enable = true,
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
}
vim.lsp.enable({"ts_ls"})
vim.lsp.enable({"clangd"})
vim.lsp.enable({"gopls"})
vim.lsp.enable({"pyright"})
vim.lsp.enable({"rust_analyzer"})
vim.lsp.enable({"kotlin-language-server"})
vim.lsp.enable({"cmake"})
vim.lsp.enable({"html"})
vim.lsp.enable({"glsl_analyzer"})
vim.lsp.enable('lua_ls')
vim.lsp.enable('zls')
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
update_in_insert = true,
}
)
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
})

Loading…
Cancel
Save