Vim Tips Wiki
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Vim Tips Wiki
1,649
pages
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
Editing
PHP editing
Back to page
Edit
Edit source
View history
Talk (0)
Edit Page
PHP editing
We recommend that you
log in
before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your
Watchlist
.
Creating an account
is quick and free.
The edit appears to have already been undone.
Anti-spam check. Do
not
fill this in!
{{TipImported |id=1025 |previous=1023 |next=1026 |created=2005 |complexity=basic |author= |version=6.0 |rating=4/5 |category1=PHP |category2= }} Here are some suggestions that may help when editing PHP files. ==Move to next variable on current line== PHP variables start with '<code>$</code>', for example, <code>$var</code>. In normal mode, type <code>f$</code> to jump forwards to the next variable; repeat by pressing <code>;</code> (next, in same direction), or <code>,</code> (next, in opposite direction). Typing <code>F$</code> finds '<code>$</code>' in the backwards direction. {{help|f}} If you do this a lot, you may want to use the following mappings in your [[vimrc]] so you can press <code>L</code> to jump to the next variable, or <code>H</code> to jump to the previous variable: <pre> noremap L f$ noremap H F$ </pre> ==Fix 4 instead of $== It's easy to press <code>4</code> instead of <code>$</code>, resulting in code like this: <pre> $var = "sometext"; echo 4var; </pre> With the following map, you can quickly fix this problem by typing <code>\4</code> while the cursor is still on the same line, after the '4' (this assumes the default backslash <Leader> key): <pre> nnoremap <Leader>4 F4r$A </pre> Here is an alternative that returns the cursor to its initial position: <pre> nnoremap <Leader>4 m`F4r$`` inoremap <Leader>4 <Esc>m`F4r$``a </pre> ==Abbreviations to insert debug code== The following abbreviations provide an easy way to enter debug code. In insert mode, type <code>phpb</code> then the name of a variable to be displayed. <pre> iab phpb exit("<hr>Debug "); iab phpv echo "<hr><pre>";var_dump($a);exit("debug "); </pre> These display any variables that have been yanked into register <code>a</code>: <pre> iab phpbb exit("<hr>Debug <C-R>a "); iab phpvv echo "<hr><pre>";var_dump(<C-R>a);exit("debug "); </pre> <code>Var_dump</code> is used for displaying arrays. This displays all defined variables: <pre> iab phpallv print_r(get_defined_vars()); </pre> ==Replace associative with object style notation== The substitute command presented below looks for each PHP array reference like: <pre> $a = $some_array['key_name']; </pre> and replaces it with: <pre> $a = $some_array->key_name; </pre> Command: <pre> :%s/\['\(.\{-}\)'\]/->\1/gc </pre> In the above, the <code>c</code> flag prompts for confirmation of each change. ==See also== *{{script|id=604|text=php.vim (html enhanced)}} combination of the php and html indent files ==Comments==
Summary:
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Help
(
view source
)
Template:Navigation
(
view source
)
Template:Script
(
view source
)
Template:TipImported
(
view source
)
Follow on IG
TikTok
Join Fan Lab