From 78b6d2bf54f58a44155e0f1df67eb51ee0a172b9 Mon Sep 17 00:00:00 2001 From: FollieHiyuki Date: Sat, 4 Sep 2021 02:15:41 +0700 Subject: [PATCH] neovim: add nvim-lint, nvim-dap-ui, vimtex --- home/.config/nvim/after/ftplugin/markdown.vim | 2 +- home/.config/nvim/after/ftplugin/tex.vim | 2 +- home/.config/nvim/lua/events.lua | 7 ++- home/.config/nvim/lua/mappings.lua | 19 ++++++++ home/.config/nvim/lua/modules/lsp.lua | 30 +++++++++++++ home/.config/nvim/lua/modules/tools.lua | 3 ++ home/.config/nvim/lua/plugins.lua | 44 ++++++++++++++----- home/.config/nvim/scripts/sumneko_lua.sh | 3 ++ home/.local/bin/firefox-sync | 29 ++++++++++++ 9 files changed, 123 insertions(+), 16 deletions(-) create mode 100755 home/.local/bin/firefox-sync diff --git a/home/.config/nvim/after/ftplugin/markdown.vim b/home/.config/nvim/after/ftplugin/markdown.vim index 529b6c9..265dd39 100644 --- a/home/.config/nvim/after/ftplugin/markdown.vim +++ b/home/.config/nvim/after/ftplugin/markdown.vim @@ -1,2 +1,2 @@ setlocal wrap -setlocal nonumber norelativenumber +" setlocal nonumber norelativenumber diff --git a/home/.config/nvim/after/ftplugin/tex.vim b/home/.config/nvim/after/ftplugin/tex.vim index 529b6c9..265dd39 100644 --- a/home/.config/nvim/after/ftplugin/tex.vim +++ b/home/.config/nvim/after/ftplugin/tex.vim @@ -1,2 +1,2 @@ setlocal wrap -setlocal nonumber norelativenumber +" setlocal nonumber norelativenumber diff --git a/home/.config/nvim/lua/events.lua b/home/.config/nvim/lua/events.lua index bc1ca0b..dafe32b 100644 --- a/home/.config/nvim/lua/events.lua +++ b/home/.config/nvim/lua/events.lua @@ -25,8 +25,10 @@ function M.load_autocmds() plugins = { -- Wrap lines in preview window -- {"User TelescopePreviewerLoaded", [[setlocal wrap]]}, + -- Re-compile packer on config changed {"BufWritePost", "*.lua", "lua require('events').packer_compile()"}, + -- Register binding for ToggleTerm inside term mode {"TermEnter", "term://*toggleterm#*", "tnoremap :ToggleTerm"} }, @@ -47,6 +49,7 @@ function M.load_autocmds() -- Auto-spelling in doc files {"BufNewFile,BufRead", "*.md,*.mkd", "setlocal spell"}, {"BufNewFile,BufRead", "*.tex", "setlocal spell"}, + -- Auto-hide numbers, statusline in specific buffers -- {"BufEnter", "term://*", "setlocal norelativenumber nonumber"}, -- {"BufEnter", "term://*", "set laststatus=0"}, @@ -56,8 +59,10 @@ function M.load_autocmds() wins = { -- Equalize window dimensions when resizing vim window {"VimResized", "*", [[tabdo wincmd =]]}, + -- Force writing shada on leaving nvim {"VimLeave", "*", [[if has('nvim') | wshada! | else | wviminfo! | endif]]}, + -- Check if file changed when its window is focus, more eager than 'autoread' {"FocusGained", "* checktime"} }, @@ -66,8 +71,6 @@ function M.load_autocmds() {"FileType", "dashboard", "set showtabline=0 | autocmd WinLeave set showtabline=2"}, {"BufNewFile,BufRead", "*.md,*.mkd", "setfiletype markdown"}, {"BufNewFile,BufRead", "*.toml", "setfiletype toml"}, - {"BufNewFile,BufRead", "*.tex", "setfiletype tex"}, - {"BufNewFile,BufRead", "*.conf", "setfiletype cfg"}, {"BufNewFile,BufRead", "*.rasi", "setfiletype css"}, {"BufNewFile,BufRead", "vifmrc,*.vifm", "setfiletype vim"}, {"BufNewFile,BufRead", "*.log,*_log,*.LO,G*_LOG", "setfiletype log"} diff --git a/home/.config/nvim/lua/mappings.lua b/home/.config/nvim/lua/mappings.lua index 9698004..8df7a21 100644 --- a/home/.config/nvim/lua/mappings.lua +++ b/home/.config/nvim/lua/mappings.lua @@ -119,6 +119,19 @@ wk.register({ z = {':ZenMode', 'Zen mode'} }, + d = { + name = 'DAP', + b = {':lua require("dap").toggle_breakpoint()', 'Toggle breakpoint'}, + c = {':lua require("dapui").close()', 'Close UI'}, + e = {':lua require("dapui").eval()', 'Evaluate cursorword'}, + f = {':lua require("dapui").float_element()', 'Float elements'}, + i = {':lua require("dap").repl.open()', 'Inspect via REPL'}, + n = {':lua require("dap").step_into()', 'Step through code'}, + o = {':lua require("dapui").open()', 'Open UI'}, + s = {':lua require("dap").continue()', 'Debug session'}, + t = {':lua require("dapui").open()', 'Toggle UI'} + }, + -- Telescope f = { name = 'Telescope', @@ -225,6 +238,12 @@ wk.register({ -- Visual mode (with leader key) -- ----------------------------------- wk.register({ + -- DAP + d = { + name = 'DAP', + e = {':lua require("dapui").eval()', 'Evaluate highlighted text'} + }, + -- GitSigns g = { name = 'Git', diff --git a/home/.config/nvim/lua/modules/lsp.lua b/home/.config/nvim/lua/modules/lsp.lua index fac90ec..f73c289 100644 --- a/home/.config/nvim/lua/modules/lsp.lua +++ b/home/.config/nvim/lua/modules/lsp.lua @@ -163,4 +163,34 @@ function M.outline_conf() } end +function M.lint_conf() + require('lint').linters_by_ft = { + markdown = {'vale', 'markdownlint', 'languagetool'}, + tex = {'vale', 'languagetool'}, + vim = {'vint'}, + -- lua = {'luacheck'}, + c = {'clangtidy', 'cppcheck'}, + cpp = {'clangtidy', 'clazy', 'cppcheck'}, + python = {'pylint', 'flake8', 'pycodestyle'}, + go = {'revive', 'golangcilint'}, + sh = {'shellcheck'}, + bash = {'shellcheck'}, + zsh = {'shellcheck'}, + html = {'tidy', 'stylelint'}, + css = {'stylelint'}, + scss = {'stylelint'}, + sass = {'stylelint'}, + javascript = {'eslint', 'stylelint'} + } + -- TODO: custom cmds for linters installed with pip (using virtualenv) + -- vint, pylint, flake8, pycodestyle, codespell + vim.cmd [[ au BufRead,BufWritePost * lua require('lint').try_lint() ]] +end + +function M.dap_conf() +end + +function M.dapui_conf() +end + return M diff --git a/home/.config/nvim/lua/modules/tools.lua b/home/.config/nvim/lua/modules/tools.lua index 5efcc48..05175f5 100644 --- a/home/.config/nvim/lua/modules/tools.lua +++ b/home/.config/nvim/lua/modules/tools.lua @@ -143,6 +143,9 @@ function M.orgmode_conf() }) end +function M.vimtex_conf() +end + function M.translate_conf() vim.g.trans_join_lines = 1 vim.g.trans_win_height = 15 diff --git a/home/.config/nvim/lua/plugins.lua b/home/.config/nvim/lua/plugins.lua index 4bb1fa7..0376271 100644 --- a/home/.config/nvim/lua/plugins.lua +++ b/home/.config/nvim/lua/plugins.lua @@ -13,6 +13,13 @@ return require('packer').startup( function(use) use {'wbthomason/packer.nvim', opt = true} + --------------------------------- + -- Plugins used by many others -- + --------------------------------- + use {'kyazdani42/nvim-web-devicons', module = 'nvim-web-devicons'} + use {'nvim-lua/plenary.nvim', module = 'plenary'} + use {'nvim-lua/popup.nvim', module = 'popup'} + -------- -- UI -- -------- @@ -31,10 +38,10 @@ return require('packer').startup( }, setup = ui.dashboard_conf } - use { -- TODO: consider moving to felline.nvim + use { -- TODO: consider moving to feline.nvim 'glepnir/galaxyline.nvim', branch = 'main', - requires = 'kyazdani42/nvim-web-devicons', + wants = 'nvim-web-devicons', config = ui.statusline_conf } use { @@ -55,7 +62,6 @@ return require('packer').startup( 'lewis6991/gitsigns.nvim', event = {'BufRead', 'BufNewFile'}, wants = 'plenary.nvim', - requires = {{'nvim-lua/plenary.nvim', opt = true}}, config = ui.gitsigns_conf } @@ -125,7 +131,7 @@ return require('packer').startup( -- LSP -- --------- local lsp = require('modules.lsp') - use { + use { -- TODO: scripts to install/update lsp servers 'neovim/nvim-lspconfig', event = 'BufReadPre', config = lsp.lsp_conf @@ -136,7 +142,7 @@ return require('packer').startup( wants = 'nvim-lspconfig', config = lsp.sqls_conf } - use { + use { -- TODO: config 'ray-x/lsp_signature.nvim', after = 'nvim-lspconfig' } @@ -154,6 +160,18 @@ return require('packer').startup( cmd = {'SymbolsOutline', 'SymbolsOutlineOpen'}, setup = lsp.outline_conf } + use { -- TODO: scripts to install/update linters + 'mfussenegger/nvim-lint', + event = 'BufRead', + config = lsp.lint_conf + } + use { -- TODO: config + 'rcarriga/nvim-dap-ui', + keys = 'd', + wants = 'nvim-dap', + requires = {{'mfussenegger/nvim-dap', config = lsp.dap_conf, opt = true}}, + config = lsp.dapui_conf + } ---------------- -- Completion -- @@ -162,7 +180,7 @@ return require('packer').startup( use { 'hrsh7th/nvim-cmp', event = 'InsertEnter', - wants = {'LuaSnip'}, + wants = 'LuaSnip', requires = { { 'L3MON4D3/LuaSnip', @@ -230,8 +248,6 @@ return require('packer').startup( 'telescope-fzf-native.nvim' }, requires = { - {'nvim-lua/popup.nvim', opt = true}, - {'nvim-lua/plenary.nvim', opt = true}, {'nvim-telescope/telescope-symbols.nvim', opt = true}, {'nvim-telescope/telescope-project.nvim', opt = true}, {'nvim-telescope/telescope-fzf-native.nvim', run = 'make', opt = true} @@ -257,7 +273,6 @@ return require('packer').startup( 'plenary.nvim' }, requires = { - {'nvim-lua/plenary.nvim', opt = true}, { 'sindrets/diffview.nvim', config = function() @@ -293,6 +308,11 @@ return require('packer').startup( ft = {'org'}, config = tools.orgmode_conf } + use { -- TODO: config + 'lervag/vimtex', + ft = 'tex', + setup = tools.vimtext_conf + } use { 'echuraev/translate-shell.vim', cmd = {'Trans', 'TransSelectDirection'}, @@ -314,7 +334,7 @@ return require('packer').startup( event = 'WinScrolled', config = tools.neoscroll_conf } - use { -- TODO: colors + use { -- TODO: colors + config 'michaelb/sniprun', run = 'bash ./install.sh 1', cmd = 'SnipRun' @@ -325,7 +345,7 @@ return require('packer').startup( } use {'tweekmonster/startuptime.vim', cmd = 'StartupTime'} -- Just for benchmarking - -- TODO: nvim-lint, rest.nvim, parinfer.nvim, editorconfig.nvim, conjure, - -- nvim-spectre, nvim-dap-ui, dial.nvim, asynctasks.nvim, hotpot.nvim + -- TODO: rest.nvim, parinfer.nvim, editorconfig.nvim, conjure, nvim-spectre, + -- dial.nvim, asynctasks.nvim, hotpot.nvim, rust-tools.nvim, crates.nvim, go.nvim end ) diff --git a/home/.config/nvim/scripts/sumneko_lua.sh b/home/.config/nvim/scripts/sumneko_lua.sh index 186025c..62db02c 100755 --- a/home/.config/nvim/scripts/sumneko_lua.sh +++ b/home/.config/nvim/scripts/sumneko_lua.sh @@ -20,4 +20,7 @@ cd 3rd/luamake cd ../.. ./3rd/luamake/luamake rebuild +# The build process automatically exports path to `~/.profile` +rm -rf ~/.profile + cd $current_path diff --git a/home/.local/bin/firefox-sync b/home/.local/bin/firefox-sync new file mode 100755 index 0000000..8ac62f0 --- /dev/null +++ b/home/.local/bin/firefox-sync @@ -0,0 +1,29 @@ +#!/bin/sh + +# A modified version compared to the one from the Arch Wiki +# (intended for using with Flatpak Firefox) + +static=static-$1 +link=$1 +volatile=/dev/shm/firefox-$1-$USER + +IFS= +set -efu + +cd ~/.var/app/org.mozilla.firefox/.mozilla/firefox + +if [ ! -r $volatile ]; then + mkdir -m0700 $volatile +fi + +if [ "$(readlink $link)" != "$volatile" ]; then + mv $link $static + ln -s $volatile $link +fi + +if [ -e $link/.unpacked ]; then + rsync -av --delete --exclude .unpacked ./$link/ ./$static/ +else + rsync -av ./$static/ ./$link/ + touch $link/.unpacked +fi