phpstorm技巧_PhpStorm-最高效率的技巧和捷径

phpstorm技巧

We all have our favorite IDEs/editors when coding. Mine is PhpStorm, and it took a while to master all its shortcuts and establish a rapid workflow. In this article, I’ll share some keyboard shortcuts and tips with you which you should make part of your regular routine if you, too, do your work in this IDE. This article was partially inspired by this Reddit thread, and will be mentioning and demonstrating some of the shortcuts found there as well.

编码时,我们都有我们最喜欢的IDE /编辑器。 Mine是PhpStorm ,花了一段时间才能掌握其所有快捷方式并建立快速的工作流程。 在本文中,我将与您分享一些键盘快捷键和提示,如果您也要在此IDE中进行工作,则应将它们作为常规例程的一部分。 本文部分受此Reddit线程的启发,并且还将提及并演示在此找到的一些快捷方式。

Note that as I’m doing my development on Linux in a vagrant box hosted on Windows, my shortcuts might be different from yours. The JetBrains reference card matches them up perfectly and gives you the OS X alternatives: Reference Card.

请注意,当我在Windows托管的游民机中进行Linux开发时,我的快捷方式可能与您的不同。 JetBrains参考卡与它们完美匹配,并为您提供了OS X替代品: 参考卡

键盘快捷键和黑客 (Keyboard shortcuts and hacks)

PhpStorm’s high configurability (it’s almost an “Android” of the PHP IDE world) lets you fine tune it to infinity – you can make it into a tool so personal, it might seem like a different IDE to anyone opening your settings. Let’s see some shortcuts and hacks we can take advantage of:

