Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 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 / 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 / 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 / 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 / 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