new: All my files

This commit is contained in:
Sayantan Santra 2024-03-13 14:07:20 -05:00
commit ea0218a8cb
Signed by: SinTan1729
GPG key ID: EB3E68BFBA25C85F
16 changed files with 550 additions and 0 deletions

View file

@ -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 "(?<!^)\\begin\{(\w+)\}" "inline begin{} / end{}" riA
\begin{`!p snip.rv = match.group(1)`} $1 \end{`!p snip.rv = match.group(1)`} $0
endsnippet

11
init.lua Normal file
View file

@ -0,0 +1,11 @@
-- Load old vimrc first
local vimrc = vim.fn.stdpath("config") .. "/vimrc.vim"
vim.cmd.source(vimrc)
-- Load plugins using vim-plug
local plug = vim.fn.stdpath("config") .. "/plug.vim"
vim.cmd.source(plug)
-- Default settings for comment plugin
require('Comment').setup()

48
plug.vim Normal file
View file

@ -0,0 +1,48 @@
" Auto install vim-plug
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" Load plugins via vim-plug
call plug#begin()
" airline related plugins
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" Auto commenting per filetype
Plug 'numToStr/Comment.nvim'
" Give option to save files using sudo, if needed
Plug 'lambdalisue/suda.vim'
" Auto toggle for number mode when vim isn't focused
Plug 'sitiom/nvim-numbertoggle'
" Plugin for lean
Plug 'julian/lean.nvim'
" LSP related plugins
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/plenary.nvim'
Plug 'hrsh7th/nvim-cmp' " For LSP completion
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-omni' " For LaTeX completion
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'SirVer/ultisnips' " For snippets
" Support programming terms
Plug 'psliwka/vim-dirtytalk', { 'do': ':let &rtp = &rtp \| DirtytalkUpdate' }
" vim-moonfly theme
Plug 'bluz71/vim-moonfly-colors', { 'as': 'moonfly' }
" Rust tools
Plug 'simrat39/rust-tools.nvim'
" Automatically add bracket pairs
Plug 'windwp/nvim-autopairs'
" Syntax highlighting for Fish scripts
Plug 'khaveesh/vim-fish-syntax'
" Plugin for LaTeX
Plug 'lervag/vimtex'
" Formatter
Plug 'stevearc/conform.nvim'
" For Searching
Plug 'junegunn/fzf.vim'
call plug#end()

50
plugin/airline.vim Normal file
View file

@ -0,0 +1,50 @@
" 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 = ''
" air-line
let g:airline_powerline_fonts = 1
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
" unicode symbols
let g:airline_left_sep = '»'
let g:airline_left_sep = '▶'
let g:airline_right_sep = '«'
let g:airline_right_sep = '◀'
let g:airline_symbols.linenr = '␊'
let g:airline_symbols.linenr = '␤'
let g:airline_symbols.linenr = '¶'
let g:airline_symbols.branch = '⎇'
let g:airline_symbols.paste = 'ρ'
let g:airline_symbols.paste = 'Þ'
let g:airline_symbols.paste = '∥'
let g:airline_symbols.whitespace = 'Ξ'
" airline symbols
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = ''
" Switch to your current theme
let g:airline_theme = 'moonfly'
" Always show tabs
set showtabline=2
" We don't need to see things like -- INSERT -- anymore
set noshowmode
" Navigate tabs using ,j and ,k
nnoremap <Leader>k :bnext<CR>
nnoremap <Leader>j :bprevious<CR>

108
plugin/autopairs.lua Normal file
View file

@ -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 '<C-c>2xi<CR><C-c>O' 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 '<bs> =' .. next_char
end
if prev_2char:match('%=$') then
return next_char
end
if prev_2char:match('=') then
return '<bs><bs>=' .. 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('(',' ',')')

72
plugin/cmp.lua Normal file
View file

@ -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({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = 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
}
})
)

38
plugin/conform.lua Normal file
View file

@ -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,
}

13
plugin/lean.lua Normal file
View file

@ -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,
-- }
-- )

13
plugin/lspconfig.lua Normal file
View file

@ -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",
}
},
},
}

26
plugin/moonfly.lua Normal file
View file

@ -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]]

11
plugin/pyright.lua Normal file
View file

@ -0,0 +1,11 @@
require'lspconfig'.pyright.setup({
on_attach = on_attach,
flags = lsp_flags,
settings = {
python = {
analysis = {
typeCheckingMode = "off"
}
}
}
})

12
plugin/rust.lua Normal file
View file

@ -0,0 +1,12 @@
require("rust-tools").setup({
server = {
settings = {
["rust-analyzer"] = {
check = {
command = "clippy"
},
},
},
},
})

3
plugin/suda.vim Normal file
View file

@ -0,0 +1,3 @@
if ! &diff
let g:suda_smart_edit = 1
endif

27
plugin/vimtex.vim Normal file
View file

@ -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 <buffer> <localleader>lo :silent VimtexCompileSS<CR>
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' }

20
themes/airline.vim Normal file
View file

@ -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

82
vimrc.vim Normal file
View file

@ -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 <silent> <c-k> :wincmd k<CR>
nmap <silent> <c-j> :wincmd j<CR>
nmap <silent> <c-h> :wincmd h<CR>
nmap <silent> <c-l> :wincmd l<CR>
" 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 <leader>d "_d
nnoremap <leader>D "_D
nnoremap <leader>x "_x
vnoremap <leader>d "_d
" Insert a newline in normal mode by ,o
nnoremap <leader>o o<Esc>k
nnoremap <leader>O O<Esc>j
" Use ,u for redo
nnoremap <leader>u <c-r>
" Load UltiSnips snippets from custom-snippets
let g:UltiSnipsSnippetDirectories=["custom-snippets", "UltiSnips"]
" Find files using fzf by ,f
nnoremap <leader>f :Files<CR>