Try:
(require 'misc)
Then use M-x forward-to-word
and see if it does what you want. You can then rebind M-f
, etc.
To make the _
not a word separator (i.e. make it a word constituent) for C & C++ mode, you would do this:
(modify-syntax-entry ?_ "w" c-mode-syntax-table)
(modify-syntax-entry ?_ "w" c++-mode-syntax-table)
For more information on syntax tables, read this wiki page. Syntax tables are generally named like tex-mode-syntax-table
and cperl-mode-syntax-table
.