Skip to content

Instantly share code, notes, and snippets.

@bfrg
bfrg / virttext.md
Last active November 27, 2022 00:45
Highlight quickfix (and/or location-list) errors as virtual text in the buffer

Highlight quickfix errors as virtual text

This script will display the errors in the current quickfix and/or location list as virtual text in the buffer.

Virtual text can be aligned after, right, below or above the line containing the error.

NOTE: For a full plugin, see vim-qf-diagnostics.

Commands

@bfrg
bfrg / autopair.vim
Last active August 8, 2022 08:28
Automatically close, skip and remove matching pairs in insert-mode
vim9script
# Auto-close parentheses
inoremap ( ()<c-g>U<left>
inoremap [ []<c-g>U<left>
inoremap { {}<c-g>U<left>
inoremap < <><c-g>U<left>
inoremap (<cr> (<cr>)<esc>O
inoremap {<cr> {<cr>}<esc>O
inoremap [<cr> [<cr>]<esc>O
@bfrg
bfrg / ls-chars.sh
Created June 5, 2022 13:02
Print the characters a font provides
#!/bin/bash
#
# Print all characters a font provides
#
# Example:
# $ ls-chars devicon
#
# Note:
# \U in printf is not POSIX standard, therefore we need bash
#
@bfrg
bfrg / onedark.vim
Last active March 11, 2021 00:23
onedark colorscheme for Vim
" ==============================================================================
" File: colors/onedark.vim
" Description: Colors based on onedark.vim by joshdick
" Maintainer: bfrg <https://github.com/bfrg>
" Last Change: Feb 13, 2021
" License: Same as Vim itself (see :h license)
" ==============================================================================
hi clear
@bfrg
bfrg / gitblame.vim
Last active August 10, 2020 20:55
Vanilla git-blame
" Vanilla git-blame
"
" git-blame current line:
" :GB
"
" git-blame selected lines:
" :'<,'>GB
"
" git-blame entire buffer:
" :%GB
@bfrg
bfrg / tabcomplete.vim
Last active August 1, 2020 10:15
Insert-mode completion using <Tab> as prefix instead of <C-X><C- >
" Shorthand for <c-x><c- > completion
"
" <tab>f triggers filename completion
" <tab>l triggers line completion
" <tab>] triggers tag completion
" ...
"
" Original idea by 'kvik' in #vim long time ago
for i in split(']defiklnopuvys', '\zs')
@bfrg
bfrg / hscroll.vim
Created July 15, 2020 10:06
Scroll the current window horizontally with h, l, H, L instead of zh, zl, zH, zL with the help of a popup window
" Simple script that adds a new horizontal scrolling mode using a popup
" window.
"
" Pressing z/ opens a small popup window in the botton right corner of the
" screen. While the popup window is open, the current window can be scrolled
" with h (left one char), l (right one char), H (one half screen left), L (one
" half screen right). Close the window with q or ENTER.
scriptencoding utf-8
@bfrg
bfrg / includeexpr.vim
Last active May 3, 2022 11:19
ftplugin for vim9script: add proper 'include', 'includeexpr', 'define', and 'path' values for vimscript files
vim9script
# File: autoload/ft/vim/includeexpr.vim
export def Main(fname: string): string
if fname =~# '^import\s\+autoload\s\+\(["'']\)\f\+\1$'
return 'autoload/' .. matchstr(fname, '^import\s\+autoload\s\+\([''"]\)\zs\f\+\ze\1$')
elseif fname =~# '^import\s\+\(["'']\)\f\+\1'
return matchstr(fname, '^import\s\+\([''"]\)\zs\f\+\ze\1$')
endif
@bfrg
bfrg / quickfix-toggle.vim
Last active May 6, 2020 14:09
Toggle the quickfix and location-list windows without scrolling the windows
" Open/close/toggle the quickfix and location-list windows without changing the
" window layout
" ------------------------------------------------------------------------------
" File: autoload/qf/window.vim
" ------------------------------------------------------------------------------
" Save and restore view of current window
function! s:winview(mode) abort
if a:mode == 0
@bfrg
bfrg / vimhelp.vim
Last active April 21, 2020 02:13
More intelligent :help that automatically splits vertically when it makes more sense
" in file ~/.vim/autoload/vim.vim
function! vim#help(arg)
let cmd = winwidth(0) * 2 < winheight(0) * 5 ? '' : 'vertical'
" Vim escapes special characters, therefore we need to remove backslash,
" otherwise it will jump to the wrong help tag, for example, :h | and :h \|
" Make sure characters inside [] are in correct order, see E944
let arg = substitute(a:arg, '\\\ze[ !#$%''*+-<[`{|]', '', 'g')
try