This is a transcript of the live video, which can be seen on Youku
There are plenty of articles about Mac productivity, but not all of them are for programmers. Some Unix commands, for example, are used infrequently. As a junior iOS programmer, I’ve tried to share a few tips that can actually improve our development efficiency.
I’m a mouseless person, and anything that requires a mouse is extremely inefficient in my view. The Mac’s trackpad is great, but I still try to avoid it. Because keeping your hands on the keyboard is better for programming. While the trackpad can’t be avoided (like browsing the Web), I’d like to avoid it at least in Xcode.
So, this article will share some system-level shortcuts for Xcode, Chrome, iTerm, and other applications, as well as common tools like Vim and Git. Except for Xcode, all of these are generic, so if you’re not an iOS developer, check out the IDE shortcuts.
review
Some people may find shortcuts awkward to use, rather than using their own trackpad (mouse). However, you should be aware that there is a limit to how effective you can be with a trackpad, and it will be much faster once you get used to the shortcuts.
This is especially important when learning VIM. Instead of focusing on how long it takes to complete a command, you should focus on how many keystrokes it takes, and you can think of a keystroke as having zero thought time after muscle memory is formed. So we came to a conclusion:
Total time = number of keystrokes * a constant (representing the time of a single keystroke).
Therefore, the evaluation of an action in VIM is usually expressed as a golf score, which indicates how many keystrokes it takes to complete the action.
But!! Shortcuts are efficient, but they don’t improve code quality. Insist on learning, but also to stop, never put the horse before the horse.
It’s not about how many shortcuts you learn, it’s about how much work you can do with them, for efficiency, that’s all.
A powerful, universal way to do this is to set -> Keyboard -> Shortcuts -> Apply shortcuts and then exactly match the names of the shortcuts in your application. This is usually done in conjunction with CheatSheet. This is also the way to change shortcuts when you feel they don’t work.
When setting shortcut keys, avoid conflicts between global shortcut keys and application shortcut keys, and ensure that some common operations are consistent across multiple applications.
I recommend switching Caps Lock to Ctrl, because the case key is used very infrequently, and Ctrl is used much more frequently than he is, so it is necessary to put the case key where it is least accessible.
Here are some of the shortcuts I use, most of them native to the system, but a few of them are my own.
An introduction to
- The preference pages of most apps pass
Command + ,
Open. - Cut, copy, paste, undo, redo, and move the cursor to the beginning and end of a line are all basic operations that must be mastered.
Snap
I believe many people have such trouble: if the application is not full screen, then the desktop display too many Windows, each window display content is not enough. Switching apps is cumbersome if the app is in full screen. Either Command + Tab or gesture swipe, but either way, the time is order n. Is there a way to order one? The answer is to use an artifact: snap
I mainly use the first or key letter of the application as the identifier, with Command + Shift prefix:
- Xcode:
J
- Chrome:
K
- ITerm:
L
- Markdown related:
M
- QQ:
Y
- WeChat:
U
- SoureceTree:
S
- MacVim:
V
- The company:
E
- The Dock:
1/2/3/4
I use memos, emails, calendars, and Settings for my work ;
I haven’t enabled this key, but it’s actually a very handy shortcut.
Choosing a Dock app is a tradeoff. Obviously the fastest way is to just press Command, but this global shortcut can cause a lot of conflicts. Controll and Option keys are very difficult to touch, so I choose Command + Shift as the shortcut prefix for all applications.
Avoid letterso
和 f
They have special uses in Xcode.
Xcode shortcuts
Compile, run, Instruments, unit tests, pause these basic operations are not explained. I’ll bold some of the commands I think are useful:
The file editor
Command + [
和Command + ]
Around the indentationCommand + Option + [
和Command + Option + ]
The current row moves up or downCommand + Option + Left/Right
Collapses and expands the current code snippet
File a jump
Command + Control + Up/Down
Switch between.h and.m filesCommand + Control + Left/Right
Browsing history switchCommand + Control + j
Jump to the definitionCommand + Option + j
Jump to directory searchCommand + 1/2/3/4/5
Jump to a different column on the leftComannd + Shift + o
File search
search
Comannd + Shift + f
Global searchCommand + e
Searches for the currently selected wordCommand + g
Search next
tab
Command + t
Create a new TABCommand + w
Close current TABCommand + Shift + [
和Command + Shift + ]
Left and right TAB
Scheme
Command + shift + ,
Edit Scheme to select Debug or Release
debugging
F6: jumps to the next instruction F7: jumps to the next instruction (it will jump into the internal function, the specific effect of the test) Control + Command + y continue to run
other
Command + k
Delete the contents of ConsoleCommand + d
Enable/disable the console (modify system shortcut keys: Show/Hide Debug Area)
For a more comprehensive introduction to keyboard shortcuts, see: this article
Vim commonly used shortcut keys
I have a Vim configuration on git, first download to ~/ directory, and then establish a soft connection:
rm .vimrc
ln -s .vim/.vimrc .vimrc
Copy the code
I recommend a Vim app for Mac: MacVim, which is better than viewing Vim on a terminal. After opening MacVim, type the following command to install the plug-in:
:BundleInstall
Copy the code
Enter input mode
i
Enter input mode in front of the cursor,a
Enter input mode after the cursorI
Enter input mode at the beginning of the line,A
The end of the line goes into input modeo
Go into input mode at the beginning of the next line,O
Enter input mode at the beginning of the previous line
Text manipulation
yy
Copy the current row,dd
Cut the current row,p
Replication. Note that I’m using Vim’s own clipboard.U
Cancellation, * *Ctrl + r
redox
Deletes the letter where the cursor is locatedcae
或bce
Delete the word where the cursor is and enter edit modeNumber + command
Repeat the command n times, for example3dd
The cursor
^
At the beginning of the line,$
Go to the end of the line: 111
或111G
Skip to line 111,gg
The first line,G
Last row.e
Move to the end of the word,w
Move to the beginning of the next word.%
Matches the parentheses (curly parentheses, middle parentheses, curly parentheses) where the current cursor is located*
Find the next word that is the same as the word where the cursor isF + letters
Jump to the position where the letter first appears,2fb
Jump to the second occurrence of the letter BT + letters
Jump to the position before the first appearance of the letter,3ta
Jump to the position before the third occurrence of the letter A- F and T are capitalized to move in the opposite direction.
Dt + letters
Indicates all contents before the letter is deleted.
The lines
<start position><command><end position>
Such as0y$
, from the beginning of the line to the end of the line,ye
Copy from the current position to the end of the word.<action>a<object>
或<action>i<object>
An action can be any command, such as d, y, v, etc. Object can be a W word, a P paragraph, or a specific letter. The difference between a and I is that I stands for inner and only works on the inside, not both ends.
Think about it, how many ways can you delete the word where the cursor is?
Answer: DIW, DAW, CAW, CIw, BCE, BDE.
Think about how they work, the latter two are not recommended (it’s possible to skip to the previous word).
What if you select the current word?
In addition to the above basic grammar, I am also compiling a set of Vim Basic Exercises, which WILL be shared with you after completion.
In actual combat
-
Comment multiple lines:
-
V: Enter the visual state
-
Nj: Select n lines down, or type Shift] to skip to the end of the segment
-
Command + / adds a comment
-
In MacVim, git blame is crystal clear:
Chrome
Command + l
Focus moves to the address barShift + Option + Delete/Left
Delete/select a word left (can be customized asCtrl-w
)Command + y
Search historyThe Command + digital
Quick TAB switchCommand + shift + []
Left and right TABCommand + t/w
Create/close a TABCommand + e/g
Search selected, go to next, or useCommand + f
And press enter.
As you can see, operations involving tabs in Chrome should be as consistent as possible with Xcode.
iTerm2
Ctrl w
Delete the previous wordCommand + r
Clear the contents of the screenCommand + t/w
Open/close TABThe Command + digital
Let’s go to the NTH TABDouble click on the
Select a word and copy it automatically
ITerm can switch tabs Left and Right by Command + Shift + [] or Left/Right by Command + Left/Right, which is redundant and uncustomary.
So refer to this article or Google, and in Preference->Keys->Global Shortcut Keys, set Command plus left and right Keys, and the corresponding operation of delete Keys.
Git
The essence of Git is manipulation of Pointers.
Master git add, commit, Stash, pull and fetch operations
Understand what is a local repository and what is a remote repository, understand the concepts of merge and conflict in multiplayer development
Master the use of branches and the use of the checkout command
Master git rebase operations, including Git rebase -I and Git rebase –onto, and master a Git workflow
Oh my zsh
First download the oh-my-zsh configuration to the ~/ directory, and then perform the following operations on the command line:
rm .zshrc
ln -s .sys.config/.zshrc .zshrc
Copy the code
Then restart iTerm. You can the be fond of according to oneself, to ~ /. Sys. Config/setting/git. Useful configuration git command alias, such as;
alias gcm='git commit -m'
alias gignore='git update-index --assume-unchanged'
alias gpush='git push origin HEAD:dev; '
alias go='git checkout'
Copy the code
More
Alfred is said to be a productivity dynamo, and since I don’t usually play with the MAC beyond writing code, I didn’t get to know it. If there are more good shortcuts and apps, feel free to talk to me.