This commit is contained in:
Victor Lalle 2023-06-04 15:19:51 +02:00
parent d436e7e412
commit c7e8bf1f56
8 changed files with 396 additions and 0 deletions

53
.gitignore vendored
View File

@ -1,3 +1,52 @@
## nvim ignore
# Project gitignore
!colors/astronvim.lua
colors/*
docs
ginit.vim
lua/user
plugin
ftplugin
spell
.luarc.json
# Global gitignore
# ----------------
# Mac OS X
.DS_Store
.AppleDouble
.LSOverride
._*
# Windoze
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
$RECYCLE.BIN/
# (Neo)Vim
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
Session.vim
Sessionx.vim
.netrwhist
*~
tags
[._]*.un~
# VS Code
.vscode
.history
# JetBrains
.idea
## My ignore
chromium/**/* chromium/**/*
microsoft-edge/**/* microsoft-edge/**/*
VSCodium/**/* VSCodium/**/*
@ -14,3 +63,7 @@ configstore/update-notifier-web-ext.json
configstore/reactNativeToolsConfig.json configstore/reactNativeToolsConfig.json
htop/htoprc htop/htoprc
nextjs-nodejs/config.json nextjs-nodejs/config.json
nvm/**/*
nvim/.github
nvim/autoload/plug.vim
nvim/shortcuts.vim

7
nvim/.stylua.toml Normal file
View File

@ -0,0 +1,7 @@
column_width = 120
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferDouble"
call_parentheses = "None"
collapse_simple_statement = "Always"

6
nvim/.typos.toml Normal file
View File

@ -0,0 +1,6 @@
# See https://github.com/crate-ci/typos/blob/master/docs/reference.md to configure typos
[default.extend-words]
enew = "enew"
fo = "fo"
[files]
extend-exclude = ["LICENSE"]

216
nvim/init.lua Normal file
View File

