Useful keybinding
Buffer and window
- SPC f s Save a buffer
- SPC f S Save all opened buffers
- SPC f f Open the buffer in now directory
- SPC f r Open the buffer and search in recently files
- SPC b b Open or switch a buffer with helm
- SPC b d Delete a buffer
- SPC b K Delete other buffer but this
- SPC w v/s split v or s
- SPC h/l/j/k switch window
Help and search
- SPC h d f 对一个功能提示并显示其文档。
- SPC h d k 对一个快捷键提示并显示其绑定的内容。
- SPC h d v 对一个变量提示并显示其文档和当前值。
- SPC h SPC 搜索一个命令,功能,变量或接口,并显示其文档
- SPC f e * Search configuration
- SPC ? 列出所有快捷键。
- SPC : M-x 列出可执行的所有命令
Others
- SPC f e R Reload the init.el
- SPC T h Select a theme using a helm buffer
- SPC f/p t To toggle the Neotree buffer press (project)
- SPC h b Open the bookmark
- SPC h T evil-tutor-start
- SPC h l Resume the last helm buffers
- SPC s L Focus the last converted search buffer
- F3 In a helm buffer, convert a helm search buffer into a regular buffer
The Emacs Evil Tutor
LESSON 1
The cursor is moved using either the arrow keys or the hjkl keys. h (left) j (down) k (up) l (right)
To exit Emacs type:
:qa! to trash all changes. OR type: :wqa to save the changes. Ctrl + f Page Down Ctrl + b Page Up
0 Cursor to the beginging of the line $ Cursor to the end of the line
G Cursor to the last of the file nG Cursor to the n line of the file gg Cursor to the begin of the file, like 1G :[Enter] followed by a line number and moves to that line number. N[Enter] Curosr to the N line
NOTE: Pressing
LESSON 2
x/X To delete a character under/before the cursor in normal state type
To delete a whole line type: dd
The format for a command in normal state is:
[number] command object OR command [number] object where: number - is how many times to repeat the command command - is what to do, such as d for delete object - is what the command should act upon, such as w for word, $ for “to the end of line”, etc.
d1G, dG, d0, d$
yy Copy the line of cursokr nyy Copy the n line data
y1G, yG, y0, y$
p/P Paste the data from the next/before line
To undo previous actions, type: u To undo the undo’s type: CTRL-R Repeat the last opeartion: .
LESSON 3
To replace text that has already been deleted, type p this puts the deleted text AFTER the cursor (if a line was deleted it will go on the line below the cursor).
To replace the character under the cursor, type r and then the character which will replace the original.
The change command allows you to change the specified object from the cursor to the end of the object. eg. Type cw to change from the cursor to the end of the word, c$ to change to the end of a line.
The format for change is: [number] c object OR c [number] object
LESSON 4
Typing / followed by a phrase searches FORWARD for the phrase. Typing ? followed by a phrase searches BACKWARD for the phrase. After a search type n to find the next occurrence in the same direction or N to search in the opposite direction.
Typing % while the cursor is on a (,),[,],{, or } locates its matching pair.
To substitute new for the first old on a line type :s/old/new To substitute new for all ‘old’s on a line type :s/old/new/g To substitute phrases between two line #’s type :#,#s/old/new/g To substitute all occurrences in the file type :%s/old/new/g To ask for confirmation each time add ‘c’ :%s/old/new/gc
LESSON 5
:!command executes an external command.
Some useful examples are: :!ls or :!dir - shows a directory listing. :!rm or :!del FILENAME - removes file FILENAME.
:w FILENAME writes the current buffer to disk with file name FILENAME.
:#,#w FILENAME saves the lines # through # in file FILENAME.
:r FILENAME retrieves disk file FILENAME and inserts it into the current buffer following the cursor position.
LESSON 6
Typing o opens a line BELOW the cursor and places the cursor on the open line in insert state. Typing a capital O opens the line ABOVE the line the cursor is on.
Type an a to insert text AFTER the character the cursor is on. Typing a capital A automatically appends text to the end of the line.
i/I Insert text at the character/Not blank
Tips
Not understand: 12.1.4 Additional text objects 12.3.3 Helm micro-state 12.7 Searching
Spacemacs Rocks
Spacemacs Rocks Season 2 ( Day one)
Install Emacs
- Mac
- Windows
- Linux(apt get install emacs)
Go over the Emacs tutorial at least once
- C-h t to open the tutorial.
- You need be familiar with cursor movement(C-f/C-b/C-n/C-p/C-a/C-e) and basic editing (C-k)
- You should be familiar with M(eta), s(uper, command key), S(hift), C(trl) M-x s-p S-p C-p
- Prefix key(c-h is a prefix key) and C-g (C-x c-f)
Learn to active some built-in functionality (org-mode)
- linum-mode to display line numbers (M-x linum-mode)
- C-x C-f(find/file) to open files, C-x C-s(ave) to save files. (You could also use your mouse to do all the file operations.)
- you should always ask Emacs the right question
- C-h k/ C-h v / C-h f (Emacs is a self document, extensiable editor.)
- The key bindings are actually a quick way to command Emacs.
Learn some elisp(emacs lisp)
- use learnxinyminutes website to learn emacs lisp.
- at least you know how to define variable, functions
- You should know how to make a function callable and how to set a key binding for the function.
Start to hacking Emacs from the day one!
- turn off tool-bar
- turn off scroll-bar
- show linum-mode
- turn off splash screen
- save your config
- define a function to quickly open your config file.
Emacs package system in the first glance.
- How to use the built-in Package system of Emacs.
- Install company mode and active it.
- Major mode and minor mode (C-h m)
- Happy hacking. :)
Bonus(org-mode basics)
3rd level
- use * to define headings
- C-c C-t to toggle TODO states
GTD(getting things done)* Day1 C-h t help model
Spacemacs Rocks Season 2 ( Day two )
Fixes some annoying stuff
make cursor style to bar
disable backup file
|
|
use C-’ to open another buffer to edit source code. Make source code fancy in the org file.
|
|
- enable recentf-mode
|
|
bring electric-indent-mode back
add delete selection mode
|
|
Make Emacs more fancy
- Open with full screen
|
|
- show match parents
|
|
It has a flaw, we will use more powerful package in the future.
- Highlight current line (global-hl-line-mode)
|
|
Improve built-in package system
- make package system more powerful with Melpa
|
|
- install a theme (monokai)
- install hungry delete mode
- package-list-packages (add/delete/update packages)
- install and configure smex and ivy mode
- use customize-group to customize the package settings
- install and configure smartparens mode
- Don’t try to update the package daily, the updating process might failed.
(tips: press M-RET to fix the order, you could also use M-RET to add new headings, cheers!)
Setup a javascript IDE
- Install js2-mode and start to write javascript
- Install nodejs-repl to execute code inside Emacs
Learn more from Emacs itself
- c-h c-f(find-function), c-h c-v(find-variable), c-h c-k(find-function-on-key)
- Tell users to learn more about elisp(M-x info)
Org-mode(Bonus Time)
Agenda files and agenda view
- one gtd.org file
|
|
Learn how to schedule items and set deadline
- c-c c-s to schedule item
- c-c c-d to set deadline of item.
Excercise
the difference between .emacs and .emacs.d/init.el file
try to configure company mode via customize-group
Spacemacs Rocks Season 2 ( Day three )
Split your configs into multiple files
use Git to management your init file
help window is anoyying..
|
|
- load-file, load-path and load
- features, provide and require, autoload
- naming conventions
zilongshanren/xxxx minor mode or major mode. niubi-mode niubi-xxx
all of the names should have a prefix, such that the naming conflicts could be minimal.
- define your abbrevs
|
|
- how to organize your configs
- init-packages.el
- init-ui.el
- init-better-defaults.el
- init-keybindings.el
- custom.el
|
|
- use `counsel-git` to find file in git managed project.
|
|
Major mode and minor mode in details
- conventions
text-mode/special-mode/prog-mode naming: xxx-mode, xxx-mode-key-map xxx-mode-hook
mode key map and mode hook
let’s take a look at a pacakge in elpa (company)
Better Defaults
- disable audio bell
|
|
- auto revert file when they are changed outside the editor
|
|
Exercise
- Only turn on Linum-mode when doing programming (tips: use prog-mode-hook)
Spacemacs Rocks Season 2 (Day 4)
Talk more about load, load-file, require, provide and auto-load
Better defaults
- Indent-region or buffer
|
|
- another way to complete things in Emacs.
|
|
Dired mode and file related operations
- copy, delete and rename file
Copy/Delete/Rname files and folders
+: to create directory C-x C-f: to create file g: to refersh dired buffer C: copy file d: delete file D: delete after confirm R: rename files
|
|
add new file and folder
for adding new folders,
C-x C-f to create a new file.
- open dired of current buffer
|
|
after applying this setting, we could press `C-x C-j` to jump to the dired buffer of current file.
- open finder on Mac. (optional)
Packages:
reveal-in-osx-finder for openning the finder of the current file.
Bonus Time. Use Org-mode literate programming to organize your Emacs configurations.
|
|
Exercise
- define C-x C-e in Js2-mode to eval js expression after node-repl mode is actived.
Spacemacs Rocks Season 2 (Day 5)
Fix smartparen quote issue
|
|
Editing large web page
|
|
Add more useful packages for web development
web-mode
toggle indent in web-mode
|
|
js2-refactor
- extract method
- extract function
occur and imenu
- improve occur
|
|
- improve imenu
|
|
expand-region and iedit mode
Bonus Time. Org export
export to html, you could also export to pdf
C-x C-e
Exercises
- Learn how to use emmet-mode to do zen coding: https://github.com/smihica/emmet-mode
- configure your system to export org file to pdf file
- install multiple cursor mode and compare it with iedit mode
Spacemacs Rocks Season 2 (Day 6)
Bonus Time: Org-mdoe
Use org-capture to take notes
|
|
Further reading: http://orgmode.org/manual/Capture.html
Install Org pomodoro to track my time
clean up configs
- move keybindings into one place
- make c-n and c-p to select company condicate
Batch rename files
- press `C-x C-q` in dired mode
- use expand-region and iedit to batch change files
search and replace
install helm-ag
- at first, you should install ag
search speed: ag > pt > ack > grep
|
|
Show javascript errors with flycheck
- flycheck-checkers
- eslint
Snippets and auto snippet
exercises
- give `helm-swoop` package a try: https://github.com/ShingoFukuyama/helm-swoop
- Give `org-mac-link` package a try: http://melpa.org/#/org-mac-link
Spacemacs Rocks Season 2 (Day 7)
Tweak C-w to delete backward
Evil (It’s not Baidu!) Turn Emacs into Vim in one second
install Evil plugin
tell the different between Evil and Vim Universal args
Evil state = Vim mode
evil normal state evil insert state evil visual state evil motion state evil emacs state evil operator state (diw)
configure Evil leader key
press `C-z` to toggle between Normal and Emacs state ??
Made some modes to use emacs-state
|
|
- binding h/j/k/l key
|
|
Add this to Dired mode, ibuffer mode?
Which key
Design your own key bindings
- Use SPC as the leader key
- Use comma as the major mode leader key
- Use SPC : to list all available commands
- Use which key to group key bindings
- Yeah! You got a minimal Spacemacs!
Bonus Time: Search Org notes
References
http://juanjoalvarez.net/es/detail/2014/sep/19/vim-emacsevil-chaotic-migration-guide/
http://nathantypanski.com/blog/2014-08-03-a-vim-like-emacs-config.html
http://blog.aaronbieber.com/2015/05/24/from-vim-to-emacs-in-fourteen-days.html
http://blog.jakubarnold.cz/2014/06/23/evil-mode-how-to-switch-from-vim-to-emacs.html
Exercises
- Install hydra and begin to add your own hydras!
Spacemacs Rocks Season 2 (Day 8)
elpa mirros
Cask and pallet
You can’t start different versions of Emacs with the single config
Troubleshootings
- Emacs 24.5: Dependency flycheck failed to install: Package `let-alist-1.0.4’ is unavailable
- define-advice is not defined for Emacs 24.5
|
|
Spacemacs Rocks Season 2 (Day 9)
Topic: Macro and Use-package
What is macro?
Code which generate code?
|
|
|
|
Write macro is almost the same as writing function in elisp.
What’s the different betwwen function and macro?
Evaluation: the macro arguments are the actual expressions appearing in the macro call.
Expansion: the value returned by the macro body is an alternate Lisp expression, also known as the expansion of the macro
examples:
back quote matters.
|
|
|
|
Why Macro?
A more useful example of Elisp macro
|
|
Use-package and basic usage
a more safe require
group config into one place
autoload and bind keys easily
make your config load faster
and more? Spacemacs use it a lot.
Bonus Time
- pretty print the lisp Object
(pp (macroexpand ‘(use-package company-mode)))
- fuck your brain?
|
|
more discussion: https://emacs-china.org/t/lisp/357
Reference
Readme more about macro: https://www.gnu.org/software/emacs/manual/html%5Fnode/elisp/Macros.html#Macros
Spacemacs Rocks Season 2 (Day 10)
Topic: Company-mode and auto-completion Cask and macro/use-package
Fix previous issues
|
|
How company-mode works?
- backend for the completion sources and front end to display the candidates
- C-h v company-backends
- try company-file and company-ispell, M-x
- C-h C-f to view the backend implementation
Why my company sucks?
- Python anaconda-mode not works
- some backend require build with a server-client architecture: company-anaconda, company-jedi, company-ycmd, company-tern etc
- At first, you should make sure the server side is working properly and then you want to make sure you use the right backend
- how to fix anaconda on Mac
Group backend
Write a Simple company backend
http://sixty-north.com/blog/writing-the-simplest-emacs-company-mode-backend
reference
- http://sixty-north.com/blog/series/how-to-write-company-mode-backends
- https://www.emacswiki.org/emacs/CompanyMode
ACUTEX 编译 PATH 配置
spacemacs does not use PATH from nix-shell · Issue #2294 · syl20bnr/spacemacs Spacemacs 默认用 exec-path-from-shell,屏蔽了 PATH 路径,因此将其去除即可
|
|