PhpStorm的高可配置性(它几乎是PHP IDE世界的“ Android”)使您可以将其微调到无穷大–您可以将其变成一个如此个性化的工具,对于任何打开设置的人来说,它似乎都是不同的IDE。 让我们看看一些可以利用的快捷方式和技巧:

  • alt

    CTRL + ALT + L, one of my most used keyboard combos, will immediately format your code according to the preferred style guidelines:

    CTRL + ALT + L,我最常用的键盘组合之一,将根据首选的样式准则立即格式化您的代码:

    What’s more, as you can see by the popup that appears in the animation above, you can choose to reformat your entire project. If you use this excessively and don’t often work on other people’s projects, you take it up another notch – bind a macro to the CTRL+S shortcut, and make PhpStorm automatically reformat your code on every manual save. Note, however, that if you’re working on a project with someone else, this might cause refactors in various files far too often, and pollute your version control system with changes that aren’t changes at all. If you’re on Linux, your CTRL+ALT+L shortcut might already be bound to “Lock Screen”, and you’ll need to unbind it from the system, or change it in PhpStorm’s settings.

    此外,如上方动画所示的弹出窗口所示,您可以选择重新格式化整个项目。 如果您过度使用该代码,并且不经常在其他人的项目上工作,则需要多加保留- 将宏绑定到CTRL + S快捷方式,并使PhpStorm在每次手动保存时自动重新格式化代码。 但是请注意,如果您正在与其他人一起进行项目,这可能会导致过多地重构各种文件,并以根本没有任何改变的方式污染您的版本控制系统。 如果您使用的是Linux,则您的CTRL + ALT + L快捷方式可能已经绑定到“锁定屏幕”,您需要将其与系统解除绑定,或者在PhpStorm的设置中进行更改。

  • alt

    Pressing CTRL+SHIFT+Backspace, or the “Forward” and “Back” buttons on your mouse if you have them, will walk you through your previous edit locations. This is very useful when dealing with large files and having to reference another part only to come back to the original to continue the work:

    按CTRL + SHIFT + Backspace或鼠标上的“前进”和“后退”按钮(如果有的话)将带您浏览以前的编辑位置。 当处理大文件并且仅引用原始部分以继续工作时,这非常有用:

  • alt

    Holding down CTRL when hovering over variables or methods will give you their full names or locations of declaration, while CTRL+Clicking on a variable or method, or pressing CTRL+B when on a method’s call or on a variable will take you directly to where it’s defined:

    将鼠标悬停在变量或方法上时,按住CTRL键将为您提供其全名或声明位置,而在按住CTRL +单击变量或方法时,或在调用方法或变量时按CTRL + B将您直接带到哪里它的定义是:

  • alt

    CTRL+Space will summon a code hinting dialog, if you accidentally closed it or for some reason it didn’t open:

    如果您不小心关闭了它或由于某种原因而未打开它,则CTRL + Space将召唤一个代码提示对话框:

  • alt

    When PhpStorm detects some problems, it will underline the problematic area and summon a lightblub on top of it when you hover your mouse or keyboard cursor in that area. Clicking this light bulb or pressing ALT+Enter will suggest solutions – in any language. This can range from turning off error reports for suppressed notices (something I recommend against), to merging CSS rules:

    当PhpStorm检测到一些问题时,它将在有问题的区域下划线并在您的鼠标或键盘光标悬停在该区域时在其上方召唤一个lightblub。 单击此灯泡或按ALT + Enter将以任何语言建议解决方案。 范围从关闭错误报告以消除隐患的通知(我建议反对 )到合并CSS规则:

  • alt
    alt

    CTRL+N and CTRL+SHIFT+N will let you instantly move to any part of any class or file in your entire project: The search is fuzzy, and also supports line numbers – you can use abbreviations followed by :XX where XX is the line number:

    CTRL + N和CTRL + SHIFT + N可以让您立即移动到整个项目中任何类或文件的任何部分:搜索是模糊的,并且还支持行号–您可以使用缩写,后跟:XX,其中XX是电话号码:

  • PhpStorm remembers multiple clipboard contents – you can press CTRL+SHIFT+V to summon a popup which lets you paste clipboard content that’s less recent than the latest.

    PhpStorm会记住多个剪贴板内容–您可以按CTRL + SHIFT + V召唤一个弹出窗口,使您可以粘贴比最近的剪贴板内容短的内容。

  • alt

    If you’re in love with Sublime’s ability to search for commands of the IDE itself, you can do that too. CTRL+SHIFT+A will spawn a command search popup. Forgot how the code reformat shortcut goes? Just CTRL+SHIFT+A and type “refor..”:

    如果您喜欢Sublime的搜索IDE本身命令的功能,也可以这样做。 CTRL + SHIFT + A将产生命令搜索弹出窗口。 忘记了重新格式化快捷方式的代码吗? 只需按CTRL + SHIFT + A,然后输入“ refor ..”:

  • alt

    Generate full HTML without writing it out, using Emmet, built into PhpStorm. Typing div#myDiv>span.mySpanClass>ul>li*5 and hitting tab will turn into: Further extend this in any language of your choice by adding your own expandable templates into the Settings -> Editor -> Live Templates dialog. You can choose where to position your cursor, add variables, and much more. The full Emmet cheat sheet for CSS and HTML can be found here.

    使用PhpStorm内置的Emmet生成完整HTML,而无需将其写出来。 键入div#myDiv>span.mySpanClass>ul>li*5div#myDiv>span.mySpanClass>ul>li*5 tab将变成:通过将自己的可扩展模板添加到“ Settings -> Editor -> Live Templates对话框中,以您选择的任何语言进一步扩展此语言。 您可以选择将光标放置在何处,添加变量等等。 完整的Emmet CSS和HTML备忘单可以在这里找到。

  • alt

    Perhaps somewhat counter-intuitively, CTRL+W (which is most often used for closing tabs, so you may want to remap it) will select a “unit” of code under your cursor (a word, a variable, etc). Repeating the combination then expands the selection to include the parent node – all the way to the entire file (e.g. function call -> instance and function call -> row -> entire row -> method -> containing class…):

    也许有点违反直觉,CTRL + W(最常用于关闭选项卡,因此您可能需要重新映射它)将在光标下选择代码的“单位”(单词,变量等)。 重复组合然后将选择范围扩展到包括父节点-一直到整个文件(例如,函数调用->实例和函数调用->行->整行->方法->包含类…):

  • alt

    Context-aware editing will allow you to edit a string that’s written in another language in a dedicated editor, complete with code hinting and autocompletion. For example, you if you have an HTML snippet written in a PHP string, you can ALT+ENTER in the string’s content and select Edit HTML content. This happens:

    上下文感知的编辑将允许您在专用的编辑器中编辑用另一种语言编写的字符串,并带有代码提示和自动完成功能。 例如,如果您有用PHP字符串编写HTML代码段,则可以在字符串的内容中按ALT + ENTER,然后选择“编辑HTML内容”。 有时候是这样的:

  • alt

    Column selection mode can be summoned by holding the middle mouse button down and dragging over a piece of code. I’ve found this especially useful when I need to paste a deeply indented part of my code, but don’t want the preceding whitespace copied as well:

    可以通过按住鼠标中键并拖动一段代码来调用列选择模式。 当我需要粘贴代码的深缩进部分但又不想复制前面的空格时,我发现这特别有用:

  • alt

    Pressing ALT+Home will let you use your cursors to move through the breadcrumb navigation at the top. ESC escapes this mode and returns you to the editor, unless you make a file selection in the breadcrumbs – then the file is immediately in focus.

    按ALT + Home将使您可以使用光标在顶部的面包屑导航中移动。 ESC会退出此模式,并返回到编辑器,除非您在面包屑中选择了文件,否则该文件将立即成为焦点。

  • alt

    Refactoring (renaming) variables and applying the change to all locations that use it is as easy as selecting right-click -> refactor, pressing SHIFT+F6 or even pressing SHIFT+ALT+CTRL+T to summon the entire refactor menu as shown in the animation below:

    重构(重命名)变量并将更改应用到使用该变量的所有位置,就像选择右键单击->重构,按SHIFT + F6甚至按SHIFT + ALT + CTRL + T即可召唤整个重构菜单一样简单,如图所示。以下动画:

  • alt

    CTRL+F12 will summon a popup that lets you select a method in the current file to which you want to jump. Even though there’s no search field, if you just start typing you can narrow the selection down to exactly what you’re looking for.

    CTRL + F12将召唤一个弹出窗口,您可以在该弹出窗口中选择要跳转到的当前文件中的方法。 即使没有搜索字段,如果您只是开始输入,也可以将选择范围缩小到您要查找的内容。

  • As described in this tweet, you can now “search everywhere” by double-tapping Shift. This is like a powerful blend of all previous search shortcuts, allowing you to find anything you need in any part of the project or IDE – from IDE commands to classes and function declarations and more.

    本推文所述 ,您现在可以通过双击Shift来“在任何地方搜索”。 这就像所有以前的搜索快捷方式的强大结合,使您可以在项目或IDE的任何部分中找到所需的任何内容-从IDE命令到类和函数声明等等。

