Skip to content

Instantly share code, notes, and snippets.

View AndrewRadev's full-sized avatar

Andrew Radev AndrewRadev

View GitHub Profile
@AndrewRadev
AndrewRadev / matchfuzzy.vim
Last active August 4, 2023 21:16
A fuzzy-finder in 40 lines of portable Vimscript
" Pick a different highlighting group by adding this in your vimrc:
"
" highlight link fuzzyMatch <group>
"
" The "default" only makes the link if it's not already set.
"
highlight default link fuzzyMatch Search
" The components of the command definition:
"
@AndrewRadev
AndrewRadev / artify_fast.vim
Created March 4, 2021 13:34
Proof-of-concept of a faster "artify" plugin
let s:tbl = {
\ 'bold': {
\ '0': '𝟎', '1': '𝟏', '2': '𝟐', '3': '𝟑', '4': '𝟒',
\ '5': '𝟓', '6': '𝟔', '7': '𝟕', '8': '𝟖', '9': '𝟗',
\ 'A': '𝐀', 'B': '𝐁', 'C': '𝐂', 'D': '𝐃', 'E': '𝐄',
\ 'F': '𝐅', 'G': '𝐆', 'H': '𝐇', 'I': '𝐈', 'J': '𝐉',
\ 'K': '𝐊', 'L': '𝐋', 'M': '𝐌', 'N': '𝐍', 'O': '𝐎',
\ 'P': '𝐏', 'Q': '𝐐', 'R': '𝐑', 'S': '𝐒', 'T': '𝐓',
\ 'U': '𝐔', 'V': '𝐕', 'W': '𝐖', 'X': '𝐗', 'Y': '𝐘',
\ 'Z': '𝐙',
@AndrewRadev
AndrewRadev / private_methods.vim
Last active February 14, 2021 11:43
Ruby private method highlight
" ~/.vim/ftplugin/ruby/private_methods.vim
" Browse through https://github.com/AndrewRadev/Vimfiles to find any future updates.
" Define what color the private methods will have
hi rubyPrivateMethod cterm=underline gui=underline
function! s:MarkPrivateArea()
if empty(prop_type_get('private_method', {'bufnr': bufnr()}))
call prop_type_add('private_method', {
\ 'bufnr': bufnr(),
@AndrewRadev
AndrewRadev / textprop_demo_1.vim
Last active February 14, 2021 11:42
Ruby private method highlight (basic)
" ~/.vim/ftplugin/ruby/textprop_demo_1.vim
" Define what color the private methods will have
hi rubyPrivateMethod cterm=underline gui=underline
function! RubyMarkPrivateArea()
if empty(prop_type_get('private_method', {'bufnr': bufnr()}))
call prop_type_add('private_method', {
\ 'bufnr': bufnr(),
\ 'highlight': 'rubyPrivateMethod',
@AndrewRadev
AndrewRadev / vim_guide.md
Created April 24, 2020 12:51
An old Vim guide I wrote in Bulgarian. Originally published at https://github.com/fmi/ruby-course-guides/blob/master/vim.md#readme

Vim

TL;DR – VIM EMERGENCY!

  • За да излезете от Vim, без да запазвате файл, натиснете Esc, след това напишете :q! и натиснете Enter.
  • За да направите промяна, натиснете i и си редактирайте текста като в нормален редактор.
  • За да запазите направените промени, натиснете Esc и след това напишете :w и натиснете Enter. След това е окей да излезете от редактора с :q.

А ако се чудите къде да инвестирате следващите десет минути от живота си, непременно прочетете това ръководство до края.

@AndrewRadev
AndrewRadev / efactory.vim
Last active April 14, 2020 12:24
An `:Efactory` command for jumping to factory_bot definitions in rails projects
" Extracted from:
" https://github.com/AndrewRadev/Vimfiles/blob/0490041cf2d0e4f7a9b2e1361bb47971dd59d836/miniplugins/plugin/rails_extra.vim
"
" Installation:
"
" Copy file to ~/.vim/plugin/efactory.vim, or just paste the whole thing in
" your `.vimrc`. No guarantees it'll work well for you, seems to work for me.
" Will extract to a plugin at some point and it'll hopefully be more reliable.
"
" Usage:
@AndrewRadev
AndrewRadev / main.rs
Last active November 13, 2018 10:23
Divide successfully or default to zero
trait OrZero {
fn or_zero(self) -> Self;
}
impl OrZero for f64 {
fn or_zero(self) -> Self {
if self.is_normal() { self } else { 0.0 }
}
}
@AndrewRadev
AndrewRadev / keep-track.sh
Last active October 21, 2018 17:23
Keep track of a long-running process
# Given a long-running process in the terminal:
#
# - Ctrl+Z to suspend it
# - Run `keep-track`
# - Output resumes, when done will show a notification with the time it took for the process to run
#
# Can be customized with an `--icon` to `notify-send`,
# maybe a sound effect added in the `&&` list.
#
function keep-track() {
extern crate solution;
use solution::*;
use std::io::{self, Write};
fn main() {
let mut game = Game::new("aardvark", 10).unwrap();
let stdin = io::stdin();
println!("Let's play hangman!");
@AndrewRadev
AndrewRadev / jsx.vim
Last active May 30, 2017 07:15
gf for react
set includeexpr=<SID>Includeexpr()
augroup jsx_autocommands
autocmd!
" Override gf if rails sets it after
autocmd User Rails cmap <buffer><expr> <Plug><cfile> <SID>Includeexpr()
augroup END
function! s:Includeexpr()