Skip to content

Instantly share code, notes, and snippets.

View AndrewRadev's full-sized avatar

Andrew Radev AndrewRadev

View GitHub Profile
@AndrewRadev
AndrewRadev / markdown_open_link.vim
Last active September 18, 2024 08:53
Open a markdown link under the cursor (proof-of-concept)
@AndrewRadev
AndrewRadev / pophelp.vim
Last active September 18, 2024 09:09
Open Vim help in a resizable, movable popup window
" Save as ~/.vim/plugin/pophelp.vim
let s:popup = 0
command! -range=0 -nargs=* -complete=help
\ Pophelp call s:Open(<q-args>, <count>)
command! Popclose call s:Close()
function! s:Open(topic, count) abort
if a:topic == ''
@AndrewRadev
AndrewRadev / netrw_icons.vim
Last active September 14, 2024 02:38
Render icons in netrw
" Save as ~/.vim/ftplugin/netrw_icons.vim
if exists('b:netrw_icons_loaded')
finish
endif
let b:netrw_icons_loaded = 1
autocmd TextChanged <buffer> call s:NetrwAddIcons()
if empty(prop_type_get('netrw_file_icon', {'bufnr': bufnr('%')}))
@AndrewRadev
AndrewRadev / smart_scrolloff.vim
Last active September 10, 2024 08:36
Set 'scrolloff' to a fraction based on terminal size
" Reimplementation of https://github.com/tonymajestro/smart-scrolloff.nvim
" Place in `~/.vim/plugin/`
"
" Note that the value is based on `&lines`, which is the global number of
" lines available to Vim. If you'd like to scale scrolloff based on window
" size, you could use `line('w$') - line('w0')`. In that case, you'd update
" `&l:scrolloff`, the window-local option.
"
" See `:help 'scrolloff'`, `:help 'lines'`, and `:help getpos()` for more
" details.
@AndrewRadev
AndrewRadev / startuptime.txt
Last active April 29, 2024 14:29
Vim startuptime dump
times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
000.013 000.013: --- VIM STARTING ---
000.147 000.134: Allocated generic buffers
000.259 000.112: locale set
000.270 000.011: GUI prepared
000.276 000.006: clipboard setup
000.280 000.004: window checked
@AndrewRadev
AndrewRadev / parse_ignore.vim
Last active April 12, 2024 16:39
Add "ignored" status to statusline
" As an example, put it in the statusline (you should not do this here, just put the %{} in your config):
let &statusline = substitute(&statusline, '%f', '%f%{get(b:,"ignore_status","")}', '')
"
" get(b:, "ignore_status", "") -> Get the key "ignore_status" from the
" dictionary b: (all buffer-local variables), defaulting to ""
"
augroup IgnoreStatus
autocmd!
@AndrewRadev
AndrewRadev / blame_colors_poc.vim
Last active April 3, 2024 09:35
Show colors in the sign column based on age of line
" Proof-of-concept, probably won't work for you, sorry
" Terminal colors, all grays, lighter to darker
let s:colors = range(232, 255)
augroup FugitiveColors
autocmd!
autocmd BufRead * call ShowBlameColors()
augroup END
@AndrewRadev
AndrewRadev / matchparen_text.vim
Created March 4, 2024 09:53
Show the opening text of a closing bracket
" Original idea: https://github.com/briangwaltney/paren-hint.nvim
"
" Requires the built-in matchparen plugin to be activated
if exists("g:loaded_matchparen_text") || &cp
finish
endif
let g:loaded_matchparen_text = 1
if empty(prop_type_get('matchparen_text'))
@AndrewRadev
AndrewRadev / textobj_url.vim
Created February 9, 2024 20:48
URL text object
onoremap <silent> iu :<c-u>call <SID>UrlTextObject()<cr>
xnoremap <silent> iu :<c-u>call <SID>UrlTextObject()<cr>
onoremap <silent> au :<c-u>call <SID>UrlTextObject()<cr>
xnoremap <silent> au :<c-u>call <SID>UrlTextObject()<cr>
function! s:UrlTextObject()
let saved_view = winsaveview()
let saved_end_pos = getpos("'b")
defer setpos("'e", saved_end_pos)
@AndrewRadev
AndrewRadev / range_highlight.vim
Created February 8, 2024 11:24
Highlight ranges as you type them, proof-of-concept
" Save in ~/.vim/plugin/range_highlight.vim
augroup range_highlight
autocmd!
autocmd CmdlineChanged : call s:RangeHighlight()
autocmd CmdlineLeave : call s:RangeClear()
augroup END
let s:match_id = 0