Wikia

Vim Tips Wiki

Watchlist Recent changes

Convert enum to string table

Redirected from VimTip107

Tip 107 Printable Monobook Previous Next

created September 5, 2001 · complexity basic · author Thomas Ramming · version 5.7


When testing your C/C++ programs, you sometimes wish to have a trace output showing you which enum value is used.

You can do this by creating a string table for that enum type, which contains the enum identifier as a string.

For example:

printf("%s", MyEnumStringTable[MyEnumVal]);

You can create the complete string table by:

  • Marking the lines containing the complete typedef enum.
  • Selecting menu C/C++.transform enum2Stringtab

You can create string table entries by:

  • Marking the lines within the typedef enum
  • Selecting menu C/C++.transform enum2String

This makes it easy to keep the enum (on changes) consistent to the string table.

Add the following lines to your gvimrc file:

31amenu C/C++.transform\ enum2Stringtab :s#[ ]*\\(\\w\\+\\)#/* \\1 */ "\\1"#<CR>o};<Esc>uOstatic const char* const Names[] = {<Esc><CR>:noh<CR>
31vmenu C/C++.transform\ enum2Stringtab :s#[ ]*\\(\\w\\+\\)#/* \\1 */ "\\1"#<CR>o};<Esc>uOstatic const char* const Names[] = {<Esc><CR>:noh<CR>

31amenu C/C++.transform\ enum2String :s#[ ]*\\(\\w\\+\\)#/* \\1 */ "\\1"#<CR>o}<Esc>:noh<CR>
31vmenu C/C++.transform\ enum2String :s#[ ]*\\(\\w\\+\\)#/* \\1 */ "\\1"#<CR>o}<Esc>:noh<CR>

CommentsEdit

Pages on Vim Tips Wiki

Add a Page
1,586pages on
this wiki
Advertisement | Your ad here

Latest Photos

Add a Photo
71photos on this wiki
See more >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki