├── README.md └── plugin └── pry.vim /README.md: -------------------------------------------------------------------------------- 1 | # vim-pry 2 | 3 | Insert `pry` statements quickly and easily into your buffer based on the 4 | filetype. 5 | 6 | tl;dr put `nmap d :call pry#insert()` somewhere in your `.vimrc`. 7 | 8 | ## Usage 9 | 10 | In vim make a mapping to call `pry#insert()` and when you're in a file with the 11 | appropriate entry in `g:pry_map` vim-pry will insert the appropriate text. 12 | 13 | For example, calling `pry#insert()` in a Ruby file will insert `require 'pry'; 14 | binding.pry`, JavaScript will insert `debugger;` etc. 15 | 16 | You probably want to define a mapping to this function for ease of use: `nmap 17 | d :call pry#insert()`. 18 | 19 | ## pry_map 20 | 21 | This works based on a global dictionary variable called `g:pry_map`. The key is 22 | the filetype and the value is the text to insert. 23 | 24 | Lets say you're a JavaScript developer and a stroke of genius hits you and you 25 | decide that `alert('hit!');` is better than `debugger;`. You could replace the 26 | mapping with `let g:pry_map.javascript = "alert('hit');"`. 27 | 28 | You can use the same syntax to add entries as well. For more information on 29 | using dictionaries in Vim, check out the chapter in [Learn Vimscript the Hard 30 | Way](http://learnvimscriptthehardway.stevelosh.com/chapters/37.html) 31 | 32 | If this plugin is missing an entry please consider making a pull request adding 33 | it. 34 | 35 | ## Installation 36 | 37 | You should probably be using [vim-plug](https://github.com/junegunn/vim-plug). 38 | Add the following to your `~/.vimrc` file, or wherever you keep your bundles. 39 | 40 | ```vim 41 | Plugin 'BlakeWilliams/vim-pry' 42 | ``` 43 | -------------------------------------------------------------------------------- /plugin/pry.vim: -------------------------------------------------------------------------------- 1 | if exists("g:loaded_pry") || &cp || v:version < 700 2 | finish 3 | endif 4 | 5 | let g:loaded_pry = 1 6 | 7 | let g:pry_map = { 8 | \ 'ruby' : "require 'pry'; binding.pry", 9 | \ 'javascript' : 'debugger', 10 | \ 'javascript.jsx' : 'debugger', 11 | \ 'elixir' : 'require IEx; IEx.pry', 12 | \ 'eruby' : "<% require 'pry'; binding.pry %>", 13 | \ 'typescript' : 'debugger', 14 | \} 15 | 16 | function! pry#insert() 17 | if has_key(g:pry_map, &filetype) 18 | let text = get(g:pry_map, &filetype) 19 | call feedkeys('o', 'i') 20 | call feedkeys(text) 21 | call feedkeys("\") 22 | else 23 | echo 'No mapping defined for filetype: ' . &filetype 24 | endif 25 | endfunction 26 | --------------------------------------------------------------------------------