Vim Tips Wiki
Advertisement
Tip 1602 Printable Monobook Previous Next

created August 15, 2008 · complexity basic · author Kale77in · version 7.0


A legacy PHP program may use variable names with underscores, for example, $this_variable_style.

Some mappings are given below to help convert legacy PHP variables to Zend/Pear/etc style, for example, $thisVariableStyle.

Converting from legacy PHP

The commands below define these mappings:

  • + Find the next $variable_with_underscores.
  • _ Convert the next underscore on the current line.

When required, you can yank the following lines in Vim (on the first line, type 2Y), then execute them (type :@") to map the + and - keys.

nnoremap + /\$\w\+_<CR>
nnoremap _ f_x~

Now you can press + to search for the next $variable_with_underscores, then press _ to find the next underscore and delete it, then toggle the case of the next character. Repeatedly press _ until all underscores are processed, then press + to find the next variable. For example, you may type +__+_+___ to skip through a file.

Type +~ for initial capitals.

Comments

I've decided to keep this short tip (which I have expanded) in anticipation that future changes may introduce other methods for converting between different variable name formats. There is probably a substitute command that would help. JohnBeckett 03:33, 5 April 2009 (UTC)


Advertisement