外挂程式 (Plugins)

PhpStorm has a wealth of various language plugins. I, for one, make heavy use of the Dart plugin for PhpStorm. This isn’t the type of plugin I’d like to talk about, though – there’s a plethora of productivity plugins, too. Plugins adding features you never thought a PHP IDE might have:

PhpStorm有大量的各种语言插件。 我首先大量使用了PhpStorm的Dart插件。 不过,这不是我要谈论的插件类型-还有很多生产力插件。 插件添加了您从未想到过PHP IDE可能具有的功能:

  • The combination of DynamicReturnType plugin with a good dependency injector, as described by Danack, will let you do proper IoC and still keep all your autocompletion and code inspection as if dealing with the classes directly. A more detailed article on using this particular combination will be published soon.

    Danack所述 ,将DynamicReturnType插件与良好的依赖注入程序 结合使用 ,可以使您执行适当的IoC,并且仍然保留所有自动完成和代码检查的功能,就好像直接处理类一样。 即将发布有关使用此特定组合的更详细的文章。

  • The key promoter plugin shows you the keyboard shortcut to your mouse actions as you perform them. If you use certain actions a lot, and they don’t have a keyboard shortcut, it will ask you if you’d like to add it.

    按键启动器插件向您显示执行鼠标操作时的键盘快捷键。 如果您经常使用某些操作,但是它们没有键盘快捷键,它将询问您是否要添加它。

  • CSS-X-Fire allows you to edit your CSS in Chrome’s Firebug lite, or Firefox’s Firebug, and on switching back to PhpStorm, you’ll be asked if you’d like to apply the changes you made in the browser to the CSS in your project’s code.

    CSS-X-Fire允许您在Chrome的Firebug lite或Firefox的Firebug中编辑CSS,并切换回PhpStorm时,系统会询问您是否要将在浏览器中所做的更改应用于CSS中。您项目的代码。

  • You might know that PhpStorm is a project-based IDE, meaning it cannot open and edit arbitrary non-project files like a regular text editor. This can be awkward when you need to brainstorm something or just write some notes for yourself but don’t want to pollute your project’s folder. Scratch lets you use temporary files in your projects for that exact purpose.

    您可能知道PhpStorm是基于项目的IDE,这意味着它无法像常规文本编辑器一样打开和编辑任意非项目文件。 当您需要集思广益或只为自己写一些笔记但又不想污染项目的文件夹时,这可能会很尴尬。 Scratch允许您将项目中的临时文件用于该特定目的。

深色主题,易于阅读 (Dark themes for readability)

Many people underestimate a good theme, dismissing it outright as flair or pure vanity. This is wrong – a good theme is a good user experience – it increases readability and makes you notice errors, keywords and all the syntax spice intuitively, without having to think about it. There are several benefits to using dark themes:

