Skip to content

Instantly share code, notes, and snippets.

View AndrewRadev's full-sized avatar

Andrew Radev AndrewRadev

View GitHub Profile
@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.
"
@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 / bookmarks.vim
Created November 16, 2011 20:02
Simple bookmark management in Vim
set viminfo+=!
if !exists('g:BOOKMARKS')
let g:BOOKMARKS = {}
endif
" Add the current [filename, cursor position] in g:BOOKMARKS under the given
" name
command! -nargs=1 Bookmark call s:Bookmark(<f-args>)
function! s:Bookmark(name)
@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 / qf.vim
Created December 2, 2011 20:14
Delete lines from the quickfix window (with undo)
" Place in ftplugin/qf.vim
xnoremap <buffer> d :DeleteLines<cr>
nnoremap <buffer> dd :DeleteLines<cr>
nnoremap <buffer> u :UndoDelete<cr>
if !exists(':DeleteLines')
let b:deletion_stack = []
" Delete by a pattern (with undo placing them all on top):
@AndrewRadev
AndrewRadev / Makefile
Created January 8, 2012 15:31
Stupidly simple Makefile for working with an Arduino
ARDUINO_PATH='/usr/share/arduino/hardware/arduino/cores/arduino'
VARIANTS_PATH='/usr/share/arduino/hardware/arduino/variants/standard'
MCU='atmega328p'
F_CPU=16000000
PORT='/dev/ttyACM0'
UPLOAD_RATE=115200
CORE_SOURCES=\
$(ARDUINO_PATH)/wiring.c\
$(ARDUINO_PATH)/wiring_analog.c\
@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 / README.markdown
Created August 11, 2011 16:45 — forked from skanev/README.markdown
Convert a <select> with <optgroups> to two <select>s that are interconnected

If you have a select with option groups:

<select data-nested-select="Select country">
  <option>Select city</option>
  <optgroup label="Bulgaria">
    <option value="sofia">Sofia</option>
    <option value="plovdiv">Plovdiv</option>
  </optgroup>
  <optgroup label="Sweden">

Stockholm

@AndrewRadev
AndrewRadev / dsf.vim
Last active November 5, 2018 05:01
Delete surrounding function call
" Delete surrounding function call
" Relies on surround.vim
"
" function_call(cursor_here) => dsf => cursor_here
"
" Try `dsf` with more complicated structures:
"
" nested(function_call(cursor_here))
" nested(cursor_here(chewy_center))
" One::Two.new([cursor_here])
@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() {