@ -0,0 +1,216 @@
-- Make local variables, instead of typing long commands over and over again.
local map = vim.api.nvim_set_keymap
local s = { silent = true }
local function autocmd(event, pattern, cmd)
vim.api.nvim_create_autocmd(event, {
pattern = pattern,
command = cmd,
})
end
--This function loads a table of options into vim.opt
local function load(x)
for name, value in pairs(x) do
vim.opt[name] = value
end
end
-- Set leader key to comma
vim.g.mapleader = ","
--Autoload function
if vim.fn.filereadable(vim.fn.system('echo -n "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim"')) == 0 then
print("Downloading junegunn/vim-plug to manage plugins...")
vim.fn.system('mkdir -p ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/')
vim.fn.system('curl "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" > ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim')
autocmd("VimEnter", "*", "PlugInstall")
end
map('n', ',,', [[:keepp /<++><CR>ca<]], s)
map('i', ',,', '<esc>:keepp /<++><CR>ca<', s)
-- Call plugins
local Plug = vim.fn['plug#']
vim.call('plug#begin', (vim.fn['system']('echo -n "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/plugged"')))
Plug 'tpope/vim-surround'
Plug 'preservim/nerdtree'
Plug 'junegunn/goyo.vim'
Plug 'jreybert/vimagit'
Plug 'vimwiki/vimwiki'
Plug 'vim-airline/vim-airline'
Plug 'tpope/vim-commentary'
Plug 'ap/vim-css-color'
Plug 'nvim-treesitter/nvim-treesitter'
Plug 'neovim/nvim-lspconfig'
Plug 'williamboman/mason.nvim'
Plug 'williamboman/mason-lspconfig.nvim'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'L3MON4D3/LuaSnip'
Plug 'VonHeikemen/lsp-zero.nvim'
Plug 'zbirenbaum/copilot.lua'
Plug 'kchmck/vim-coffee-script'
vim.call('plug#end')
-- Set options
local basics = {
title = true,
background = "light",
go = "a",
hlsearch = false,
clipboard = "unnamedplus",
showmode = false,
ruler = false,
laststatus = 0,
showcmd = false,
--filetype plugin on | this is default in neovim
syntax = "on", -- this is default in neovim
encoding = "utf-8",
number = true,
relativenumber = true,
--Enable autocompletion:
wildmode = "longest,list,full",
splitright = true,
splitbelow = true
}
-- Some basics
vim.keymap.set("n", "c", '"_c', s)
--Disables automatic commenting on newline:
autocmd("FileType", "markdown", "setlocal formatoptions-=c formatoptions-=r formatoptions-=o")
-- Perform dot commands over visual blocks:
map("v", ".", ":normal .<CR>",s)
--Goyo plugin makes text more readable when writing prose:
map('n', '<leader>f', ":Goyo | set bg=light | set linebreak<CR>",s)
--Spell-check set to <leader>o, 'o' for 'orthography':
map('n', '<leader>o', ":setlocal spell! spelllang=en_us<CR>",s)
--nerdtree
map("n", "<leader>n", ":NERDTreeToggle<CR>",s)
autocmd("bufenter *", "*", "if (winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree()) | q | endif")
if vim.fn.has('nvim') == 1 then
vim.b.NERDTreeBookmarksFile = vim.fn.stdpath('data') .. '/NERDTreeBookmarks'
else
vim.b.NERDTreeBookmarksFile = '~/.vim/NERDTreeBookmarks'
end
-- vimling
map("n","<leader>d", ":call ToggleDeadKeys()<CR>",s)
map("i", "<leader>d", "<esc>:call ToggleDeadKeys()<CR>a",s)
map("n","<leader>i", ":call ToggleIPA()<CR>",s)
map("i", "<leader>i", "<esc>:call ToggleIPA()<CR>a",s)
map("n", "<leader>q", ":call ToggleProse()<CR>",s)
--Shortcutting split navigation, saving a keypress:
map("n", "<C-h>", "<C-w>h", s)
map("n", "<C-j>", "<C-w>j", s)
map("n", "<C-k>", "<C-w>k", s)
map("n", "<C-l>", "<C-w>l", s)
--Replace ex mode with gq
map("n", "Q", "gq", s)
--Check file in shellcheck:
map("n", "<leader>s", ":!clear && spellcheck -x %<CR>", s)
--Open my bibliography file in split
map("n", "leader>b", ":vsp<space>$BIB<CR>", s)
map("n", "leader>r", ":vsp<space>$REFER<CR>", s)
--Replace all in aliased to S
map('n', 'S', ":%s//g<Left><Left>", s)
--Compile document, be it groff/LaTeX/markdown/etc.
map("n", "<leader>c", ":w! |!compiler '%:p'<CR>", s)
--Open corresponding .pdf/.html or preview
map("n", "<leader>p", ":!opout '%:p'<CR>", s)
--Runs a script that cleans out tex build files whenever I close out of a .tex file.
autocmd("VimLeave", "*.tex", "!texclear %")
-- Ensure files are read as what I want:
map("n", "<leader>v", ":VimwikiIndex<CR>", s)
vim.g.vimwiki_ext2syntax = {
['.Rmd'] = 'markdown',
['.rmd'] = 'markdown',
['.md'] = 'markdown',
['.markdown'] = 'markdown',
['.mdown'] = 'markdown'
}
--Runs a script that cleans out tex build files whenever I close out of a .tex file.
vim.g.vimwiki_list = {
{
path = '~/.local/share/nvim/vimwiki',
syntax = 'markdown',
ext = '.md'
}
}
--Save file as sudo on files that require root permission
vim.api.nvim_command('cabbrev w!! execute "silent! write !sudo tee % >/dev/null" <bar> edit!')
--Enable markdown syntax for .md files
autocmd({"BufRead", "BufNewFile"}, {"/tmp/calcurse*","~/.calcurse/notes/*"}, "set filetype=markdown")
autocmd({"BufRead", "BufNewFile"}, {"*.ms", "*.me", "*.mom", "*.man"}, "set filetype=groff")
autocmd({"BufRead", "BufNewFile"}, {"*.tex"}, "set filetype=tex")
-- Enable Goyo by default for mutt writing
autocmd({"BufRead", "BufNewFile"}, {"/tmp/neomutt*"}, "let g:goyo_width=80")
autocmd({"BufRead", "BufNewFile"}, {"/tmp/neomutt*"}, "set bg=light")
autocmd({"BufRead", "BufNewFile"}, {"/tmp/neomutt*"}, "map ZZ :Goyo|x!<CR>")
autocmd({"BufRead", "BufNewFile"}, {"/tmp/neomutt*"}, "map ZQ :Goyo|q!<CR>")
--Automatically deletes all trailing whitespace and newlines at end of file on save. & reset cursor position
autocmd("BufWritePre", "*", "let currPos = getpos('.')")
autocmd("BufWritePre", "*", "%s/\\s\\+$//e")
autocmd("BufWritePre", "*", "%s/\\n\\+\\%$//e")
autocmd("BufWritePre", "*", "cal cursor(currPos[1], currPos[2])")
--When shortcut files are updated, renew bash and ranger configs with new material:
autocmd("BufWritePost", "bm-files,bm-dirs", "!shortcuts")
--Run xrdb whenever Xdefaults or Xresources are updated.
autocmd("BufWritePost", "Xresources,Xdefaults,xresources,xdefaults", "set filetype=xdefaults")
autocmd("BufWritePost", "Xresources,Xdefaults,xresources,xdefaults", "!xrdb %")
--Recompile dwmblocks on config edit.
autocmd("BufWritePost", "config.h", "!cd ~/.local/src/dwmblocks/; sudo make install && { killall -q dwmblocks;setsid -f dwmblocks }")
-- Auto compile dwm on config.h change
function compile_dwm_config()
local current_file = vim.fn.expand('%:p') -- get current file path
if current_file == os.getenv("HOME")..'/.local/src/dwm/config.h' then
os.execute('cd ~/.local/src/dwm && sudo make clean install')
end
end
autocmd("BufWritePost", "config.h", "lua compile_dwm_config()")
--Turns off highlighting on the bits of code that are changed, so the line that is changed is highlighted but the actual text that has changed stands out on the line and is readable.
if vim.opt.diff:get() then
vim.cmd('highlight! link DiffText MatchParen')
end
--Function for toggling the bottom statusbar:
local h = {hidden_all = 0}
function Toggle_hidden_all()
local hideOptions = {}
if h.hidden_all == 0 then
h.hidden_all = 1
hideOptions = {
showmode = false,
ruler = false,
laststatus = 0,
showcmd = false,
}
else
h.hidden_all = 0
hideOptions = {
showmode = true,
ruler = true,
laststatus = 2,
showcmd = true,
}
end
load(hideOptions)
end
vim.keymap.set('n', '<leader>h', function() Toggle_hidden_all() end, {silent = true, noremap = true})
-- load options
load(basics)
vim.cmd('silent! source ~/.config/nvim/shortcuts.vim')
require("victor")

