6

Today I had that old feeling of wonder on how powerful VIM is: I needed a number sequence in the start of some fields and discovered the power of g CTRL-A.

So as I always do when I discover something new in VIM I tried to find exactly what this command does, but was baffled to see what :h g told me about g CTRL-A:

g_CTRL-A    g CTRL-A       only when compiled with MEM_PROFILE
                           defined: dump a memory profile

Huh? What's a "memory profile"? what does that have to do with number sequences? I try to use g CTRL-A in other element besides a blockwise selection of numbers and it did nothing.

Can anyone explain what exactly g CTRL-A does and what a memory profile is?

Edit

As @MDeBusk correctly pointed out, that wasn't the correct help entry. A bit down below we see the correct entry as the following:

v_g_CTRL-A  g CTRL-A    2  add N to number in highlighted text

That's better. The former entry was for normal mode. But when using in a selection we're on visual mode.

Fine. But the question remains: what does g CTRL-A on normal mode do? What's a memory profile? Does anyone know?

2 Answers 2

8

But the question remains: what does g CTRL-A on normal mode does ? What's a memory profile ? Anyone knows ?

This refers to this bit of code from src/feature.h:

/*
 * MEM_PROFILE      Debugging of memory allocation and freeing.
 */
// #define MEM_PROFILE

If you remove the // comment symbol at the start of that line (or just add -DMEM_PROFILE to your compiler command line), this will define a C preprocessor variable called MEM_PROFILE. That will in turn enable other code in other files that tracks calls to allocate and free memory and a function called vim_mem_profile_dump(). When that function is compiled into Vim it's called when you use the normal mode g CTRL-A command and when Vim exits.

That function just prints some information about the memory allocations and deallocations that Vim has done to that point:

    printf(_("\n[bytes] total alloc-freed %lu-%lu, in use %lu, peak use %lu\n"),
        mem_allocated, mem_freed, mem_allocated - mem_freed, mem_peak);
    printf(_("[calls] total re/malloc()'s %lu, total free()'s %lu\n\n"),
        num_alloc, num_freed);

This is debugging information that might be of interest to a developer working on the Vim source code. For regular users it won't be of much, if any, interest, which is why it's disabled by default.

3
  • Perfect answer thanks. Are u from the development team ? Sep 16, 2022 at 15:32
  • 1
    @NelsonTeixeira No. But I am a developer who is familiar with C and this particular technique (which is not uncommon), so simply browsing the source a little bit (with help from the GitHub search box) quickly found the code relating to this, which works pretty much as I'd expected it to. The real work was calibrating the answer to make sense to non-developers, which I guess I managed to do. :-P
    – cjs
    Sep 17, 2022 at 6:12
  • Great thanks. :) Sep 19, 2022 at 11:56
6

You're looking at the help for g_CTRL-A in normal mode, but when you're incrementing a list of numbers, you're in visual mode.

I'm sorry; I don't know what a memory profile is exactly. It's related to debugging and requires vim to be compiled with that purpose in mind. When I type g_CTRL-A in normal mode, I don't notice anything happening. I didn't compile it with MEM_PROFILE, so I imagine nothing does happen.

1
  • You're correct, will change my question accordingly Sep 16, 2022 at 3:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.