From bf175d083fcbaf81528d695f1cbb2db885189b7c Mon Sep 17 00:00:00 2001 From: tiynger Date: Wed, 16 Oct 2019 16:25:42 +0200 Subject: [PATCH] enhancing tex feeling in vim --- .config/aliasrc | 4 +-- .config/nvim/init.vim | 41 +++++++++++++++++------------ .local/bin/tools/compiler | 38 ++++++++++++++++++++++++++ .local/bin/{ => tools}/dmenuunicode | 0 .local/bin/tools/texclear | 14 ++++++++++ .local/bin/unix | 25 ------------------ 6 files changed, 78 insertions(+), 44 deletions(-) create mode 100755 .local/bin/tools/compiler rename .local/bin/{ => tools}/dmenuunicode (100%) create mode 100755 .local/bin/tools/texclear delete mode 100755 .local/bin/unix diff --git a/.config/aliasrc b/.config/aliasrc index 7e4d614..f070321 100644 --- a/.config/aliasrc +++ b/.config/aliasrc @@ -26,9 +26,9 @@ sc() { find ~/.config/* ~/.local/bin/* -type f | fzf | xargs -r $EDITOR ;} sd() { find ~/ownCloud/* -type f | grep ".pdf" | fzf | xargs -r $READER ;} # git -texhandout() { +texhandout() { [[ -z $1 ]] && echo "missing argument: filename (no ending)" && return 1 - cp ~/gitrepos/Tools/LaTeX\ Templates/LaTeX\ Handout/Handout.tex $1.tex && xelatex $1.tex + cp ~/gitrepos/Tools/LaTeX\ Templates/LaTeX\ Handout/Handout.tex $1.tex && compile $1.tex } # grep diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index c415317..735d41f 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -1,3 +1,5 @@ +let mapleader ="," + if ! filereadable(expand('~/.config/nvim/autoload/plug.vim')) echo "Downloading junegunn/vim-plug to manage plugins..." silent !mkdir -p ~/.config/nvim/autoload/ @@ -11,21 +13,33 @@ set nohlsearch set clipboard=unnamedplus " Some basics: - nnoremap c "_c - set nocompatible - filetype plugin on - syntax on - set encoding=utf-8 - set number relativenumber +nnoremap c "_c +set nocompatible +filetype plugin on +syntax on +set encoding=utf-8 +set number relativenumber " Disables automatic commenting on newline: - autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o +autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o " Splits open at the bottom and right, which is non-retarded, unlike vim defaults. - set splitbelow splitright +set splitbelow splitright " Copy selected text to system clipboard (requires gvim/nvim/vim-x11 installed): - vnoremap "+y - map "+P +vnoremap "+y +map "+P + +" Read files correctly +autocmd BufRead,BufNewFile *.tex set filetype=tex + +" Compiler for languages +map c :w! \| !compiler % + +" Clean LaTex build files +autocmd VimLeave *.tex !texclear % + +" Delete trailing whitespaces on save +autocmd BufWritePre * %s/\s\+$//e " Plugin section call plug#begin('~/.config/nvim/plugged') @@ -34,12 +48,7 @@ Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } Plug 'lervag/vimtex', {'for': 'tex'} Plug 'artur-shaik/vim-javacomplete2' call plug#end() - -" neotex let g:neotex_enabled = 2 -let g:neotex_pdflatex_alternative = 'xelatex' - -" deoplete let g:deoplete#enable_at_startup = 1 let g:deoplete#enable_smart_case = 1 let g:deoplete#sources = {} @@ -47,7 +56,6 @@ let g:deoplete#sources.java = ['jc', 'javacomplete2', 'file', 'buffer'] call deoplete#custom#var('omni', 'input_patterns', { \ 'tex': g:vimtex#re#deoplete \}) - "tab as remapping for deoplete inoremap \ pumvisible() ? "\" : @@ -57,6 +65,5 @@ function! s:check_back_space() abort "" {{{ let col = col('.') - 1 return !col || getline('.')[col - 1] =~ '\s' endfunction "" }}} - " javacomplete2 autocmd FileType java setlocal omnifunc=javacomplete#Complete diff --git a/.local/bin/tools/compiler b/.local/bin/tools/compiler new file mode 100755 index 0000000..201064e --- /dev/null +++ b/.local/bin/tools/compiler @@ -0,0 +1,38 @@ +#!/usr/bin/env 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. Opens .sent files as sent +# presentations. Runs scripts based on extention or shebang + +file=$(readlink -f "$1") +dir=$(dirname "$file") +base="${file%.*}" + +cd "$dir" || exit + +textype() { \ + command="pdflatex" + ( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex" + $command --output-directory="$dir" "$base" && + grep -i addbibresource "$file" >/dev/null && + biber --input-directory "$dir" "$base" && + $command --output-directory="$dir" "$base" && + $command --output-directory="$dir" "$base" + } + +case "$file" in + *\.ms) refer -PS -e "$file" | groff -me -ms -kept -T pdf > "$base".pdf ;; + *\.mom) refer -PS -e "$file" | groff -mom -kept -T pdf > "$base".pdf ;; + *\.[0-9]) refer -PS -e "$file" | groff -mandoc -T pdf > "$base".pdf ;; + *\.rmd) echo "require(rmarkdown); render('$file')" | R -q --vanilla ;; + *\.tex) textype "$file" ;; + *\.md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;; + *config.h) sudo make install ;; + *\.c) cc "$file" -o "$base" && "$base" ;; + *\.py) python "$file" ;; + *\.go) go run "$file" ;; + *\.sent) setsid sent "$file" 2>/dev/null & ;; + *) sed 1q "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;; +esac diff --git a/.local/bin/dmenuunicode b/.local/bin/tools/dmenuunicode similarity index 100% rename from .local/bin/dmenuunicode rename to .local/bin/tools/dmenuunicode diff --git a/.local/bin/tools/texclear b/.local/bin/tools/texclear new file mode 100755 index 0000000..83fd586 --- /dev/null +++ b/.local/bin/tools/texclear @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# Clears the build files of a LaTeX/XeLaTeX build. +# I have vim run this file whenever I exit a .tex file. + +case "$1" in + *.tex) + file=$(readlink -f "$1") + dir=$(dirname "$file") + base="${file%.*}" + find "$dir" -maxdepth 1 -type f -regextype gnu-awk -regex "^$base\\.(4tc|xref|tmp|pyc|pyo|fls|vrb|fdb_latexmk|bak|swp|aux|log|synctex\\(busy\\)|lof|lot|maf|idx|mtc|mtc0|nav|out|snm|toc|bcf|run\\.xml|synctex\\.gz|blg|bbl)" -delete ;; + *) printf "Give .tex file as argument.\\n" ;; +esac + diff --git a/.local/bin/unix b/.local/bin/unix deleted file mode 100755 index 14d7ef0..0000000 --- a/.local/bin/unix +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh -#original artwork by http://www.sanderfocus.nl/#/portfolio/tech-heroes -#converted to shell by #nixers @ irc.unix.chat - -cat << 'eof' - ,_ ,_==▄▂ - , ▂▃▄▄▅▅▅▂▅¾. / / - ▄▆<´ "»▓▓▓%\ / / / / - ,▅7" ´>▓▓▓% / / > / >/% - ▐¶▓ ,»▓▓¾´ /> %/%// / / - ▓▃▅▅▅▃,,▄▅▅▅Æ\// ///>// />/ / - V║«¼.;→ ║<«.,`=// />//%/% / / - //╠<´ -²,)(▓~"-╝/¾/ %/>/ /> - / / / ▐% -./▄▃▄▅▐, /7//;//% / / - / ////`▌▐ %zWv xX▓▇▌//&;% / / - / / / %//%/¾½´▌▃▄▄▄▄▃▃▐¶\/& / - </ /)VY>7; \_ UNIX IS VERY SIMPLE IT JUST NEEDS A - / /</ //<///<_/%\▓ V%W%£)XY _/%‾\_, GENIUS TO UNDERSTAND ITS SIMPLICITY - / / //%/_,=--^/%/%%\¾%¶%%} /%%%%%%;\, - %/< /_/ %%%%%;X%%\%%;, _/%%%;, \ - / / %%%%%%;, \%%l%%;// _/%;, dmr - / %%%;, <;\-=-/ / - ;, l -eof \ No newline at end of file