commit a1db2f0e2e1f7d0bd7f372269282d16a39defa0d
parent a43765c1af2489d14c41ed9fe3ebe0f2f5c649db
Author: Markus Hanetzok <markus@hanetzok.net>
Date: Sun, 1 Dec 2024 00:58:33 +0100
add nvim config and scripts
copied some scripts from Luke Smiths voidrice repo
(https://github.com/lukesmithxyz/voidrice) and added config for neovim
Diffstat:
4 files changed, 216 insertions(+), 0 deletions(-)
diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim
@@ -0,0 +1,140 @@
+let mapleader =" "
+
+if ! filereadable(system('echo -n "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim"'))
+ echo "Downloading junegunn/vim-plug to manage plugins..."
+ silent !mkdir -p ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/
+ silent !curl "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" > ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim
+ autocmd VimEnter * PlugInstall
+endif
+
+map ,, :keepp /<++><CR>ca<
+imap ,, <esc>:keepp /<++><CR>ca<
+
+call plug#begin(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'
+call plug#end()
+
+set title
+set bg=dark
+set go=a
+set mouse=a
+set nohlsearch
+set clipboard+=unnamedplus
+set noshowmode
+set noruler
+set laststatus=0
+set noshowcmd
+set tw=79
+set shiftwidth=2
+colorscheme elflord
+
+" Some basics:
+ nnoremap c "_c
+ filetype plugin on
+ syntax on
+ set encoding=utf-8
+ set number relativenumber
+" Enable autocompletion:
+ set wildmode=longest,list,full
+" Disables automatic commenting on newline:
+ autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
+" Perform dot commands over visual blocks:
+ vnoremap . :normal .<CR>
+" Goyo plugin makes text more readable when writing prose:
+ map <leader>f :Goyo \| set bg=dark \| set linebreak<CR>
+" Spell-check set to <leader>o, 'o' for 'orthography':
+ map <leader>o :setlocal spell! spelllang=de_de<CR>
+" Splits open at the bottom and right, which is non-retarded, unlike vim defaults.
+ set splitbelow splitright
+
+" Nerd tree
+ map <leader>q :NERDTreeToggle<CR>
+ autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
+ let NERDTreeBookmarksFile = stdpath('data') . '/NERDTreeBookmarks'
+
+" vim-airline
+ if !exists('g:airline_symbols')
+ let g:airline_symbols = {}
+ endif
+ let g:airline_symbols.colnr = ' C:'
+ let g:airline_symbols.linenr = ' L:'
+ let g:airline_symbols.maxlinenr = '☰ '
+
+" Shortcutting split navigation, saving a keypress:
+ map <C-h> <C-w>h
+ map <C-j> <C-w>j
+ map <C-k> <C-w>k
+ map <C-l> <C-w>l
+
+" Replace ex mode with gq
+ map Q gq
+
+" Check file in shellcheck:
+ map <leader>s :!clear && shellcheck -x %<CR>
+
+" Replace all is aliased to S.
+ nnoremap S :%s//g<Left><Left>
+
+" Compile document, be it groff/LaTeX/markdown/etc.
+ map <leader>c :w! \| !compiler "%:p"<CR>
+
+" Open corresponding .pdf/.html or preview
+ map <leader>p :!opout "%:p"<CR>
+
+" 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:
+ let g:vimwiki_ext2syntax = {'.Rmd': 'markdown', '.rmd': 'markdown','.md': 'markdown', '.markdown': 'markdown', '.mdown': 'markdown'}
+ map <leader>v :VimwikiIndex<CR>
+ let g:vimwiki_list = [{'path': '~/.local/share/nvim/vimwiki', 'syntax': 'markdown', 'ext': '.md'}]
+ 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
+
+" Save file as sudo on files that require root permission
+ cabbrev w!! execute 'silent! write !sudo tee % >/dev/null' <bar> edit!
+
+" Enable Goyo by default for mutt writing
+ autocmd BufRead,BufNewFile /tmp/neomutt* :Goyo 80 | call feedkeys("jk")
+ 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 *.[ch] %s/\%$/\r/e " add trailing newline for ANSI C standard
+ autocmd BufWritePre *neomutt* %s/^--$/-- /e " dash-dash-space signature delimiter in emails
+ autocmd BufWritePre * cal cursor(currPos[1], currPos[2])
+
+" 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 &diff
+ highlight! link DiffText MatchParen
+endif
+
+" Function for toggling the bottom statusbar:
+let s:hidden_all = 0
+function! ToggleHiddenAll()
+ if s:hidden_all == 0
+ let s:hidden_all = 1
+ set noshowmode
+ set noruler
+ set laststatus=0
+ set noshowcmd
+ else
+ let s:hidden_all = 0
+ set showmode
+ set ruler
+ set laststatus=2
+ set showcmd
+ endif
+endfunction
+nnoremap <leader>h :call ToggleHiddenAll()<CR>
diff --git a/.local/bin/compiler b/.local/bin/compiler
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+# This script will compile or run another finishing operation on a document. I
+# have this script run via vim.
+
+# Compiles .tex. groff (.mom, .ms), .rmd, .md, .org. Opens .sent files as sent
+# presentations. Runs scripts based on extension or shebang.
+
+# Note that .tex files which you wish to compile with XeLaTeX should have the
+# string "xelatex" somewhere in a comment/command in the first 5 lines.
+
+file="${1}"
+ext="${file##*.}"
+dir=${file%/*}
+base="${file%.*}"
+
+cd "${dir}" || exit "1"
+
+case "${ext}" in
+ [0-9]) preconv "${file}" | refer -PS -e | groff -mandoc -T pdf > "${base}.pdf" ;;
+ mom|ms) preconv "${file}" | refer -PS -e | groff -T pdf -m"${ext}" > "${base}.pdf" ;;
+ c) cc "${file}" -o "${base}" && "./${base}" ;;
+ cpp) g++ "${file}" -o "${base}" && "./${base}" ;;
+ cs) mcs "${file}" && mono "${base}.exe" ;;
+ go) go run "${file}" ;;
+ h) sudo make install ;;
+ java) javac -d classes "${file}" && java -cp classes "${base}" ;;
+ m) octave "${file}" ;;
+ md) [ -x "$(command -v lowdown)" ] && \
+ lowdown --parse-no-intraemph "${file}" -Tms | groff -mpdfmark -ms -kept -T pdf > "${base}.pdf" || \
+ [ -x "$(command -v groffdown)" ] && \
+ groffdown -i "${file}" | groff -T pdf > "${base}.pdf" || \
+ pandoc -t ms --highlight-style="kate" -s -o "${base}.pdf" "${file}" ;;
+ org) emacs "${file}" --batch -u "${USER}" -f org-latex-export-to-pdf ;;
+ py) python "${file}" ;;
+ [rR]md) Rscript -e "rmarkdown::render('${file}', quiet=TRUE)" ;;
+ rs) cargo build ;;
+ sass) sassc -a "${file}" "${base}.css" ;;
+ scad) openscad -o "${base}.stl" "${file}" ;;
+ sent) setsid -f sent "${file}" 2> "/dev/null" ;;
+ tex)
+ textarget="$(getcomproot "${file}" || echo "${file}")"
+ command="pdflatex"
+ head -n5 "${textarget}" | grep -qi "xelatex" && command="xelatex"
+ ${command} --output-directory="${textarget%/*}" "${textarget%.*}" &&
+ grep -qi addbibresource "${textarget}" &&
+ biber --input-directory "${textarget%/*}" "${textarget%.*}" &&
+ ${command} --output-directory="${textarget%/*}" "${textarget%.*}" &&
+ ${command} --output-directory="${textarget%/*}" "${textarget%.*}"
+ ;;
+ *) sed -n '/^#!/s/^#!//p; q' "${file}" | xargs -r -I % "${file}" ;;
+esac
diff --git a/.local/bin/opout b/.local/bin/opout
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+# opout: "open output": A general handler for opening a file's intended output,
+# usually the pdf of a compiled document. I find this useful especially
+# running from vim.
+
+basename="${1%.*}"
+
+case "${*}" in
+ *.tex|*.sil|*.m[dse]|*.[rR]md|*.mom|*.[0-9]) target="$(getcomproot "$1" || echo "$1")" ; setsid -f xdg-open "${target%.*}".pdf >/dev/null 2>&1 ;;
+ *.html) setsid -f "$BROWSER" "$basename".html >/dev/null 2>&1 ;;
+ *.sent) setsid -f sent "$1" >/dev/null 2>&1 ;;
+esac
diff --git a/.local/bin/remaps b/.local/bin/remaps
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# This script is called on startup to remap keys.
+# Decrease key repeat delay to 300ms and increase key repeat rate to 50 per second.
+xset r rate 300 50
+# Map the caps lock key to super, and map the menu key to right super.
+setxkbmap -option caps:super,altwin:menu_win
+# When caps lock is pressed only once, treat it as escape.
+killall xcape 2>/dev/null ; xcape -e 'Super_L=Escape'
+# Turn off caps lock if on since there is no longer a key for it.
+xset -q | grep -q "Caps Lock:\s*on" && xdotool key Caps_Lock