Tip - How To Quickly Move Lines In Your .NET IDE
[Tip, Development]
Suppose you are working in your favourite IDE and need to move a line of code 3 lines up.
How you would do it depends on whether you are a novice or a master.
A novice would:
- Select the entire line with their mouse (or keyboard if they are especially adept)
- Cut - keyboard
Control/Command,x - Move the cursor three rows up (using mouse or keyboard)
- Paste - keyboard
Control/Command,v
A master would probably use vi key bindings and do the following:
- Cut the entire line and put the contents in the buffer - keystroke.
d,d - Move three lines up - keystroke
3,k - Paste the contents of the buffer - keystroke
p
There is a better way for Zen masters.
- Place the cursor on the line you want to move
- Press and hold the
ALTkey - Press the up arrow ⬆️ as many times as you want the line to move up
To move lines down, use the down arrow, ⬇️ .
This works with the following IDEs:
- Visual Studio
- Visual Studio Code
- JetBrains Rider (if you use Visual Studio bindings)
It also works with SQL Server Management Studio, SSMS.
Happy hacking!