许多人低估了一个好主题,将其完全视为天才或纯洁的虚荣心。 这是错误的-好的主题是良好的用户体验-它提高了可读性,并让您直观地注意到错误,关键字和所有语法香料,而无需考虑它。 使用深色主题有几个好处:

  • when looking at a bright display, your eyes get fatigued faster, especially at night (which is when most programmers tend to do their work). On dark displays, instead of focusing on the entire bright screen and trying to discern holes in it (darkness – letters), your eyes are immediately drawn to the bright parts – the text, ignoring the background altogether.

    当观看明亮的显示器时,您的眼睛会更快疲劳,尤其是在晚上(这是大多数程序员倾向于工作的时候)。 在黑暗的显示器上,您不会将注意力集中在整个明亮的屏幕上并试图辨别屏幕上的Kong洞(黑暗–字母),而是立即将眼睛转向明亮的部分–文字,而完全忽略了背景。
  • I subjectively claim that colors are easier to notice when on darker backgrounds. Naturally, this means the colors should have a decent, but not too strong contrast to the background

    我主观地声称,在深色背景上,颜色更容易被发现。 自然地,这意味着颜色应该与背景具有相称但不太强烈的对比
  • It’s a known fact that blue light from self-lit displays suppresses melatonin, which in turn disrupts your sleep patterns. If you find yourself having difficulty falling asleep after a 4AM coding session despite feeling utterly obliterated by fatigue, try a darker theme and exposing yourself to less light in general when working at night.

    众所周知 ,自发光显示器发出的蓝光会抑制褪黑激素,进而破坏您的睡眠方式。 如果您发现自己在4AM编码会议后仍难以入睡,尽管感到疲倦被完全遮盖住了,请尝试使用较暗的主题,并在夜间工作时将自己暴露在较少的光线下。

Things to look for in a theme are mid-range contrasts. Avoid absolutes – the background shouldn’t be pure black, and the text shouldn’t be pure white/red/green/orange. These sharp contrasts confuse and strain the eye just as much as having an all-white background and all-dark text does. Instead, look for pastel, smokey colors. Likewise, increasing the font is usually a good idea, if the theme’s default is tiny. The eyes strain when reading too small letters, and if the spacing isn’t good enough either, you’ll have a hard time reading anything without welcoming a headache. Two of my suggestions for darker themes are Darcula, which comes built into PhpStorm, and Solarized.

主题中要寻找的东西是中等范围的对比。 避免使用绝对值-背景不应为纯黑色,文本不应为纯白色/红色/绿色/橙色。 这些鲜明的对比就像全白背景和全黑文字一样使眼睛迷惑和疲劳。 相反,请寻找柔和的烟熏颜色。 同样,如果主题的默认值很小,则增加字体通常是个好主意。 阅读太小的字母时眼睛会疲劳,如果间距也不足够,您将很难阅读任何内容而不会感到头痛。 我对较暗主题的两个建议是Darcula(已内置到PhpStorm中)和Solarized

Apart from the generally more pleasant color scheme in Darcula (shown above), I’m the type of developer who uses comments extensively in my projects, so having them more legible but still not distracting is a valuable perk. The project structure is also, in my opinion, far more readable in the second screenshot – the light blue vs. gray contrast seems optimal to my eye.

除了在Darcula中通常更令人愉悦的配色方案(如上所示)之外,我是在项目中广泛使用注释的开发人员类型,因此使注释更清晰但又不会分散注意力是一种宝贵的特权。 在我看来,第二个屏幕截图中的项目结构也更具可读性-浅蓝色与灰色的对比似乎是我的最佳选择。

While most theme preference discussions are, admittedly, subjective, I encourage you to venture outside your eyes’ comfort zone for a day or two and give alternatives a go. You’d be surprised at how fast you can adapt to the new style if you find one that particularly matches you.

虽然大多数主题首选项讨论都是主观的,但我还是鼓励您冒险在自己舒适的区域之外进行一两天的尝试,并尝试其他方法。 如果发现特别适合您的样式,您会以多快的速度适应新样式,您会感到惊讶。

结论 (Conclusion)

In this article, we covered and demonstrated some popular and/or extremely useful keyboard shortcuts and productivity hacks for PhpStorm – an IDE that’s far more customizable than one might assume at first glance. What are your tips and productivity hacks? Do you see any missing? Let us know in the comments below and we’ll add them!

在本文中,我们介绍了PhpStorm的一些流行的和/或极其有用的键盘快捷键和生产力黑客,这是一种IDE,其自定义性远比乍一看要好得多。 您有哪些技巧和生产力方面的技巧? 您是否看到任何遗失? 在下面的评论中告诉我们,我们将其添加!

翻译自: https://www.sitepoint.com/phpstorm-top-productivity-hacks-shortcuts/

phpstorm技巧

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值