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 / dump_highlights.vim
Last active August 2, 2023 08:18
Try to take the current colorscheme's highlights and put them in a file
" Adapted from https://vi.stackexchange.com/a/16111
"
command! -nargs=1 DumpHighlight call s:DumpHighlight(<q-args>)
function! s:DumpHighlight(filename) abort
let output = execute('hi', 'silent!')
let colors_name = fnamemodify(a:filename, ':r')
let highlights =<< trim eval EOF
hi clear
@AndrewRadev
AndrewRadev / put_at_end.vim
Last active July 30, 2023 13:43
Create a normal-mode Vim mapping to append characters to a line, respecting comments
" Place this file in autoload/put_at_end.vim.
"
" Create mappings in normal mode that call the function with the string to append:
"
" nnoremap <silent> z, :call put_at_end#Mapping(',')<cr>
" nnoremap <silent> z; :call put_at_end#Mapping(';')<cr>
" nnoremap <silent> z) :call put_at_end#Mapping('),')<cr>
"
" If you have repeat.vim installed, you can repeat the append with a .
"
@AndrewRadev
AndrewRadev / duplicate.vim
Last active August 30, 2022 08:26
Duplicate lines and blocks of code in Vim
" Pressing zj and zk duplicate a single line below and above the cursor,
" respectively. This is pretty common functionality and simple to implement.
"
" Pressing zJ and zK duplicates a "block" of code, which is defined by indent.
" In the languages from the s:indent_based_languages list, a "hanging" indent
" is taken. Example:
"
" def one(self):
" pass
"
@AndrewRadev
AndrewRadev / cheerlights.sh
Created December 22, 2011 13:55
Simple shell script that checks the current cheerlights color
#! /bin/sh
current_color=''
last_color=''
while :;
do
current_color=`curl -s 'http://api.thingspeak.com/channels/1417/field/1/last.txt'`
if [ "$current_color" != "$last_color" ]
@AndrewRadev
AndrewRadev / ember-projections.json
Last active May 6, 2021 17:47
A `.projections.json` file that can be used with vim-projectionist for navigating ember.js projects
{
"app/initializers/*.js": {
"type": "initializer"
},
"app/models/*.js": {
"type": "model",
"alternate": "app/adapters/{}.js",
},
"app/adapters/*.js": {
"type": "adapter",
@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 / eruby.vim
Created July 1, 2012 16:10
My ftplugin/eruby.vim file
" This file is supposed to be saved as "~/.vim/ftplugin/eruby.vim". If desired, parts of it can be
" picked and saved into separate files in the same directory as long as they start with "eruby_",
" for example "~/.vim/ftplugin/eruby_surroundings.vim".
" Surround mappings. The character defines the mapping. Most of these are meant for use in visual
" mode to add a wrapping, although they can probably be used otherwise as well.
"
" These ones let you wrap a piece of text on a line with erb <% %> markers. The last one is
" particularly useful for adding translations in the place of hardcoded strings.
"