Skip to content

Instantly share code, notes, and snippets.

@bfrg
bfrg / packdir.vim
Last active February 20, 2020 00:28
Quickly open the root directory of a plugin under ~/.vim/pack using the default file explorer
" ==============================================================================
" Quickly open the root directory of a plugin under ~/.vim/pack using your
" default file explorer (dirvish, netrw, etc.)
"
" Commands:
" Open root directory of plugin <plug> ...
" :PackE {plug} ...in current window
" :PackS {plug} ...in new split
" :PackV {plug} ...in new vertical split
" :PackT {plug} ...in new tab page
@bfrg
bfrg / dotfiles.vim
Last active July 21, 2019 19:09
Commands to quickly edit my dotfiles (supports wildmenu tab-completion and accepts partial matches)
" ==============================================================================
" Quickly edit my dotfiles
"
" Commands:
" Edit the dotfile 'foo' ...
" :DotE foo ... in current window
" :DotS foo ... in new split window
" :DotV foo ... in new vertical split
" :DotT foo ... in new tab page
"
@bfrg
bfrg / verbose2qf.vim
Last active April 1, 2023 07:46
Redirect the output of ":verbose {cmd}" to a quickfix list
" ==============================================================================
" Redirect the output of ':verbose {cmd}' to a quickfix list
"
" Commands:
" :Verbose {cmd}
" Add items to new quickfix list
"
" :VerboseAdd {cmd}
" Append items to current quickfix list
"
@bfrg
bfrg / qfhistory.vim
Last active June 6, 2022 13:23
Print the quickfix (or location-list) history and switch to selected list
vim9script
# Print the quickfix (or location-list) history and switch to the selected list
# Alternative: https://github.com/bfrg/vim-qf-history
def Errorlists(loclist: bool)
const Xgetlist = loclist ? function('getloclist', [0]) : function('getqflist')
const nr: number = Xgetlist({nr: '$'}).nr
if !nr
echomsg 'No entries'
@bfrg
bfrg / msgpopup.vim
Last active April 13, 2020 15:56
Like :messages but instead display the output in a popup window
" ==============================================================================
" Display the output of :messages in a popup window
"
" Commands:
" :Messages
"
" Popup Mappings:
" j/k - scroll down/up one line
" d/u - scroll down/up one half page
" f/b - scroll down/up one full page
@bfrg
bfrg / hipopup.vim
Created April 13, 2020 16:24
Display the output of :highlight in a popup window
" ==============================================================================
" Display the output of :highlight in a popup window
"
" Command:
"
" :Highlight [{args}...]
"
" {args} is an optional list of highlight groups (partial names are supported)
"
" Examples:
@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
@bfrg
bfrg / quickfix-toggle.vim
Last active May 29, 2024 18:07
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 / 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 / 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