From ea0218a8cb4649511c9058b1f8821ff7c850423d Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Wed, 13 Mar 2024 14:07:20 -0500 Subject: [PATCH] new: All my files --- custom-snippets/tex.snippets | 16 ++++++ init.lua | 11 ++++ plug.vim | 48 ++++++++++++++++ plugin/airline.vim | 50 ++++++++++++++++ plugin/autopairs.lua | 108 +++++++++++++++++++++++++++++++++++ plugin/cmp.lua | 72 +++++++++++++++++++++++ plugin/conform.lua | 38 ++++++++++++ plugin/lean.lua | 13 +++++ plugin/lspconfig.lua | 13 +++++ plugin/moonfly.lua | 26 +++++++++ plugin/pyright.lua | 11 ++++ plugin/rust.lua | 12 ++++ plugin/suda.vim | 3 + plugin/vimtex.vim | 27 +++++++++ themes/airline.vim | 20 +++++++ vimrc.vim | 82 ++++++++++++++++++++++++++ 16 files changed, 550 insertions(+) create mode 100644 custom-snippets/tex.snippets create mode 100644 init.lua create mode 100644 plug.vim create mode 100644 plugin/airline.vim create mode 100644 plugin/autopairs.lua create mode 100644 plugin/cmp.lua create mode 100644 plugin/conform.lua create mode 100644 plugin/lean.lua create mode 100644 plugin/lspconfig.lua create mode 100644 plugin/moonfly.lua create mode 100644 plugin/pyright.lua create mode 100644 plugin/rust.lua create mode 100644 plugin/suda.vim create mode 100644 plugin/vimtex.vim create mode 100644 themes/airline.vim create mode 100644 vimrc.vim diff --git a/custom-snippets/tex.snippets b/custom-snippets/tex.snippets new file mode 100644 index 0000000..3f22be6 --- /dev/null +++ b/custom-snippets/tex.snippets @@ -0,0 +1,16 @@ +priority -10 + +extends tex + +snippet "\\begin\{(\w+)\}" "multiline begin{} / end{}" rbA +\begin{`!p snip.rv = match.group(1)`} + $1 +\end{`!p snip.rv = match.group(1)`} +endsnippet + +priority -20 + +snippet "(?k :bnext +nnoremap j :bprevious + diff --git a/plugin/autopairs.lua b/plugin/autopairs.lua new file mode 100644 index 0000000..05ca743 --- /dev/null +++ b/plugin/autopairs.lua @@ -0,0 +1,108 @@ +local Rule = require('nvim-autopairs.rule') +local npairs = require('nvim-autopairs') +local cond = require('nvim-autopairs.conds') + +npairs.setup({ + -- will ignore alphanumeric and `.` symbol + ignored_next_char = "[%w%.]", +}) + +npairs.add_rules({ + Rule("\\(", "\\)", {"tex", "latex"}), + Rule("\\[", "\\]", {"tex", "latex"}), + }, + -- disable for .vim files, but it work for another filetypes + Rule("a","a","-vim") +) + +-- Add spaces between brackets +local brackets = { { '(', ')' }, { '[', ']' }, { '{', '}' } } +npairs.add_rules { + -- Rule for a pair with left-side ' ' and right side ' ' + Rule(' ', ' ') + -- Pair will only occur if the conditional function returns true + :with_pair(function(opts) + -- We are checking if we are inserting a space in (), [], or {} + local pair = opts.line:sub(opts.col - 1, opts.col) + return vim.tbl_contains({ + brackets[1][1] .. brackets[1][2], + brackets[2][1] .. brackets[2][2], + brackets[3][1] .. brackets[3][2] + }, pair) + end) + :with_move(cond.none()) + :with_cr(cond.none()) + -- We only want to delete the pair of spaces when the cursor is as such: ( | ) + :with_del(function(opts) + local col = vim.api.nvim_win_get_cursor(0)[2] + local context = opts.line:sub(col - 1, col + 2) + return vim.tbl_contains({ + brackets[1][1] .. ' ' .. brackets[1][2], + brackets[2][1] .. ' ' .. brackets[2][2], + brackets[3][1] .. ' ' .. brackets[3][2] + }, context) + end) +} +-- For each pair of brackets we will add another rule +for _, bracket in pairs(brackets) do + npairs.add_rules { + -- Each of these rules is for a pair with left-side '( ' and right-side ' )' for each bracket type + Rule(bracket[1] .. ' ', ' ' .. bracket[2]) + :with_pair(cond.none()) + :with_move(function(opts) return opts.char == bracket[2] end) + :with_del(cond.none()) + :use_key(bracket[2]) + -- Removes the trailing whitespace that can occur without this + :replace_map_cr(function(_) return '2xiO' end) + } +end + +-- Add space around = +npairs.add_rules { + Rule('=', '', { "-tex", "-vim", "-sh" }) + :with_pair(cond.not_inside_quote()) + :with_pair(function(opts) + local last_char = opts.line:sub(opts.col - 1, opts.col - 1) + if last_char:match('[%w%=%s]') then + return true + end + return false + end) + :replace_endpair(function(opts) + local prev_2char = opts.line:sub(opts.col - 2, opts.col - 1) + local next_char = opts.line:sub(opts.col, opts.col) + next_char = next_char == ' ' and '' or ' ' + if prev_2char:match('%w$') then + return ' =' .. next_char + end + if prev_2char:match('%=$') then + return next_char + end + if prev_2char:match('=') then + return '=' .. next_char + end + return '' + end) + :set_end_pair_length(0) + :with_move(cond.none()) + :with_del(cond.none()) +} + +-- Insertion with surrounding check +function rule2(a1,ins,a2,lang) + npairs.add_rule( + Rule(ins, ins, lang) + :with_pair(function(opts) return a1..a2 == opts.line:sub(opts.col - #a1, opts.col + #a2 - 1) end) + :with_move(cond.none()) + :with_cr(cond.none()) + :with_del(function(opts) + local col = vim.api.nvim_win_get_cursor(0)[2] + return a1..ins..ins..a2 == opts.line:sub(col - #a1 - #ins + 1, col + #ins + #a2) -- insert only works for #ins == 1 anyway + end) + ) +end +-- Only use it for ocaml +rule2('(','*',')','ocaml') +rule2('(*',' ','*)','ocaml') +rule2('(',' ',')') + diff --git a/plugin/cmp.lua b/plugin/cmp.lua new file mode 100644 index 0000000..97a58d8 --- /dev/null +++ b/plugin/cmp.lua @@ -0,0 +1,72 @@ +local cmp = require('cmp') +local cmp_autopairs = require('nvim-autopairs.completion.cmp') + +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(winhighlight), + documentation = cmp.config.window.bordered(winhighlight), + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = 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 = "omni" }, + -- { name = 'vsnip' }, -- For vsnip users. + -- { name = 'luasnip' }, -- For luasnip users. + { name = 'ultisnips' }, -- For ultisnips users. + -- { name = 'snippy' }, -- For snippy users. + }, {{ name = 'buffer' }} + ), + experimental = { ghost_text = true }, + }) + + -- Set configuration for specific filetype. + cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git). + }, { + { 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' } +}) +}) + +-- Insert `(` after select function or method item +cmp.event:on( + 'confirm_done', + cmp_autopairs.on_confirm_done({ + filetypes = { + tex = false + } + }) +) diff --git a/plugin/conform.lua b/plugin/conform.lua new file mode 100644 index 0000000..87d0fa9 --- /dev/null +++ b/plugin/conform.lua @@ -0,0 +1,38 @@ +local cnf = require("conform") + +-- Setup autoformat on save, with async for slow formatters +local slow_format_filetypes = { "tex" } +cnf.setup({ + formatters_by_ft = { + tex = { "latexindent" } + }, + + format_on_save = function(bufnr) + if slow_format_filetypes[vim.bo[bufnr].filetype] then + return + end + local function on_format(err) + if err and err:match("timeout$") then + slow_format_filetypes[vim.bo[bufnr].filetype] = true + end + end + + return { timeout_ms = 200, lsp_fallback = true }, on_format + end, + + format_after_save = function(bufnr) + if not slow_format_filetypes[vim.bo[bufnr].filetype] then + return + end + return { lsp_fallback = true } + end, +}) + +cnf.formatters.latexindent = { + -- command = "/usr/bin/latexindent", + prepend_args = { "-g", "/dev/null" }, -- Do not create an indent.log file + range_args = function(ctx) + return { "--lines", ctx.range.start[1] .. "-" .. ctx.range["end"][1] } + end, +} + diff --git a/plugin/lean.lua b/plugin/lean.lua new file mode 100644 index 0000000..d777749 --- /dev/null +++ b/plugin/lean.lua @@ -0,0 +1,13 @@ +require('lean').setup{ + abbreviations = { builtin = true }, + mappings = true, +} + +-- -- Update error messages even while you're typing in insert mode +-- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( +-- vim.lsp.diagnostic.on_publish_diagnostics, { +-- underline = true, +-- virtual_text = { spacing = 4 }, +-- update_in_insert = true, +-- } +-- ) diff --git a/plugin/lspconfig.lua b/plugin/lspconfig.lua new file mode 100644 index 0000000..a654bde --- /dev/null +++ b/plugin/lspconfig.lua @@ -0,0 +1,13 @@ +local lspconfig = require('lspconfig') +lspconfig.pyright.setup {} +lspconfig.tsserver.setup {} +lspconfig.rust_analyzer.setup { + -- Server-specific settings. See `:help lspconfig-setup` + settings = { + ['rust-analyzer'] = { + check = { + command = "clippy", + } + }, + }, +} diff --git a/plugin/moonfly.lua b/plugin/moonfly.lua new file mode 100644 index 0000000..670df16 --- /dev/null +++ b/plugin/moonfly.lua @@ -0,0 +1,26 @@ +-- Use moonfly colors in popups +vim.g.moonflyNormalFloat = true + +-- Extra setup to distinguish between edit and floating windows +vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( + vim.lsp.handlers.hover, { + border = "single" + } +) +vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( + vim.lsp.handlers.signatureHelp, { + border = "single" + } +) +vim.diagnostic.config({ float = { border = "single" } }) +-- Some more setup is inside cmp.lua + +-- Make the background transparent +vim.g.moonflyTransparent = true + +-- Display diagnostic virtual text in color +vim.g.moonflyVirtualTextColor = true + +-- Use the moonfly colorscheme +vim.cmd [[colorscheme moonfly]] + diff --git a/plugin/pyright.lua b/plugin/pyright.lua new file mode 100644 index 0000000..132e859 --- /dev/null +++ b/plugin/pyright.lua @@ -0,0 +1,11 @@ +require'lspconfig'.pyright.setup({ + on_attach = on_attach, + flags = lsp_flags, + settings = { + python = { + analysis = { + typeCheckingMode = "off" + } + } + } +}) diff --git a/plugin/rust.lua b/plugin/rust.lua new file mode 100644 index 0000000..b092415 --- /dev/null +++ b/plugin/rust.lua @@ -0,0 +1,12 @@ +require("rust-tools").setup({ + server = { + settings = { + ["rust-analyzer"] = { + check = { + command = "clippy" + }, + }, + }, + }, +}) + diff --git a/plugin/suda.vim b/plugin/suda.vim new file mode 100644 index 0000000..d66021d --- /dev/null +++ b/plugin/suda.vim @@ -0,0 +1,3 @@ +if ! &diff + let g:suda_smart_edit = 1 +endif diff --git a/plugin/vimtex.vim b/plugin/vimtex.vim new file mode 100644 index 0000000..3cca6a9 --- /dev/null +++ b/plugin/vimtex.vim @@ -0,0 +1,27 @@ +" Automatically start continuous compilation +" augroup vimtex_config +" autocmd User VimtexEventInitPost VimtexCompile +" augroup END + +" Enable languagetool support using YaLafi +let g:vimtex_grammar_vlty = {'lt_command': 'languagetool'} +set spelllang=en_us + +" Compile once by \lo +augroup vimrc_tex + autocmd! + autocmd FileType tex nnoremap lo :silent VimtexCompileSS +augroup END + +" Enable word wrapping for tex files +" autocmd FileType tex :set wrap +autocmd FileType tex :set linebreak +autocmd FileType tex :set tw=140 + +" Use zathura with vimtex, the zathura_simple one makes synctex work in +" Wayland +let g:vimtex_view_method = 'zathura_simple' + +" Use a temporary directory for aux files +let g:vimtex_compiler_latexmk = { 'aux_dir' : '/tmp/latexmk' } + diff --git a/themes/airline.vim b/themes/airline.vim new file mode 100644 index 0000000..14f9f22 --- /dev/null +++ b/themes/airline.vim @@ -0,0 +1,20 @@ +" enable tabline +let g:airline#extensions#tabline#enabled = 1 +let g:airline#extensions#tabline#left_sep = '' +let g:airline#extensions#tabline#left_alt_sep = '' +let g:airline#extensions#tabline#right_sep = '' +let g:airline#extensions#tabline#right_alt_sep = '' + +" enable powerline fonts +let g:airline_powerline_fonts = 1 +let g:airline_left_sep = '' +let g:airline_right_sep = '' + +" Switch to your current theme +let g:airline_theme = 'onedark' + +" Always show tabs +set showtabline=2 + +" We don't need to see things like -- INSERT -- anymore +set noshowmode diff --git a/vimrc.vim b/vimrc.vim new file mode 100644 index 0000000..5f7dfd2 --- /dev/null +++ b/vimrc.vim @@ -0,0 +1,82 @@ +" Disable netrw for nvim-tree to work +let loaded_netrw = 1 +let loaded_netrwPlugin = 1 + +" Turn on numbers +set number + +" Turn off line wrapping +set nowrap + +" Turn on syntax highlighting +syntax on +filetype plugin indent on + +" Disable cmdline from bottom +set cmdheight=0 + +" Display as much of a line as possible instead of just showing @ +set display+=lastline + +" Ignore case while searching except when the search term contains capital letters +set ignorecase +set smartcase + +" Use 4 spaces for tabs and properly adjust them for files using TAB +set tabstop=4 +set shiftwidth=4 +set expandtab + +" Needed for group colors to work in nvim-tree +set termguicolors + +" Show LSP signs in the number column +set signcolumn=number + +" Turn on spell checking +set spell + +" Enable mouse support +set mouse=n + +" Set K to hover +command -nargs=+ LspHover lua vim.lsp.buf.hover() +set keywordprg=:LspHover + +" Enable programming dictionary +set spelllang=en,programming + +" Use ctrl-[hjkl] to select the active split! +nmap :wincmd k +nmap :wincmd j +nmap :wincmd h +nmap :wincmd l + +" Disable unused plugins +let g:loaded_perl_provider=0 +let g:loaded_node_provider=0 +let g:loaded_ruby_provider=0 + +" Change the leader to a comma +let mapleader = "," +let g:mapleader = "," + +" Use ,dd for deleting without putting into buffer +nnoremap d "_d +nnoremap D "_D +nnoremap x "_x +vnoremap d "_d + +" Insert a newline in normal mode by ,o +nnoremap o ok +nnoremap O Oj + +" Use ,u for redo +nnoremap u + +" Load UltiSnips snippets from custom-snippets +let g:UltiSnipsSnippetDirectories=["custom-snippets", "UltiSnips"] + +" Find files using fzf by ,f +nnoremap f :Files +