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

  1. The preference pages of most apps passCommand + ,Open.
  2. 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:

  1. Xcode:J
  2. Chrome:K
  3. ITerm:L
  4. Markdown related:M
  5. QQ:Y
  6. WeChat:U
  7. SoureceTree:S
  8. MacVim:V
  9. The company:E
  10. The Dock:1/2/3/4I use memos, emails, calendars, and Settings for my work
  11. ;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 lettersofThey 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

  1. Command + [Command + ]Around the indentation
  2. Command + Option + [Command + Option + ]The current row moves up or down
  3. Command + Option + Left/RightCollapses and expands the current code snippet

File a jump

  1. Command + Control + Up/DownSwitch between.h and.m files
  2. Command + Control + Left/RightBrowsing history switch
  3. Command + Control + jJump to the definition
  4. Command + Option + jJump to directory search
  5. Command + 1/2/3/4/5Jump to a different column on the left
  6. Comannd + Shift + oFile search

search

  1. Comannd + Shift + fGlobal search
  2. Command + eSearches for the currently selected word
  3. Command + gSearch next

tab

  1. Command + tCreate a new TAB
  2. Command + wClose current TAB
  3. Command + Shift + [Command + Shift + ]Left and right TAB

Scheme

  1. 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

  1. Command + kDelete the contents of Console
  2. Command + dEnable/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

  1. iEnter input mode in front of the cursor,aEnter input mode after the cursor
  2. IEnter input mode at the beginning of the line,AThe end of the line goes into input mode
  3. oGo into input mode at the beginning of the next line,OEnter input mode at the beginning of the previous line

Text manipulation

  1. yyCopy the current row,ddCut the current row,pReplication. Note that I’m using Vim’s own clipboard.
  2. UCancellation, * *Ctrl + rredo
  3. xDeletes the letter where the cursor is located
  4. caebceDelete the word where the cursor is and enter edit mode
  5. Number + commandRepeat the command n times, for example3dd

The cursor

  1. ^At the beginning of the line,$Go to the end of the line
  2. : 111111GSkip to line 111,ggThe first line,GLast row.
  3. eMove to the end of the word,wMove to the beginning of the next word.
  4. %Matches the parentheses (curly parentheses, middle parentheses, curly parentheses) where the current cursor is located
  5. *Find the next word that is the same as the word where the cursor is
  6. F + lettersJump to the position where the letter first appears,2fbJump to the second occurrence of the letter B
  7. T + lettersJump to the position before the first appearance of the letter,3taJump to the position before the third occurrence of the letter A
  8. F and T are capitalized to move in the opposite direction.Dt + lettersIndicates all contents before the letter is deleted.

The lines

  1. <start position><command><end position>Such as0y$, from the beginning of the line to the end of the line,yeCopy from the current position to the end of the word.
  2. <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

  1. Comment multiple lines:

  2. V: Enter the visual state

  3. Nj: Select n lines down, or type Shift] to skip to the end of the segment

  4. Command + / adds a comment

  5. In MacVim, git blame is crystal clear:

Chrome

  1. Command + lFocus moves to the address bar
  2. Shift + Option + Delete/LeftDelete/select a word left (can be customized asCtrl-w)
  3. Command + ySearch history
  4. The Command + digitalQuick TAB switch
  5. Command + shift + []Left and right TAB
  6. Command + t/wCreate/close a TAB
  7. Command + e/gSearch selected, go to next, or useCommand + fAnd press enter.

As you can see, operations involving tabs in Chrome should be as consistent as possible with Xcode.

iTerm2

  1. Ctrl wDelete the previous word
  2. Command + rClear the contents of the screen
  3. Command + t/wOpen/close TAB
  4. The Command + digitalLet’s go to the NTH TAB
  5. Double click on theSelect 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.