J_yang
J_yang

Reputation: 2812

Vim, uncomment block of python code starting with # + space. The v-block way

It is common to comment the block of python with with # following with space. So using the v-block mode with ctrl+v, how to delete the first 2 character? Using x will leave a spacebar at the head of line, which messes up the indentation.

# class Memoize:
#     def __init__(self, func):
#         self.func = func
#         self.cache = {}
#     def __call__(self, arg):
#         if arg not in self.cache:
#             self.cache[arg] = self.func(arg)
#         return self.cache[arg]

I know using substitute (s) can do the job, but I find that to be quite slow.

Many thanks.

Upvotes: 0

Views: 355

Answers (2)

Mayank Porwal
Mayank Porwal

Reputation: 34046

You can do it like this:

  1. Go to the beginning of the first line, where you want to delete the first 2 chars from.
  2. Press Ctrl+v. Enter the Visual block mode.
  3. Use the arrow keys to select multiple chars.
  4. In your case, press right arrow key once. This will select # and space.
  5. Press down arrow key to select the multiple lines.
  6. Press x to delete them all.

Below are the images doing the same:

Bring the cursor to beginning of the first line:

enter image description here

Enter the visual block mode and follow Steps #3 and #4:

enter image description here

Press x and save your file:

enter image description here

Upvotes: 1

Kent
Kent

Reputation: 195029

ctrl-v

  • move your cursor on the # of the class line, press ctrl-v
  • press jjjjj..l till the suitable line or Gl if the last commented line is the end of the file.
  • press x

:s

  • select (v or ctrl-v) the lines
  • press :s/^# // then enter.

Upvotes: 2

Related Questions