Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Konfekt / single-file-git-with-vim.md
Last active February 2, 2025 14: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 / better_gx.md
Last active January 21, 2025 10:40
Open links and files in browser

This has been included in :help netrw-handler

; 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 / wacom2monitor.sh
Last active January 10, 2025 18:15
A shell script to map all Wacom devices to a given monitor, in particular to switch through all available monitors by repeatedly calling it with the parameter NEXT
#!/usr/bin/env bash
# exit on error or on use of undeclared variable or pipe error:
set -o errexit -o errtrace -o nounset -o pipefail
# optionally debug output by supplying TRACE=1
[[ "${TRACE:-0}" == "1" ]] && set -o xtrace
shopt -s inherit_errexit
PS4='+\t '
IFS=$'\n\t'
@Konfekt
Konfekt / aichat.vim
Last active December 31, 2024 05:51
Vim commands to pipe text to aichat and open a chat window
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]
let instruction = trim(instruction[i:-1])
else
@Konfekt
Konfekt / silent-launch-open.vim
Last active December 21, 2024 20:41
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 / 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 / filepicker.md
Last active November 3, 2024 05:52
Open files selected in LF/Yazi/Ranger/NNN in (Neo)Vim with :FilePicker
@Konfekt
Konfekt / mailcap
Last active November 2, 2024 05:33
mailcap file to display files in and outside of terminal for mutt, less, ranger / lf, ..
# Save as ~/.mailcap. Then use run-mailcap to:
#
# - open files by `run-mailcap --action=view <file>`, or
# - view them in the terminal by `run-mailcap --action=cat <file>`.
#
# Useful
#
# - in mutt by `set mailcap_file $HOME/.mailcap`
# - in Vim by adding to your vimrc
#
@Konfekt
Konfekt / okular-markdown-preview-vim.md
Last active October 29, 2024 22:30
A dead-simple markdown previewer in Vim thanks to KDE's document viewer Okular

KDE's document viewer Okular renders markdown as HTML (and reloads it automatically on changes.) Thus, simply open the markdown file currently edited in Vim in Okular to be all set!

To start an GUI application from Vim, without freezing, hit-<enter> prompts or scrambling screen lines, one can add a command such as

if has('unix')
 command! -complete=shellcmd -nargs=1 -bang Silent execute ':silent !' . (0 ? 'nohup ' .  . '/dev/null 2&gt;&amp;1 &amp;' : ) | execute ':redraw!'