Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Konfekt / better_gx.vim
Created September 18, 2024 06:11
Open URLs such as markdown links in browser
" Better gx to open URLs in Vim.
"
" Adapted from https://github.com/habamax/.vim/blob/d5087779fee4a7372c1dd2c407674997fdb1268d/autoload/os.vim
" to use in particular :Open command from https://gist.github.com/Konfekt/8e484af2955a0c7bfe82114df683ce0f
" See also https://gist.github.com/AndrewRadev/1ba9eba62df82d616fc8040338c4c4e1
func! s:BetterGx() abort
" URL regexes
let rx_base = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S'
let rx_bare = rx_base . '\+'
@Konfekt
Konfekt / filepicker.vim
Last active September 14, 2024 13:35
Open files selected in LF/Yazi/Ranger/NNN in (Neo)Vim with :FilePicker
" Use Ranger/LF/Yazi/NNN to select and open file(s) in (Neo)Vim.
"
" You need to either
"
" - copy the content of this file to your ~/.vimrc resp. ~/.config/nvim/init.vim,
" - or put it into ~/.vim/plugin respectively ~/.config/nvim/plugin,
" - or source this file directly:
"
" let s:fp = "/path/to/filepicker.vim"
" if filereadable(s:fp) | exec "source" s:fp | endif
@Konfekt
Konfekt / project-local-viminfo.vim
Last active September 14, 2024 06:57
Project-Local Viminfo
" If you work on more than one (git) project, say those of Vim and Linux, then
" you may wish to keep their file histories, bookmarks, command histories ... separate.
" This can be achieved with separate viminfo files, by adding this snippet to your vimrc and
" a .viminfo inside your repository that, if empty, will be initially replaced by
" your current one. Then at the start of a Vim session, the viminfo file of the
" current work dir is loaded.
" Add this snippet to your vimrc to enable a project/repo-local viminfo by `touch .viminfo/shada`.
" Add .viminfo/shade to .git/info/exclude (maybe best in the git template) to avoid cluttering git status.
@Konfekt
Konfekt / msys2-pacman-packages.sh
Created August 21, 2024 20:44
Install a batch of useful MinGW tools
#!/bin/sh
pacman -S \
--needed \
base-devel \
mingw-w64-ucrt-x86_64-toolchain \
cmake \
mingw-w64-ucrt-x86_64-cmake-gui \
\
ctags \
@Konfekt
Konfekt / fix.py
Created May 23, 2024 12:29
let ChatGPT suggest fixes to spewn errors
#!/usr/bin/env python3
"""
Adaption of https://github.com/tom-doerr/fix/blob/main/main.py
This script executes a program.
If the program throws an error, the script generates suggestions
for fixing the error.
"""
@Konfekt
Konfekt / swap-alt-win-tab.ahk
Created April 27, 2024 20:04
Swap Win+Tab and Alt+Tab on Windows with Autohotkey v2
; Swap Alt+Tab and Win+Tab
; From https://www.autohotkey.com/boards/viewtopic.php?style=19&p=548067&sid=dfc532a1b55a0d25862c8ee98674e0db#p548067
#HotIf WinActive("ahk_class XamlExplorerHostIslandWindow")
*!Tab::Send("{Alt Down}{Right}")
~*Alt Up::Send("{Enter}")
#HotIf
*!Tab::#Tab
; From https://www.autohotkey.com/docs/v2/Hotkeys.htm#AltTabWindow
@Konfekt
Konfekt / bkp.sh
Created April 27, 2024 10:59
backup a file or restore it if it ends in a bkp extension
#!/usr/bin/env bash
# for each file, either back it up or restore it, in case it ends in a bkp extension
for f in "$@"; do
p="${f%/}"
[ "$p" != "${p%.bkp}" ] &&
cp --archive --interactive --update --verbose "$p" "${p%.bkp}" ||
cp -aiuv "${p}" "$p.bkp"
done; }
@Konfekt
Konfekt / scoop-apps.ps1
Last active September 17, 2024 05:35
Install a batch of useful scoop apps
<#
.SYNOPSIS
Script to install Scoop apps
.DESCRIPTION
Script uses scoop
.NOTES
**NOTE** Will configure the Execution Policy for the "CurrentUser" to Unrestricted.
Original Author: Mike Pruett
Date: October 18th, 2018
@Konfekt
Konfekt / single-file-git-with-vim.md
Last active April 21, 2024 15:25
Easily version control a single file under vim

Git was not designed for single-file projects, or managing multiple text files independently within a directory. However, below shell script and accompanying Vim commands work around it by creating a unique bare repository for each file (using a Git command to set a different location for each file's .git directory).

Command-Line Instructions

Copy the following script into a folder in $PATH, say as ~/bin/git1 (or g1) and mark it executable:

#!/usr/bin/env bash
@Konfekt
Konfekt / chmod-safe-sane.sh
Last active April 20, 2024 13:31
change permissions to be sane or safe inside a $dir by chmod-sane/safe $dir
#!/bin/sh
# Change file permissions to be sane or safe inside a directory $dir by
# chmod-sane/safe $dir
# For example, ~/.gnupg better be safe whereas ~/.cache can be sane.
# Set permissions in a specified directory to a
# standard, reasonable setting where directories are executable and readable by
# all users (755), and files are readable and writable by the owner, and readable
# by others (644). Additionally, files with execute permissions set for any user