Skip to content

Instantly share code, notes, and snippets.

@gawen
Last active August 29, 2015 14:07
Show Gist options
  • Save gawen/73254ac12b6c20252a8e to your computer and use it in GitHub Desktop.
Save gawen/73254ac12b6c20252a8e to your computer and use it in GitHub Desktop.
This VIM macro saves my life
" Put your text cursor on an expression you want to search in your project
" and type :Gr
" It will open a buffer on the left with every references of this expression
" in your current folder (recursively).
python << EOF
import vim
def set_register(reg, value):
vim.command("let @%s='%s'" % (reg, value.replace("'","''")))
def get_register(reg):
return vim.eval("@" + reg)
def get_word_under_cursor():
set_register("g", "")
vim.command("normal viw\"gy")
return get_register("g")
def grep_word():
word = get_word_under_cursor()
vim.command("vnew")
vim.command("r!grep -R \"%s\" * | grep \"%s\"" % (word, word, ))
vim.command("/%s" % (word, ))
vim.command("normal gg0")
vim.command("command Gr py grep_word()")
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment