From e1b90958e2e7a0270c0c7326fc4c8997ba2b9e62 Mon Sep 17 00:00:00 2001 From: mitsuo Date: Wed, 2 Sep 2020 10:57:26 -0500 Subject: Markdown to pdf/html in Vim; fortune for bash --- bash_aliases | 14 +++++++--- bashrc | 12 ++++++-- fun.vim | 78 ++++++++++++++++++++++++++++++++++++++++------------ vimrc | 90 ++++++++++++++++++++++++++++++++++++++++++++++-------------- 4 files changed, 150 insertions(+), 44 deletions(-) diff --git a/bash_aliases b/bash_aliases index 8d75f2b..bdf2229 100644 --- a/bash_aliases +++ b/bash_aliases @@ -15,14 +15,21 @@ alias grep='grep --color=auto -i' # color case-insensitive alias la='ls -A' alias ll='ls -l -h' alias lla='ll -A' -alias ls='ls --color=auto' +alias ls='ls --color=auto --group-directories-first --classify' #alias less='less -Ri' # make less's searches case insensitive and # colorized LESS=Ri # TODO move to an appropiate place +alias gcc='gcc -g -std=c99 -lm' +alias ed='ed -p "* "' +alias diff='diff -s' # Other program's options # ====================================================================== -alias feh='feh -g 640x480 -S filename' +#alias feh='feh -g 640x480 -S filename' # opens files sorted by filename +alias feh='feh -g 640x480 --auto-zoom --scale-down --on-last-slide hold' +alias feht='feh -Tthumb_s' +alias fehfx='feh -Tfs --slideshow-delay' +alias fehfrx='feh -Tfs --recursive --slideshow-delay' alias units='units --verbose' @@ -36,10 +43,9 @@ alias cp='cp -i' # same # Quick tools # ====================================================================== alias pdfreduce='gs -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook' -alias weather="curl wttr.in/Austin?mF" -alias weatherhelp="curl wttr.in/:help" alias youtube-dl_info='youtube-dl --get-filename --get-format --get-duration --get-description' alias youtube-dl_fast='youtube-dl --format "best[height<=720]" -o '\''%(title)s.%(ext)s'\' +alias mpv_webcam='mpv av://v4l2:/dev/video0' # retrived from the Archwiki # Cosmetic diff --git a/bashrc b/bashrc index 972964e..d6b7d97 100644 --- a/bashrc +++ b/bashrc @@ -120,9 +120,17 @@ if [ -d "$HOME/.local/bin" ] ; then PATH="$HOME/.local/bin:$PATH" fi +# Bash completition for pandoc +eval "$(pandoc --bash-completion)" + # Greeting or salute -cowsay -f flaming-sheep "oh no" +# TODO: randomly select one of the following greeting commands +#cowsay -f flaming-sheep "oh no" # original +#cowsay $(fortune -e 30% debian-hints 20% linux 20% science \ +cowsay $(fortune 30% debian-hints 20% linux 20% science \ + 20% off/linux 10% off/black-humor) +#fortune ascii-art # Some environmental variables. -export TLDR_CONFIG_DIR="$HOME/.config" +export TLDR_CONFIG_DIR="$XDG_CONFIG_HOME" export GPG=TTY=$(tty) diff --git a/fun.vim b/fun.vim index ce77e92..909c328 100644 --- a/fun.vim +++ b/fun.vim @@ -1,23 +1,67 @@ " Echoes longest line number and lenght. function! LongestLineLength ( ) - let maxlength = 0 - let linenumber = 1 - while linenumber <= line("$") - exe ":".linenumber - let linelength = virtcol("$") - if maxlength < linelength - let maxlength = linelength - let maxlinenumber = linenumber - endif - let linenumber = linenumber+1 - endwhile - -" exe ':0' -" exe 'normal O' -" exe 'normal 0C'.maxlength - exe "normal" . maxlinenumber . "G" - exe ":echo \"" . maxlinenumber . ": " . maxlength . "\"" + let maxlength = 0 + let linenumber= 1 + while linenumber <= line("$") + exe ":".linenumber + let linelength = virtcol("$") + if maxlength < linelength + let maxlength = linelength + let maxlinenumber = linenumber + endif + let linenumber = linenumber+1 + endwhile + +"exe ':0' +"exe 'normal O' +"exe 'normal 0C'.maxlength + exe "normal" . maxlinenumber . "G" + exe ":echo \"" . maxlinenumber . ": " . maxlength . "\"" endfunction command LongestLineLength call LongestLineLength() + + +" Save markdown document and export to pdf using pandoc. +" +" It would be nicer if a default document would be used but I coulnd't made it +" to work even after reading that manual section like 2 times. Also, there are +" variables that are lists of other variables that I don't know how to make them +" work (e.g. geometry=[top=1in, bottom=1in, heightrounded]) + +function! Md2Pdf ( ) + exe ":w" + exe ":! pandoc -o " . expand("%:r") . ".pdf -t latex -N --variable classoption=twosides --variable papersize=a4 --variable margin-left=1in --variable margin-right=1in --variable margin-top=1in --variable margin-bottom=1in --variable links-as-notes --variable colorlinks --variable pagestyle=plain --variable documentclass=article " . expand("%") + echo "pdf saved as " . expand("%:p:r") . ".pdf" +endfunction + +function! Md2Pdfms ( ) + exe ":w" + exe ":! pandoc -o " . expand("%:r") . ".pdf" . " -t ms -N " . expand("%") + echo "pdf saved as " . expand("%:p:r") . ".pdf" +endfunction + +command Md2Pdf call Md2Pdf() +command Md2Pdfms call Md2Pdfms() + + +" Save markdown document and export to html using pandoc + +function! Md2Html ( ) + exe ":w" + exe ":! pandoc -o " . expand("%:r") . ".html" . " -s -N " . expand("%") + echo "html saved as " . expand("%:p:r") . ".html" +endfunction + +command Md2Html call Md2Html() + +" Compiles and Runs a C++ project + +function! CompRunProj ( ) + exe ":w" + exe ":! g++ -o " . expand("%:r") . " *.cpp" + exe ":! ./" . expand("%:r") +endfunction + +command CompRunProj call CompRunProj() diff --git a/vimrc b/vimrc index 3024e0d..80b2acd 100644 --- a/vimrc +++ b/vimrc @@ -1,5 +1,6 @@ " mitsuo's vimrc " Created c. 2019-11-11 +" Last update (after destroying it accidentally) 2020-09-02 " " ┌─┬─┬─┬─┬─┬─┐ " │m│i│t│s│u│o│✓x が @@ -11,23 +12,47 @@ " TODO: sort sections +" Variables +" ---------------------------------------------------------------------- +set undodir=$XDG_DATA_HOME/vim/undo +set directory=$XDG_DATA_HOME/vim/swap +set backupdir=$XDG_DATA_HOME/vim/backup +set viminfo+='1000,n$XDG_DATA_HOME/vim/viminfo +set runtimepath=$XDG_CONFIG_HOME/vim,$VIMRUNTIME,$XDG_CONFIG_HOME/vim/after +" TODO fix this +"let vcpath="~/.vim/vimfun/" " vim configuration path + + " Useful " ---------------------------------------------------------------------- set nocompatible " Auto-recognize files and apply pluggins " filetype plugin indent on syntax on + +" Search files set wildmenu -set showcmd +set path+=** " Search down into subfolders + +set showcmd " show partial command on last line (below status bar) set scrolloff=5 " show a few lines of context " not default in some systems -set backspace=indent,eol,start +set backspace=indent,eol,start " Allow and in insert mode " number gutter set nonumber set norelativenumber +" Tag Jumping +" Instructions: create tag index (e.g. $ ctags -R .) +" place cursor on tag +" ^] to jump to definition +" g^] if more than 1 definition +" ^T to return (or ^O) +" TODO: create tags automatically (:!ctags -R . after :w if ft=c) + + " Search " ---------------------------------------------------------------------- @@ -92,10 +117,9 @@ set encoding=utf-8 " Mappings " ---------------------------------------------------------------------- +map :source ~/.config/vim/vimrc map :tabp map :tabn -" TODO: Funcking unmap the F1 key -"unmap " Yanking and pasting @@ -119,25 +143,36 @@ set printoptions=paper:A4,duplex:long " set printoptions+=number:y " TODO: Figure out how to print multibyte encodings. Enabling this settings " produces errors. -" set printencoding=utf-8 +set encoding=utf-8 +set fileencoding=utf-8 " set printmbcharset=JIS_X_1990 " This allows Japanese characters to be printed " set printmbfont=r:Noto-Sans-CJK-JP -" Variables +" Functions " ---------------------------------------------------------------------- -set undodir=$XDG_DATA_HOME/vim/undo -set directory=$XDG_DATA_HOME/vim/swap -set backupdir=$XDG_DATA_HOME/vim/backup -set viminfo+='1000,n$XDG_DATA_HOME/vim/viminfo -set runtimepath=$XDG_CONFIG_HOME/vim,$VIMRUNTIME,$XDG_CONFIG_HOME/vim/after -" TODO fix this -"let vcpath="~/.vim/vimfun/" " vim configuration path +" TODO: maybe replace with $runtimepath +source ~/.config/vim/fun.vim -" Functions +" Snippets " ---------------------------------------------------------------------- -source ~/.config/vim/fun.vim +nnoremap ,ch :-1r ~/.config/vim/snippets/cheader.c + + +" File Browsing +" ---------------------------------------------------------------------- +" Use netrw out of the box file browser plugin. +" :e . open file browser on current directory +" V or t open file on vsplit or new tab. +" :bd or :Rex to return +" More mappings on |netrw-browse-maps| +"let g:netrw_banner=0 " disable banner +"let g:netrw_browse_split=4 " open in prior window +let g:netrw_altv=1 " open splits to the right +"let g:netrw_list_hide=netrw_gitignore#Hide() +"let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+' " wtf? (?) +" Learned from Max Cantor talk https://youtu.be/XA2WjJbmmoM " Additions @@ -156,19 +191,32 @@ inoremap diWi=" " iVim " ---------------------------------------------------------------------- -" TODO: map :h _argument_ to :h _argument_ L_ This makes help window -" to almost fill the super small screen. +" TODO: map :h _argument_ to :h _argument_ L| makes help window +" almost fill the super small screen. " Plugins " ---------------------------------------------------------------------- -" Install vim-plug -if empty(glob('~/.vim/autoload/plug.vim')) - silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs +" Automatic vim-plug install +if empty(glob('$XDG_CONFIG_HOME/vim/autoload/plug.vim')) + silent !curl -fLo $XDG_CONFIG_HOME/vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim autocmd VimEnter * PlugInstall --sync | source $MYVIMRC endif + call plug#begin() Plug 'ARM9/arm-syntax-vim' -au BufNewFile,BufRead *.s,*.S set filetype=arm " arm = armv6/7 +autocmd BufNewFile,BufRead *.s,*.S set filetype=arm " arm = armv6/7 + call plug#end() + +" Other plugins +source ~/.config/vim/plugins/* + + +" Ducktape +" ---------------------------------------------------------------------- +" Not even the ducktape worked for this one on C files TODO +set formatoptions-=o " Automatically insert the current comment leader +" TODO: fix this shit getting reset in a markdown text +set formatoptions+=r " auto insert comment leader after -- cgit v1.2.3