Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Konfekt / EvaluateAsComment.vim
Last active April 16, 2024 05:19
Add evaluation of selected code as comment
" From https://old.reddit.com/r/neovim/comments/1c3gf93/commentreplnvim_run_code_from_your_buffer_and/
"
" Add the following lines to `ftplugin/{python,sh,zsh,lua,perl, ...}.vim
" and call :EvaluateAsComment to add the evaluation of the selected lines as a comment:
"
" print(1+2)
"
" becomes
"
" # 3
@Konfekt
Konfekt / RunOrRaise.ahk
Last active April 9, 2024 12:26
Autohotkey v2 Script to Run or Raise application using Shortcut
; Run or Raise Application using Shortcut
; From https://gist.github.com/dewaka/c494543b4cd2a2dcd09cc5a6aa0f7517 adapted to ah2
RunOrRaise(exePath, winID:="") {
if (winID == "") {
exeName := SubStr(exePath, InStr(exePath, "\", , -1)+1)
winID := "ahk_exe " . exeName
}
If not WinExist(winID) {
UserProfile := EnvGet("USERPROFILE")
@Konfekt
Konfekt / mapping-with-count-to-list-repo-or-all-files-altered-in-count-last-commits.vim
Created April 9, 2024 12:25
A mapping that uses FZF to list all files in a Git repo and takes a count to restrict to those altered in last <count> commits
" A mapping that uses FZF to list all files in a Git repo and takes a count to restrict to
" those altered in last <count> commits.
nnoremap <silent><expr> g. v:count ? ':<c-u>' . v:count . 'GFilesAltered<cr>' : ':<c-u>GFiles<cr>'
command! -count=1 GFilesAltered call fzf#vim#files('', fzf#vim#with_preview( {
\ 'source': 'git log HEAD --max-count=<count> --diff-filter=MA --name-only --pretty=format: | ' . s:filter,
\ 'options': '--multi --prompt "Files altered in last <count> commits: "',
\ } ))
" If Fugitive is installed, there's a fallback, here's a possible fallback
@Konfekt
Konfekt / okular-markdown-preview-vim.md
Last active March 20, 2024 16:10
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!'
@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')
; 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 / aichat.vim
Last active March 2, 2024 05:49
Vim commands to pipe text to aichat and open a chat window
if executable('aichat')
command! -range -nargs=+ -complete=customlist,s:AIChatRoleCompletion AIRole <line1>,<line2>call s:AIRole(<q-args>)
function! s:AIRole(instruction) range
let instruction = trim(a:instruction)
let i = match(instruction . ' ', '\s')
let role = instruction[0:i-1]
let instruction = trim(instruction[i:-1])
let prompt = !empty(instruction) ? shellescape('Please consider: ' . instruction . '.') : ''
" term ++hidden ++open
exe a:firstline.','.a:lastline . 'term aichat --role ' . role . ' ' . prompt
@Konfekt
Konfekt / git-multihook.sh
Last active December 11, 2023 10:01
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 / git-diff.md
Last active December 11, 2023 09:52
git diff common binary files
@Konfekt
Konfekt / mailcap
Last active December 8, 2023 11:27
mutt mailcap file to display attachments in mutt mail client
# From http://wiki.free-unices.org/doku.php/config/mutt/new_mailcap
application/vnd.oasis.opendocument.text; mutt_bgrun okular %s; test=test -n "$DISPLAY"
application/vnd.oasis.opendocument.text; odt2txt %s | cat --squeeze-blank; copiousoutput
# application/vnd.oasis.opendocument.text; pandoc --from=odt --to=plain %s | cat --squeeze-blank ; copiousoutput
# application/vnd.oasis.opendocument.text; libreoffice --cat %s | cat --squeeze-blank ; copiousoutput
application/vnd.oasis.opendocument.spreadsheet; mutt_bgrun libreoffice --nologo %s; test=test -n "$DISPLAY"
application/vnd.oasis.opendocument.spreadsheet; odt2txt %s | cat --squeeze-blank; copiousoutput
# application/vnd.oasis.opendocument.spreadsheet; libreoffice --cat %s | cat --squeeze-blank ; copiousoutput