View File

@ -0,0 +1,43 @@
require('copilot').setup({
panel = {
enabled = true,
auto_refresh = false,
keymap = {
jump_prev = "[[",
jump_next = "]]",
accept = "<CR>",
refresh = "gr",
open = "<M-CR>"
},
layout = {
position = "bottom", -- | top | left | right
ratio = 0.4
},
},
suggestion = {
enabled = true,
auto_trigger = true,
debounce = 75,
keymap = {
accept = "<tab>",
accept_word = false,
accept_line = false,
next = "<M-]>",
prev = "<M-[>",
dismiss = "<C-]>",
},
},
filetypes = {
yaml = false,
markdown = false,
help = false,
gitcommit = false,
gitrebase = false,
hgcommit = false,
svn = false,
cvs = false,
["."] = false,
},
copilot_node_command = 'node', -- Node.js version must be > 16.x
server_opts_overrides = {},
})

3
nvim/lua/victor/init.lua Normal file
View File

@ -0,0 +1,3 @@
require("victor.lsp")
require("victor.copilot")
require("victor.treesit")

57
nvim/lua/victor/lsp.lua Normal file
View File

@ -0,0 +1,57 @@
local lsp = require("lsp-zero")
lsp.preset("recommended")
lsp.ensure_installed({
'tsserver',
'rust_analyzer',
})
-- Fix Undefined global 'vim'
lsp.nvim_workspace()
local cmp = require('cmp')
local cmp_select = {behavior = cmp.SelectBehavior.Select}
local cmp_mappings = lsp.defaults.cmp_mappings({
['<C-k>'] = cmp.mapping.select_prev_item(cmp_select),
['<C-j>'] = cmp.mapping.select_next_item(cmp_select),
--Make the enter button select the item
['<CR>'] = cmp.mapping.confirm({ select = true }),
["<C-Space>"] = cmp.mapping.complete(),
})
cmp_mappings['<Tab>'] = nil
cmp_mappings['<S-Tab>'] = nil
lsp.setup_nvim_cmp({
mapping = cmp_mappings
})
lsp.set_preferences({
suggest_lsp_servers = false,
sign_icons = {
error = 'E',
warn = 'W',
hint = 'H',
info = 'I'
}
})
lsp.on_attach(function(client, bufnr)
local opts = {buffer = bufnr, remap = false}
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts)
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts)
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, opts)
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts)
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
end)
lsp.setup()
vim.diagnostic.config({
virtual_text = true
})

View File

@ -0,0 +1,11 @@
require'nvim-treesitter.configs'.setup {
-- A list of parser names, or "all" (the five listed parsers should always be installed)
ensure_installed = { "c", "lua", "vim", "vimdoc", "query" },
sync_install = false,
auto_install = true,
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
}