开发者

On keystroke insert line of code in (mac)vim, for pdb

I'm looking for the way to insert a line of code with a keystroke like leaderp in Macvim

I want to in开发者_JAVA技巧sert 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


Using registers?

write that line somewhere and copy it to register p, then use "pp to print it

import pdb; pdb.set_trace()

"pY

"pp
import pdb; pdb.set_trace()

or use abbreviations

:ab teh the
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