I'm looking for the way to insert a line of code with a keystroke like leaderp in Macvim
I want to insert the following line of code:
import pdb; pdb.set_trace()
Probably not an unheard of line of code in python land
I'd use a simple mapping (without functions) to leader p:
nnoremap <leader>p oimport pdb; pdb.set_trace()<Esc>
When pressing o, this enters insert mode inserts a blank line after the current one (with o) and then types import pdb; pdb.set_trace()
, finally it goes back to normal mode (with Esq).
If you want to insert the code before the current line replace o by O:
nnoremap <leader>p Oimport pdb; pdb.set_trace()<Esc>
Or alternatively you could set this for leader shift-p:
nnoremap <leader><S-p> Oimport pdb; pdb.set_trace()<Esc>
Why not try the vimpdb plugin? Alternatively, if your looking for snippet functionality, the combination of the supertab and snipmate plugins works great.
This might not be the best vimscript every but it does wat you want! :-) Just place this in your .vimrc and you can call it with leader p.
map <Leader>p :call InsertLine()<CR>
function! InsertLine()
let trace = expand("import pdb; pdb.set_trace()")
execute "normal o".trace
endfunction
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With