从RStudio转用PyCharm:如何实现Ctrl+Enter单行代码运行?
Hey there! I totally get that muscle memory from RStudio—using Ctrl+Enter to run single lines of code is such a handy habit for debugging step-by-step and building functions piece by piece. Great news: PyCharm has exactly this functionality, it just might be mapped to a different shortcut by default, or you can even customize it to match your RStudio workflow!
Default Shortcut for Single Line Execution
If you don't want to tweak settings right away, use these default shortcuts to run the line your cursor is on (no need to select anything first):
- Windows/Linux: Press
Alt+Shift+E - Mac: Press
Option+Shift+E
This will send the current line directly to the Python console and execute it, just like Ctrl+Enter does in RStudio. Plus, if you select multiple lines, this same shortcut will run all the selected code at once.
Customize to Use Ctrl+Enter (Just Like RStudio)
If you want to stick with your familiar Ctrl+Enter shortcut, here's how to set it up:
- Open the settings menu:
- Windows/Linux: Go to
File > Settings - Mac: Go to
PyCharm > Settings
- Windows/Linux: Go to
- Navigate to the
Keymapsection in the left sidebar. - In the search bar at the top, type "Execute selection in console" to find the relevant action.
- Right-click on the action, then select
Add Keyboard Shortcut. - Press
Ctrl+Enter(orCmd+Enteron Mac if you prefer that RStudio-like feel for macOS). - If there's a shortcut conflict, PyCharm will warn you—you can either reassign the conflicting shortcut or confirm to replace it.
- Click
OKto save your new shortcut.
Now you can use Ctrl+Enter exactly like you did in RStudio: place your cursor on any line, press the shortcut, and watch it run in the console. Perfect for debugging line-by-line or building code incrementally!
内容的提问来源于stack exchange,提问作者Vedda

