Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 578  / 1 Year ago, tue, february 21, 2023, 10:07:58

In my python application i need to write import import pdb; pdb.set_trace() for debugging.
And after debugging line is removed.



Is there any way in gvim to insert this line by key mapping, so that i have not to type it every time ?


More From » python

 Answers
2

Add to your .vimrc:



command D :normal iimport pdb; pdb.set_trace()^V ESC


Note:




  1. That is indeed two is. Essentially this command does everything that you do when manually entering that text (press i to start insert mode, type the remaining text, etc.).

  2. The ^V ESC means: Press CtrlV to get into verbatim mode, and then press Esc. This will enter Esc as a character (visible as ^[).



Now, in you can go to command mode and use the D command to have this text inserted:



:D


You can also map this to a normal mode shortcut, perhaps.



Instead of ^V ESC, which will bring you out of insert mode, you can add ^V Enter (same thing, press Enter instead of Esc) to go to a new line and remain in insert mode.


[#23332] Thursday, February 23, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gavgenerati

Total Points: 120
Total Questions: 126
Total Answers: 119

Location: Marshall Islands
Member since Wed, Feb 9, 2022
2 Years ago
;