Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Konfekt / set.vim
Last active April 28, 2024 05:50
Use :Set! (instead of :set) to make setting persist in a modeline
function! Set(args, isPersistent) abort
" remove whitespaces surrounding =
let cmd = 'set ' . substitute(a:args, '\s*=\s*', '=', 'g')
execute cmd
if !a:isPersistent | return | endif
" append modeline
let commentstring = empty(&l:commentstring) ?
\ (empty(&g:commentstring) ? '# %s' : &g:commentstring) : &l:commentstring
@Konfekt
Konfekt / silent-launch-open.vim
Last active October 7, 2025 20:03
Open TUI, GUI or file/URL cleanly in Neovim / Vim
" Use :Sil(ent) cmd to run a command cmd inside Vim with terminal output.
" For example, :Silent lazygit
" To surpress its output use :Launch; useful for GUI applications.
" For example, launch Firefox by :Launch firefox, or
" look up a keyword by :set keywordprg=:Launch\ zeal
" To open a file or URL, use :Open file/URL
" Useful, say, to view a compiled HTML of a markdown file, by :Open %:r.html
" or open an URL such as :set keywordprg=:Open\ https://devdocs.io/#q=
@Konfekt
Konfekt / make_completion.vim
Last active March 19, 2024 07:20
:Make target completion in Vim
" From https://github.com/mg979/tasks.vim/pull/15/files
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Command-line completion for ":Make"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
command! -bang -nargs=* -complete=customlist,MakeComplete Make silent make<bang> <args> | silent redraw!
command! -bang -nargs=* -complete=customlist,MakeComplete LMake silent lmake<bang> <args> | silent redraw!
if executable('awk')
@Konfekt
Konfekt / chatgpt-write-msg.py
Last active May 4, 2024 00:02
let ChatGPT write a sensible commit message using an adaptable Python script
#!/usr/bin/env python3
# Adaption of https://github.com/tom-doerr/chatgpt_commit_message_hook/main/prepare-commit-msg
#
# Mark this file as executable and add it into the global hooks folder
# whose path is given by the core.hooksPath configuration variable
# skip during rebase
import sys
if len(sys.argv) > 2:
@Konfekt
Konfekt / aichat.vim
Last active March 13, 2025 14:36
Vim commands to pipe text to aichat and open a chat window; use AIChatAppend/Replace/Session to append / replace text or open a terminal session; pass a role by appending s slash, say `AIChatReplace /coder`. Consider abbreviating commands with https://github.com/Konfekt/vim-alias
if !executable('aichat') | finish | endif
function! s:ProcessInstruction(instruction) abort
let instruction = trim(a:instruction)
if instruction[0] ==# '/'
let i = match(instruction..' ', '\s')
if i > 1
" Extract the role and the remaining instruction
let role = instruction[1:i-1]
@Konfekt
Konfekt / git-multihook.sh
Last active December 1, 2025 16:37
use global git hooks as fallback to local hooks
#!/usr/bin/env bash
#
# Adaption of https://github.com/majutsushi/etc/commit/e62904088c698e064c17522d54dff91b629ee253#diff-53b7e445a85984949f551c277d4cc4ee9682287cb234e075e6d352be887e7494
# with https://github.com/pivotal-cf/git-hooks-core/blob/master/.base-hook
#
# This script is meant to be put into a directory pointed to by core.hooksPath
# in Git 2.9.
# Then for each hook you want to support, create a symlink "hookname -> multihook"
# and optionally a directory "hookname.d" where you can put all scripts for
# that hook
@Konfekt
Konfekt / .xbindkeys.sh
Last active May 16, 2023 11:44
xbindkeys bindings to copy recognized (OCRed) text of rectangular selection or current window to clipboard (similar to Text Extractor of Powertoys under Microsoft Windows)
# Uses ksnip to select a rectangular region. Other options, instead of
#
# ksnip --rectarea --saveto "$file"
#
# are
#
# - spectacle --background --region --output "$file"
# - xfce4-screenshooter --region --mouse --save "$file"
# - maim --select --hidecursor --quiet "$file"
; Original author: Joe Winograd 21-Aug-2021
; Converted to AHK v2 by Enno 24-Apr-2023
Version:="6"
#SingleInstance Force ; replace old instance immediately
InitializeVars() ; initialize all variables
ConfigureInitialTray() ; configure initial system tray (notification area)
Return
InitializeVars()
@Konfekt
Konfekt / ulister.ini
Created April 17, 2023 05:35
Universal Lister Total Commander plugin setup file to exclude common text files to be rather shown by a text viewer such as Cuda Lister
[ulister]
noloadtypes=1999,1118,1119,1170,4000,4001,4002,4003,4004,4005,4006,4007,4008,4009,4010,4011,4012,4013,4014,4015,4016,4017,4018,4021,4022,4023,4024,4025,4026,4027,4028,4029,4030,4031,4032,4033,4034,4035,4036,4037,4058,4059,4060,4061,4062,4063,4064,4065,4066,4067,4068,4069,4070,4071,4072,4073,4074,4075,4076,4077,4078,4079,4080,4082,4083,4084,4085,4086,4087,4088,4089,4090,4091,4092,4093
nopreviewtypes=1999,1118,1119,1170,4000,4001,4002,4003,4004,4005,4006,4007,4008,4009,4010,4011,4012,4013,4014,4015,4016,4017,4018,4021,4022,4023,4024,4025,4026,4027,4028,4029,4030,4031,4032,4033,4034,4035,4036,4037,4058,4059,4060,4061,4062,4063,4064,4065,4066,4067,4068,4069,4070,4071,4072,4073,4074,4075,4076,4077,4078,4079,4080,4082,4083,4084,4085,4086,4087,4088,4089,4090,4091,4092,4093
@Konfekt
Konfekt / Everything.ini
Last active September 14, 2024 07:58
Everything configuration lines to exclude human unreadable, cache and temp files
[Everything]
exclude_folders="*\\temp","*\\tmp","*\\.cache","*\\*cache","*\\Trash","Trash-0","*\\.git","*\\.hg","C:\\Windows\\WinSxS","C:\\Windows.old","C:\\System Volume Information","C:\\$WinREAgent","C:\\Recovery","C:\\Config.Msi","C:\\Intel","C:\\PerfLogs","C:\\Users\\Default","C:\\Users\\Public","*\\scoop\\cache","*\\scoop\\buckets","*mozilla\\firefox","*\\syncthing\\index*"
exclude_files=~$*;*~;*.swap;*.temp;*.tmp;tags;thumbs.db;desktop.ini;*.pyc;*.pyo;*.out;*.toc;*.fls;*.fmt;*.fdb_latexmk;*.synctex;*.synctex.gz;*.synctex.gz(buzy);*.pdfsync;confdefs.h;*.elc;*.qmlc;config.status;.histfile.*;*.rej;*.jsc;lzo;*.blg;confstat;*.toc;moc_*.cpp;*.orig;*.po;litmain.sh;libtool;ui_*.h;*.lot;CTestTestfile.cmake;cmake_install.cmake;*.nvram;*.cb2;*.loT;nbproject;*.map;__pycache__;*.part;*.db;*.la;*.log;*.fq;.pch;*.fna;*.gmo;*.gbff;*.lo;*.qrc;*.pc;*.moc;*.init;conftest;qrc_*.cpp;*.fastq;*.aux;CMakeCache.txt;*.faa;*.fot;.yarn-cache;*.m4;*.a;*.vm*;autom4te;*.gb;*.omf;*.rcore;*.csproj;Makefile.am;*.lof;*.o;*.brf;*.fasta;*