Skip to content

Instantly share code, notes, and snippets.

View AndrewRadev's full-sized avatar

Andrew Radev AndrewRadev

View GitHub Profile
@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 / LICENSE
Last active March 20, 2024 14:25
Execute a vim motion on the "next" text object
MIT License
Copyright (c) 2017 Andrew Radev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@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
@AndrewRadev
AndrewRadev / quickmacro.vim
Last active January 24, 2024 17:55
Create a macro with a single keybinding in a default register, apply by dot-repeating
" Place file in autoload/quickmacro.vim
"
" Create mapping in vimrc to start and stop the macro with e.g. M:
"
" nnoremap M :call quickmacro#Record()<cr>
"
" Apply macro by @m, or if you have repeat.vim, just press .
let s:recording = v:false
@AndrewRadev
AndrewRadev / substitute_code.vim
Last active January 9, 2024 09:54
Substitute while skipping strings
" Install by saving as `~/.vim/plugin/substitute_code.vim`
" Use like the regular `:s` command:
"
" %Scode/foo/bar/g
"
" It ignores comments, but not strings. Tweak implementation as desired.
command! -nargs=1 -range Scode call s:Scode(<q-args>, <line1>, <line2>)
" Input should be something like /<pattern>/<replacement>/<flags>
@AndrewRadev
AndrewRadev / timestamp.vim
Last active October 19, 2023 11:24
Timestamp formatting
" Place under ~/.vim/plugin/
"
" Calling :Timestamp will try to convert the word under the cursor. Selecting
" an area in visual mode will pass it to `date` and replace the entire area.
"
command! -range=0 Timestamp call s:Timestamp(<count>)
function! s:Timestamp(count) abort
let is_visual = a:count > 0