diff --git a/.gitignore b/.gitignore index c0c4fc8..bad1872 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ vim/.vim/autoload/ vim/.vim/.netrwhist neovim/.config/nvim/spell/ +neovim/.config/nvim/lazy-lock.json qutebrowser/* !qutebrowser/.config/qutebrowser/config.py diff --git a/neovim/.config/nvim/init.lua b/neovim/.config/nvim/init.lua index 6290ce4..bed2a64 100644 --- a/neovim/.config/nvim/init.lua +++ b/neovim/.config/nvim/init.lua @@ -8,245 +8,16 @@ -- -------------------------------------------------------------------------------- --- Lua-interface helpers -local opt = vim.opt -local map = vim.keymap.set -local func = vim.fn -local cmd = vim.cmd -local api = vim.api -local augroup = vim.api.nvim_create_augroup -local autocmd = vim.api.nvim_create_autocmd - --------------------------------------------------------------------------------- --- Plugin Management: --- Bootstrap lazy.nvim -local lazypath = func.stdpath("data") .. "/lazy/lazy.nvim" -if not vim.loop.fs_stat(lazypath) then - func.system { - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", - lazypath - } -end -opt.runtimepath:prepend(lazypath) - -- Leader keys need to be set before lazy.nvim is loaded. +vim.keymap.set({"n", "v"}, "", "", {silent = true}) vim.g.mapleader = " " vim.g.maplocalleader = "-" -require("lazy").setup { - -- Tokyo Night colourscheme. - {"folke/tokyonight.nvim", priority = 1000}, - -- Statusline plugin written in pure lua. - "nvim-lualine/lualine.nvim", - -- Adds icons to Neovim plugins. - {"nvim-tree/nvim-web-devicons", lazy = true}, - -- Extension and language-server host for Neovim. - {"neoclide/coc.nvim", branch = "release"}, - -- Insert or delete brackets, parenthesis, quotes in pairs. - "jiangmiao/auto-pairs", - -- A modern filetype plugin for LaTeX. - {"lervag/vimtex", ft = "tex"} -} - -require("tokyonight").setup { - style = "night" -} - --- Lualine -local function spellStatus() - if vim.wo.spell == true then -- Note that 'spell' is a window option, so: wo - return "󰓆 " .. vim.bo.spelllang - end - return '' -end - -require('lualine').setup { - options = { - theme = "tokyonight" - }, - sections = { - lualine_a = {'mode'}, - lualine_b = {'diagnostics'}, - lualine_c = {'filename', spellStatus}, - lualine_x = {{'filetype', icon_only = true}}, - lualine_y = {'progress'}, - lualine_z = {'location'} - }, - tabline = { - lualine_a = {'buffers'}, - lualine_z = {'tabs'} - } -} - --- CoC Intellisense -local cocMapOpts = { - silent = true, - noremap = true, - expr = true, - replace_keycodes = false -} --- Use to cycle completions. -function _G.check_back_space() - local col = func.col('.') - 1 - return col == 0 or func.getline('.'):sub(col, col):match('%s') ~= nil -end -map("i", "", [[coc#pum#visible() ? coc#pum#next(1) : v:lua.check_back_space() ? "" : coc#refresh()]], cocMapOpts) -map("i", "", [[coc#pum#visible() ? coc#pum#prev(1) : "\"]], cocMapOpts) --- Use to confirm completion. -map("i", "", [[coc#pum#visible() ? coc#pum#confirm() : "\u\\=coc#on_enter()\"]], cocMapOpts) - --- VimTeX -vim.g.vimtex_view_method = "sioyek" +-- Lazy.nvim plugin manager: +require("lazy-setup") -------------------------------------------------------------------------------- -- Settings: --- Highlight the row the cursor is currently on. -opt.cursorline = true --- Ignore case when searching. -opt.ignorecase = true --- Don't ignore case if search contains capitals. -opt.smartcase = true --- Wrap when jumping through search results. -opt.wrapscan = false --- Show line numbers. -opt.number = true --- Set relative line number. -opt.relativenumber = true --- Keep the lines above and below the cursor. -opt.scrolloff = 1 --- Draw a signcolumn. -opt.signcolumn = "yes" --- Set terminal colours. -opt.termguicolors = true --- Timeout between mapped key sequence presses. -opt.timeoutlen = 200 --- Sets coloured bar as a text-width guide. -opt.colorcolumn = "81" --- Text-wrapping width. -opt.textwidth = 80 --- Set tab width. -opt.tabstop = 4 --- Set width for indention shifts. -opt.shiftwidth = 4 --- Show current mode on the last line. -opt.showmode = false --- Where to draw the statusline. -opt.laststatus = 3 --- Spellcheck language. -opt.spelllang = "en_gb" - --- Add OCaml indent tool to runtimepath -opt.runtimepath:prepend("~/.opam/cs3110-2023sp/share/ocp-indent/vim") - -cmd("colorscheme tokyonight") - -cmd("filetype plugin on") - --- Jump to the last visited position in the file. -augroup("jumpLastPosition", {clear = true}) -autocmd({"BufReadPost"}, { - group = "jumpLastPosition", - callback = - function() - local ft = vim.opt_local.filetype:get() - -- don"t apply to git messages - if (ft:match("commit") or ft:match("rebase")) then - return - end - -- get position of last saved edit - local markpos = api.nvim_buf_get_mark(0, '"') - local line = markpos[1] - local col = markpos[2] - -- if in range, go there - if (line > 1) and (line <= api.nvim_buf_line_count(0)) then - api.nvim_win_set_cursor(0, {line,col}) - end - end -}) - --- Load templates based on file extensions. -augroup("templates", {clear = true}) -autocmd("BufNewFile", { - group = "templates", - command = [[silent! execute '0r ~/.config/nvim/templates/template.'.expand(":e")]] -}) -autocmd("BufNewFile", { - group = "templates", - pattern = "makefile", - command = "silent! 0r ~/.config/nvim/templates/template.makefile" -}) - --- Delete trailing whitespace before saving. -augroup("deleteTrailingSpace", {clear = true}) -autocmd("BufWritePre", { - group = "deleteTrailingSpace", - callback = - function() - local view = func.winsaveview() - cmd([[silent! %s/\s\+$//g]]) - func.winrestview(view) - end, - desc = "Delete trailing whitespace before saving" -}) - --------------------------------------------------------------------------------- --- Mappings: --- Normal-mode mappings: -local mapOpts = {silent = true} -map("n", "s", ":setlocal spell!", mapOpts) -map("n", "", ':noh:let @/="ldsfl2393rj0mash02enp3irdsfc"', mapOpts) -map("n", "daa", "ggdG", mapOpts) -map("n", "zt", "zt2", mapOpts) -map("n", "zb", "zb2", mapOpts) --- Fold around a code-block. -map("n", "ff", "zfaB", mapOpts) -map("n", "p", "gwap", mapOpts) -map("n", "K", ":Man", mapOpts) -map("n", "gb", "gT", mapOpts) -map("n", "", ":Texplore", mapOpts) - --- Insert-mode mappings -map("i", ",,", "", mapOpts) - --- Plugin specific bindings: --- CoC Mappings Stolen from neoclide/coc.nvim/README.md --- Use `[g` and `]g` to navigate diagnostics -map("n", "[g", "(coc-diagnostic-prev)", mapOpts) -map("n", "]g", "(coc-diagnostic-next)", mapOpts) - --- Go-to code navigation. Use to go back through the stack. -map("n", "gd", "(coc-definition)", mapOpts) -map("n", "gy", "(coc-type-definition)", mapOpts) -map("n", "gi", "(coc-implementation)", mapOpts) -map("n", "gr", "(coc-references)", mapOpts) - --- Rename a symbol. -map("n", "rn", "(coc-rename)", mapOpts) - --- Apply AutoFix to problem on the current line. -map("n", "qf", "(coc-fix-current)", {silent = true, nowait = true}) - --- Use KK to show documentation in preview window. -function _G.show_docs() - local cw = func.expand("") - if func.index({"vim", "help"}, vim.bo.filetype) >= 0 then - api.nvim_command("h " .. cw) - elseif api.nvim_eval("coc#rpc#ready()") then - func.CocActionAsync("doHover") - else - api.nvim_command("!" .. vim.o.keywordprg .. " " .. cw) - end -end -map("n", "KK", ":lua _G.show_docs()", mapOpts) - -augroup("cocGolang", {clear = true}) -autocmd("BufWritePre", { - group = "cocGolang", - pattern = "go", - command = 'silent! call CocAction("runCommand", "editor.action.organizeImport")', - desc = "Organise imported Go modules" -}) +require("options") +require("mappings") +require("autocmds") diff --git a/neovim/.config/nvim/lazy-lock.json b/neovim/.config/nvim/lazy-lock.json deleted file mode 100644 index 39f7864..0000000 --- a/neovim/.config/nvim/lazy-lock.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "auto-pairs": { "branch": "master", "commit": "39f06b873a8449af8ff6a3eee716d3da14d63a76" }, - "coc.nvim": { "branch": "release", "commit": "bbaa1d5d1ff3cbd9d26bb37cfda1a990494c4043" }, - "lazy.nvim": { "branch": "main", "commit": "25beed5e2e935ebc00d7e3eed1dc502df3c40e39" }, - "lualine.nvim": { "branch": "master", "commit": "05d78e9fd0cdfb4545974a5aa14b1be95a86e9c9" }, - "nvim-web-devicons": { "branch": "master", "commit": "efbfed0567ef4bfac3ce630524a0f6c8451c5534" }, - "tokyonight.nvim": { "branch": "main", "commit": "1ee11019f8a81dac989ae1db1a013e3d582e2033" }, - "vimtex": { "branch": "master", "commit": "08371bf97a9c4ce3dbdf996161faf04ff8b32aa0" } -} \ No newline at end of file diff --git a/neovim/.config/nvim/lua/autocmds.lua b/neovim/.config/nvim/lua/autocmds.lua new file mode 100644 index 0000000..8ef01b8 --- /dev/null +++ b/neovim/.config/nvim/lua/autocmds.lua @@ -0,0 +1,73 @@ +local augroup = vim.api.nvim_create_augroup +local autocmd = vim.api.nvim_create_autocmd +local cmd = vim.cmd +local func = vim.fn +local api = vim.api + +-- Jump to the last visited position in the file. +augroup("jumpLastPosition", {clear = true}) +autocmd({"BufReadPost"}, { + group = "jumpLastPosition", + callback = + function() + local ft = vim.opt_local.filetype:get() + -- don"t apply to git messages + if (ft:match("commit") or ft:match("rebase")) then + return + end + -- get position of last saved edit + local markpos = api.nvim_buf_get_mark(0, '"') + local line = markpos[1] + local col = markpos[2] + -- if in range, go there + if (line > 1) and (line <= api.nvim_buf_line_count(0)) then + api.nvim_win_set_cursor(0, {line,col}) + end + end +}) + +-- Load templates based on file extensions. +augroup("templates", {clear = true}) +autocmd("BufNewFile", { + group = "templates", + command = [[silent! execute '0r ~/.config/nvim/templates/template.'.expand(":e")]] +}) +autocmd("BufNewFile", { + group = "templates", + pattern = "makefile", + command = "silent! 0r ~/.config/nvim/templates/template.makefile" +}) + +-- Delete trailing whitespace before saving. +augroup("deleteTrailingSpace", {clear = true}) +autocmd("BufWritePre", { + group = "deleteTrailingSpace", + callback = + function() + local view = func.winsaveview() + cmd([[silent! %s/\s\+$//g]]) + func.winrestview(view) + end, + desc = "Delete trailing whitespace before saving" +}) + +-- Highlight yanked text for a short time. +augroup("highlightOnYank", {clear = true}) +autocmd("TextYankPost", { + group = "highlightOnYank", + command = [[silent! lua vim.highlight.on_yank({higroup = "IncSearch", timeout = 100})]] +}) + +-- Track daily thesis progress. +augroup("thesisProgress", {clear = true}) +local progressScript = "~/Documents/CourseWork/Cambridge/MPhilThesis/paper/progress.sh" +autocmd("BufWritePost", { + group = "thesisProgress", + pattern = "*/MPhilThesis/paper/**.tex", + callback = + function () + local progress = func.system(progressScript) + cmd("redraw") + print(progress) + end +}) diff --git a/neovim/.config/nvim/lua/lazy-setup.lua b/neovim/.config/nvim/lua/lazy-setup.lua new file mode 100644 index 0000000..4d6caff --- /dev/null +++ b/neovim/.config/nvim/lua/lazy-setup.lua @@ -0,0 +1,16 @@ +-- Bootstrap lazy.nvim if it's not installed. +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", + lazypath + } +end +vim.opt.runtimepath:prepend(lazypath) + +-- Set up all plugins in the lua/plugins directory +require("lazy").setup("plugins") diff --git a/neovim/.config/nvim/lua/mappings.lua b/neovim/.config/nvim/lua/mappings.lua new file mode 100644 index 0000000..95eea01 --- /dev/null +++ b/neovim/.config/nvim/lua/mappings.lua @@ -0,0 +1,21 @@ +local map = vim.keymap.set +local mapOpts = {silent = true} + +-- Normal-mode mappings: +map("n", "s", ":setlocal spell!", mapOpts) +map("n", "", ':noh:let @/="ldsfl2393rj0mash02enp3irdsfc"', mapOpts) +map("n", "daa", "ggdG", mapOpts) +map("n", "zt", "zt2", mapOpts) +map("n", "zb", "zb2", mapOpts) +-- Fold around a code-block. +map("n", "p", "gwap", mapOpts) +map("n", "K", ":Man", mapOpts) +map("n", "gb", "gT", mapOpts) +map("n", "", ":Texplore", mapOpts) +map("n", "[b", ":bprevious", mapOpts) +map("n", "]b", ":bnext", mapOpts) +-- Commonly mistyped quit. +map("n", "q:", ":q") + +-- Insert-mode mappings +map("i", ",,", "", mapOpts) diff --git a/neovim/.config/nvim/lua/options.lua b/neovim/.config/nvim/lua/options.lua new file mode 100644 index 0000000..9af066c --- /dev/null +++ b/neovim/.config/nvim/lua/options.lua @@ -0,0 +1,29 @@ +local opt = vim.opt +local cmd = vim.cmd + +opt.cursorline = true +opt.ignorecase = true +opt.smartcase = true +opt.wrapscan = false +opt.number = true +opt.relativenumber = true +opt.scrolloff = 1 +opt.signcolumn = "yes" +opt.termguicolors = true +opt.timeoutlen = 300 +opt.colorcolumn = "81" +opt.textwidth = 80 +opt.tabstop = 4 +opt.shiftwidth = 4 +opt.showmode = false +opt.laststatus = 3 +opt.spelllang = "en_gb" +opt.hidden = true + +-- Add OCaml indent tool to runtimepath +opt.runtimepath:prepend("~/.opam/cs3110-2023sp/share/ocp-indent/vim") + +cmd("colorscheme tokyonight") + +cmd("filetype plugin on") + diff --git a/neovim/.config/nvim/lua/plugins/autopairs/init.lua b/neovim/.config/nvim/lua/plugins/autopairs/init.lua new file mode 100644 index 0000000..5f728dd --- /dev/null +++ b/neovim/.config/nvim/lua/plugins/autopairs/init.lua @@ -0,0 +1,4 @@ +-- Insert or delete brackets, parenthesis, quotes in pairs. +return { + "jiangmiao/auto-pairs" +} diff --git a/neovim/.config/nvim/lua/plugins/coc/autocmds.lua b/neovim/.config/nvim/lua/plugins/coc/autocmds.lua new file mode 100644 index 0000000..561ff3c --- /dev/null +++ b/neovim/.config/nvim/lua/plugins/coc/autocmds.lua @@ -0,0 +1,10 @@ +local augroup = vim.api.nvim_create_augroup +local autocmd = vim.api.nvim_create_autocmd + +augroup("cocGolang", {clear = true}) +autocmd("BufWritePre", { + group = "cocGolang", + pattern = "go", + command = [[silent! call CocAction("runCommand", "editor.action.organizeImport")]], + desc = "Organise imported Go modules" +}) diff --git a/neovim/.config/nvim/lua/plugins/coc/init.lua b/neovim/.config/nvim/lua/plugins/coc/init.lua new file mode 100644 index 0000000..d01b577 --- /dev/null +++ b/neovim/.config/nvim/lua/plugins/coc/init.lua @@ -0,0 +1,8 @@ +-- Extension and language-server host for Neovim. +require("plugins.coc.mappings") +require("plugins.coc.autocmds") + +return { + "neoclide/coc.nvim", + branch = "release" +} diff --git a/neovim/.config/nvim/lua/plugins/coc/mappings.lua b/neovim/.config/nvim/lua/plugins/coc/mappings.lua new file mode 100644 index 0000000..bcbbaac --- /dev/null +++ b/neovim/.config/nvim/lua/plugins/coc/mappings.lua @@ -0,0 +1,47 @@ +local map = vim.keymap.set + +local cocMapOpts = { + silent = true, + noremap = true, + expr = true, + replace_keycodes = false +} + +-- Use to cycle completions. +function _G.check_back_space() + local col = vim.fn.col(".") - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") ~= nil +end +map("i", "", [[coc#pum#visible() ? coc#pum#next(1) : v:lua.check_back_space() ? "" : coc#refresh()]], cocMapOpts) +map("i", "", [[coc#pum#visible() ? coc#pum#prev(1) : "\"]], cocMapOpts) +-- Use to confirm completion. +map("i", "", [[coc#pum#visible() ? coc#pum#confirm() : "\u\\=coc#on_enter()\"]], cocMapOpts) + +-- Use `[g` and `]g` to navigate diagnostics +map("n", "[g", "(coc-diagnostic-prev)", mapOpts) +map("n", "]g", "(coc-diagnostic-next)", mapOpts) + +-- Go-to code navigation. Use to go back through the stack. +map("n", "gd", "(coc-definition)", mapOpts) +map("n", "gy", "(coc-type-definition)", mapOpts) +map("n", "gi", "(coc-implementation)", mapOpts) +map("n", "gr", "(coc-references)", mapOpts) + +-- Rename a symbol. +map("n", "rn", "(coc-rename)", mapOpts) + +-- Apply AutoFix to problem on the current line. +map("n", "qf", "(coc-fix-current)", {silent = true, nowait = true}) + +-- Use KK to show documentation in preview window. +function _G.show_docs() + local cw = vim.fn.expand("") + if vim.fn.index({"vim", "help"}, vim.bo.filetype) >= 0 then + vim.api.nvim_command("h " .. cw) + elseif vim.api.nvim_eval("coc#rpc#ready()") then + vim.fn.CocActionAsync("doHover") + else + vim.api.nvim_command("!" .. vim.o.keywordprg .. " " .. cw) + end +end +map("n", "KK", ":lua _G.show_docs()", mapOpts) diff --git a/neovim/.config/nvim/lua/plugins/fzf/init.lua b/neovim/.config/nvim/lua/plugins/fzf/init.lua new file mode 100644 index 0000000..5e059bb --- /dev/null +++ b/neovim/.config/nvim/lua/plugins/fzf/init.lua @@ -0,0 +1,11 @@ +-- fzf wrapper plugin. +-- Replace :buffers mapping if fzf plugin is available. +local mapOpts = {silent = true} + +vim.g.fzf_preview_window = "up,50%" +vim.keymap.set("n", "b", ":Buffers", mapOpts) +vim.keymap.set("n", "o", ":Files", mapOpts) + +return { + "junegunn/fzf.vim" +} diff --git a/neovim/.config/nvim/lua/plugins/indent-blankline/init.lua b/neovim/.config/nvim/lua/plugins/indent-blankline/init.lua new file mode 100644 index 0000000..f04196a --- /dev/null +++ b/neovim/.config/nvim/lua/plugins/indent-blankline/init.lua @@ -0,0 +1,9 @@ +-- Draw indentation guides. +return { + "lukas-reineke/indent-blankline.nvim", + + opts = { + show_current_context = true, + show_current_context_start = false, + } +} diff --git a/neovim/.config/nvim/lua/plugins/lualine/init.lua b/neovim/.config/nvim/lua/plugins/lualine/init.lua new file mode 100644 index 0000000..660eb94 --- /dev/null +++ b/neovim/.config/nvim/lua/plugins/lualine/init.lua @@ -0,0 +1,37 @@ +-- Statusline plugin written in pure lua. +local function spellStatus() + if vim.wo.spell == true then -- Note that 'spell' is a window option, so: wo + return "󱓷 " .. vim.bo.spelllang + end + return "" +end + +return { + "nvim-lualine/lualine.nvim", + + opts = { + options = { + theme = "tokyonight" + }, + sections = { + lualine_a = {"mode"}, + lualine_b = {"diagnostics"}, + lualine_c = { + { + "filename", + symbols = { + readonly = "󰌾" + } + }, + spellStatus, + }, + lualine_x = {{"filetype", icon_only = true}}, + lualine_y = {"progress"}, + lualine_z = {"location"} + }, + tabline = { + lualine_a = {"buffers"}, + lualine_z = {"tabs"} + } + } +} diff --git a/neovim/.config/nvim/lua/plugins/nvim-treesitter/init.lua b/neovim/.config/nvim/lua/plugins/nvim-treesitter/init.lua new file mode 100644 index 0000000..b98cb84 --- /dev/null +++ b/neovim/.config/nvim/lua/plugins/nvim-treesitter/init.lua @@ -0,0 +1,20 @@ +-- Interface to the tree-sitter incremental parsing library. +return { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + + config = function () + require("nvim-treesitter.configs").setup { + ensure_installed = { + "c", + "cpp", + "go", + "python", + "lua", + "ocaml" + }, + highlight = { enable = true }, + indent = { enable = true } + } + end +} diff --git a/neovim/.config/nvim/lua/plugins/nvim-web-devicons/init.lua b/neovim/.config/nvim/lua/plugins/nvim-web-devicons/init.lua new file mode 100644 index 0000000..addb386 --- /dev/null +++ b/neovim/.config/nvim/lua/plugins/nvim-web-devicons/init.lua @@ -0,0 +1,5 @@ +-- Adds icons to Neovim plugins. +return { + "nvim-tree/nvim-web-devicons", + lazy = true +} diff --git a/neovim/.config/nvim/lua/plugins/tokyonight/init.lua b/neovim/.config/nvim/lua/plugins/tokyonight/init.lua new file mode 100644 index 0000000..da69410 --- /dev/null +++ b/neovim/.config/nvim/lua/plugins/tokyonight/init.lua @@ -0,0 +1,17 @@ +-- Tokyo Night colourscheme. +return { + "folke/tokyonight.nvim", + priority = 1000, + + opts = { + style = "night", + + on_highlights = + function(highlights, colors) + highlights.IncSearch = { + bg = colors.magenta, + fg = colors.black + } + end + } +} diff --git a/neovim/.config/nvim/lua/plugins/vimtex/init.lua b/neovim/.config/nvim/lua/plugins/vimtex/init.lua new file mode 100644 index 0000000..34b70e5 --- /dev/null +++ b/neovim/.config/nvim/lua/plugins/vimtex/init.lua @@ -0,0 +1,7 @@ +-- A modern filetype plugin for LaTeX. +vim.g.vimtex_view_method = "sioyek" + +return { + "lervag/vimtex", + ft = "tex" +}