Use Vim (Note for vimbook-OPL.pdf)

Learn use vim as my main text editor
總體上感覺:
看到10章之後,速度慢慢就上去了,可能是自己慢慢熟悉命令了。
這個Note僅僅是我在練習時順便整理的。

The Tutorial

Get start

    I just think vim is a very good productivity tools.

    Did you think so?

    尝试使用中文,感觉这个输入法的速度都变快了,有没有?

    字体比较小,怎样把字体变大呢?(cmd=)

    背景也能不能设置为黑色的呢?(GUI 下 theme=evening)

    都需要自己探索,学习。

1.Vim:Commands

Moving Around

    hjkl Move cursor ### Deleting Characters
    x: Delete charcter under score your cursor ### Changing modals
    esc: Change modal
    i	inserts a character before the character under the cursor
    v: Visual modal (Select multi lines text) ### Undo and Redo
    u: Undo

    U: Undo line

    Ctrl r twice: Undoes the undo

Getting Out

    ZZ: Writes files and exits 保存并关闭文件

    :q!	quit-and-throw-things-away 退出不保存

    :w	写入文件不退出

    :q	退出

Other Editing Commands

    a	insert text after the cursor
    dd	delete a line
    o	a new line below the cursor,then enter insert mode.
    O	a new line above the cursor,then enter insert mode.
    :help	display help

    some text enclosed in vertical bars (etc: |tutor),then press
    ctrl ]	Jump to tag(Jump to the location of the tag given by the word under the cursor)
    ctrl t	pop tag(Back to the location of the tag)

    get help in NORMAL mode on subject

    etc.
    :help x
    :help deleting
    :help ctrl-a
    :help ctrl-h


    get help in INSERT mode on subject
    prefix key i_

    :help i_ctrl-h

    special key such as Arrow key
    :help <Up>	get help on <Up> arrow key
    other help prefix key , see note

    **Using a Count to Edit Faster**
    If you want to type aaaaaaaaa
    you can
	    9ia<Esc> 	then it will insert aaaaaaaaa
    or
	    9aa<Esc>	append aaaaaaaaa to after the cursor 

    If you want move up 10 lines
    you can
	    10k
    to move down 10 lines
	    10j
    to move cursor left 5 characters
	    5h
    to move cursor right 5 characters
	    5l

2.Editing a Little Faster

Word Movement

    w	forward 1 word
    b	backward 1 word
    3w	forward 3 words
    4b	backward 4 words

Moving to the Start or End of a line

    $	move to the end of line
    ^	move to the begin of line
    2$	move to the end of 2 line
    0	move to the begin of line

Searching Along a Single Line

    fx	forward search single character x
    Fx	backward search single character x
    2fx	twice search single character x
    tx	cursor stop in searched character x begin
    Tx	cursor stop in searched character x after

Moving to a Specific Line

    gg	Go to file start
    G	Go to file end	

Telling Where Are in a File

    :set number	display line number
    :set nonumber	display line number off

Where am I?

    ctrl+g	display a status line that indicates where you are in the file.	

Scrolling Up and Down

    ctrl+u	scroll up half a screen
    ctrl+d	scroll down half a screen

Deleting Text

    dw	delete a word
    dd	delete one line
    d2w	delete two word
    d3d	delete three line
    d$	delete from cursor to end of line
    d0 or d^	delete from cursor to begin of line
    3d2w	delete 2 words repeat 3 times for a  total of 6 words

Chaging Text

    cw	change a word
    c3w	change 3 words
    cc	change a line

Joining Lines

    J	join the current line with the next one
    3J	join 3 lines to one line

Replacing Characters

    rx	replaces the character under the cursor with x
    5ra	replaces the character under the cursor with aaaaa

Changin Case

    ~	change the character under the cursor with lowercase or uppercase

Keyboard Macros

    q character command records keystrokes into the register named character. (The char-
    acter must be between a and z.)
    ---
    qa	Start recording a macro in register a.
    ^	Move to the beginning of the line.
    i#define<Esc>	Insert the string #define at the beginning of the line.
    j	go to next line
    q	Stop recording the macro.
    ---
    @a	use macro
    10@a	use macro 10 times

3.Searching

Simple Searches

    /string		search string	if you want to search forward use /<Enter>
    /<Up>or<Down>	use history search string

Searching Options

Highlighting

    :set hlsearch	set highlighting search
    :set nohlsearch 	no highlighting search
    :nohlsearch	clear the current highlighting

Incremental Searches

    :set incsearch
    :set noincsearch
    n	next matched string ### Searching Backward
    ?string		search string backward
    n	last matched string

Changing Direction

    n	normal next matched string
    N reverse search between ? and /

Basic Regular Expressions

The Beginning(^) and End ($) of a line

    /str$	search line end with str 
    /^str	search line begin with str 

Match Any Single Character(.)

    etc.
    /a.p	apple	adplus result will show like left words

Regular Expression Summary

    x	The literal character x
    ^	Start of line
    $	End of line
    .	A single character
    character	Turns off the special meaning of many characters, gives special meaning to a few others

4. Text Blocks and Multiple Files

Cut,Paste and Copy

    Use p (put) command
    dd -> p  You can delete a line ,then put into your cursor in what line you want
    d$ -> p	 You can delete from cursor to end of line , then put into where you want to put under your cursor
    d2w -> p delete 2 words then put to another place

Character Twiddling

    etc.
    if you want to type 'the' then you type 'teh' you can put your cursor on 'e' then
    xp	x->delete the character p-> paste character after the cursor

More on “Putting”

    p	places the text after the cursor
    P	places the text before the cursor
    3p	paste 3 times

Marks

    :marks Display all marks
    ma	make a mark named a
    mb	make a mark named b
    `a	jump to mark a
    `b	jump to mark b
    d'a	from cursor delete mark a content

Yanking

    yank (Most other editors call copy operation)
    yy yank a line then use p to paste
    3y	yank 3 lines

Which File Am I On?

    :args

Edit multi files

    you can use vim to open a.txt b.txt
    vim a.txt b.txt
    then
    :next	Next file
    :previous	Previous file
    :wnext	Write then go to next file
    :wprevious	Write then go to previous file
    :rewind		Edit first file
    :last	Edit last file
    ctrl+^(6)	switch to alternate file (You can use :next to jump other file then two files are alternate)

5.Windows

Opening a New Window

    :split	split to up/down two window
    ctrl+w w	move cursor to alternate window
    ctrl+w j	move cursor to down window
    ctrl+w k	move cursor to up window

Opening Another Window with Another File

    :split file	etc. :split YQRealLink.m
    :split +/str file	search str and open file	etc. :split +/define YQRealLink.m	search define in YQRealLink.m
    :20 split file	Open file set window size 20 rows

Split Summary

    :count split +command file
    count	The size of window
    +command	An initial command
    file	The name of file to edit(You can use autocompleted to fix filename)

The :new Command

    open a new window without content of file(This is a new file)

Changing Window Size

    ctrl-w+		etc. ctrl+w 10 + increase 10 rows to current window
    ctrl-w-		etc. ctrl+w 20 - decrease 20 rows to current window
    .	Repeat last command	
    ctrl-w=		etc. ctrl+w =	make all window size equal
    (count)ctrl-w_		makes current window (count) lines high

Buffers

    :buffers	show current buffer list
    stats explain
    - Inactive
    h Hidden
    % Current
    # Alternate buffer
    + File has been modified

Selecting a Buffer

    :buffer number	etc. :buffer 2	Select second buffer file
    or
    :buffer file	etc. :buffer file2.txt
    :sbuffer number(or file)	splits the window and starts editing the buffer
    Annotations: P51	Other buffer-related commands

6.Basic Visual Mode

Entering Visual Mode(v)

    :help v_d	describes what the d command does in visual mode
    v	visual block
    V	visual line
    You can use <Esc> to leave all mode ### Editing with Visual Mode
    d	delete highlighted text
    D	delete highlighted line
    y	places the highlighted text into a register
    Y	places the highlighted line into a register
    c	change text
    C	change line
    J	join all the highlighted lines into one long line
    If you want to join the lines without adding spaces,use the
    gJ command

Indent

    <	shiftwidth(shift tab)
    >	width(tab)
    =	indents the text
    ctrl ]	jump to definition of the function highlighted
    K	man highlighted text ### Visual Block Mode
    :help v_b_r	get help on the visual block r command
    ctrl-v	Enter visual block mode
    then
    I	insert after blocked text
    and you can use hjkl to select block
    c	delete string then insert on each line in the block
    C	delete the character from cursor to end of line then insert new text to block
    $	extend block to the end of line
    A	add text to the end of each line #### Replacing
    r	applies all the selected characters with a single character #### Shifting
    >	right tab
    <	left tab	
    one
    two
    three

7. Commands for Programmers

Syntax Coloring

    :syntax on #### Syntax Coloring Problems
    :set background?	get current background setting
    :set background=light	set background to light
    :set background=dark	set background to dark
    :set filetype=c(Or java )	tell Vim types of syntax highlighting to use
    :set shiftwidth=4	change the size of the shift width ### Automatic Indentation
    set: cindent
    set: smartindent
    set: autoindent

    to set all open c,cpp file use cindent to .vimrc file
    :filetype on
    :autocmd FileType c,cpp :set cindent


    = using Vim's internal formatting program

Locating Items in a Program

    [ctrl-i,]ctrl-i		

8. Basic Abbreviations,Keyboard Mapping,and Initialization Files

Abbreviations

    :abbreviate ad advertisement	when you type ad<space> or <tab> then will appear advertisement

    see all abbreviate use
    :abbreviate

    see you vimrc file
    :version

    write all your settings to a file
    :mkvimrc file

    My .vimrc is locate on ~/.vimrc

9.Basic Command-Mode Commands

    :	Enter command line mode 
    :p(rint)	Just print current line text
    :1,5 print	Print 1-5 lines content
    :5 print	Print fifth line text
    :1,$ print	Print all content
    ma	mark selected content to a
    :'a print	print a mark content
    :shell	Enter shell mode (As Terminal) type exit to back to vim

10.Basic GUI Usage

11.Dealling with Text Files

Automatic Text Wrapping

Text Formatting Command

    :range center width 	etc.	:1,5 center 30	to center a range of lines(width default is 80)
    :range right width
    :range left margin

The formatoptions Option

    :set formatoptions=cq
    c	Automatically wrap comment. Insert the comment leader automatically.
    q	Allow gq to format comments. #### File Formats
    :set fileformats=unix,dos	set file fromat to unix,dos
    :set fileformat?	see current file format
    :set fileformat=unix	set file format to unix #### Changing How the Last Line Ends
    :set endofline	Last line ends in <EOL>
    :set noendofline	Last line does not have an <EOL> #### Troff-Related Movement
    )	moves forward one sentence
    (	backward sentence	
    }	moves forward one paragraph (most as one blank line as division)
    {	backward paragraph ### Section Moving
    [[	move a section backward
    ]]	move a section forward

12.Automatic Completion

    ctrl-p	backward search word to complete
    Many options you can customize in advanced chapter
    ctrl-n	forward search word to complete ### Customization of Completion
    :set ignorecase		tells the editor to tray all words regardless of case ### Specifying a Dictionary
    :set dictionary=file,file,...
    etc.
    single dictionary
    :set dictionary=/Users/yaqinking/Documents/dict/anime_dic.txt
    multi dictionary
    :set dictionary=/usr/dict/words,/usr/doc/words
    !You can specify your input method dict to you vim dict to auto complete your type exp.

Line mode

    ctrl-x ctrl-l	line completion ### Adjusting the screen
    ctrl-x ctrl-y	scroll up one line
    ctrl-x ctrl-e	scroll down one line

14.File Recovery and Command-Line Arguments

    :set backup	open backup
    :set backupext=string	add extension type to backup file
    etc.
    :set backupext=.bak
    It will be backup to file.txt.bak

    :set nobackup	close backup
    :set backupdir=~/tmp/

    $vim -r file
    recovery file from swap file
    :swapname	show what swap file your current use
    If you don't want to use swap file (Default swap file is on :set swapfile)
    :set noswapfile

Controlling When the Swap File Is Writen

    :set updatetime=23000	23seconds(milliseconds)
    :set updatecount=400	the number of character 400 you typed it will be writen to swap file

15.Miscellaneous Commands

    ga(or :ascii)	prints the number of the chracter under the cursor.
    5gg(or 5G)	go to 5 line
    30gg(or 30G)	go to 30 line
    ctrl-l		Screen Redraw
    z10	resize current window to 10 lines
    :intro		View introductory flash screen

16.Cookbook

Chracter Twiddling

    teh->the	xp ### Replacing One Word with Another Using One Command
    If you want to replace Oreimou to Oreimou Radio,
    If Oreimou line are 100-110,

    :100,110s/Oreimou/Oreimou Radio/g

    :100,110	100 line to 110 line
    s	:substitute
    Oreimou		old word
    Oreimou Radio	new word
    g	global change

    If you want to change all use	1,$
    1	first line
    $	last line

Interactively Replacing One Word With Another

    1.	/Radio<Enter>	Search
    2.	cw<Esc>	change word
    3.	n	next word Radio
    4.	cw<Esc>	change word
    5.	repeat 3-4

Moving Text

    If you want to moving some line
    1.	V	select line
    2.	ma	mark as a
    3.	move cursor to where you want put line
    4.	d'a	delete marked a content(Put it to pasteboard)
    5.	p	paste to cursor current line

Moving paragraph

    1.	V	select start line
    2.	ma	mark as a
    3.	}	move to paragraph end
    4.	mb	mark as b
    5.	move cursor to where you want put line
    6.	:'a,'b move .		move

Copying a Block of Text from One File to Another

    0.	:split file	split window
    1.	V	select line (etc. select 2 lines) then
    2.	2y	yank 2lines text
    3.	ctrl-w-w(or ctrl-w-p)	switch to another window
    4.	p	paste

    or

    1.	ma	mark as a
    2.	y'a	yank 'a
    3.	ctrl-w-w	switch to another window
    4.	p	paste ### Drawing Comment Boxes
    put into .vimrc
    :ab #b /****************************************
    :ab #e <Space>****************************************/
    When you want to type #b just type #bb then delete second b it will not expanded.

    Another better option use external program like boxes(see http://www.vim.org)

Oops, I Left the File Write-Protected

    :w filename	save to another file

17.Topics Not Covered

File Encoding

    :set fe=encoding	set file encoding
    :set fe=twiwan(or prc)	traditional Chinese (or Simplified Chinese)
    :set fileencoding=encoding	long format
    :set fe=japan		Japanese Ecoding

The Details

18.Complete Basic Editing

    e	move to end of a word
    ge	backward move to end of a word
    3ge	3 backward move to endo af a word

    ^	move to first non-black character on the line
    0	move to beginning of the line

Repeating Single-Chracter Searches

    fx	searches fo the first x (to repeat search use ;	 to reverse use , )

Moving Lines up and down

    -	moves up to the first non-blank character line
    =	moves down ### Jumping Around
    <count>-	move <count> up line
    <count>G	go to <count> line

    ctrl-o	Jump to previous location
    <TAB>	Jump to next location ### Where Am I,in Detail
    ctrl-g	Display summary information at the bottom of the screen	
    1ctrl-g	add path to show
    2ctrl-g	add buffer to show
    gctrl-g	another tpe of status information

Scrolling Up

    ctrl-u	scrolls up half a screen
    :set scroll=10	set ctrl-u commands scrolls up number
    2ctrl-u	scrolls up 2 line
    5ctrl-y	scrolls up 5 line
    ctrl-b	scrolls up an entire screen

Scrolling Down

    ctrl-d	move down The amount is controlled by the 'scroll' option

    ctrl-e	move down one line

    ctrl-f	move down one screen of data (also <PageDown> or <S-Down> Shift-ArrowDown)

Define How Much to Scroll

    :set scrolljump=5 ### Delete to the End of the Line
    <count>D	delete line (or <count> amount lines)
    C	change line text current cursor to end of line then enter INSERT mode

    Mmmm, basic command has d and d two forms, and you can add <count> to dozens do.
    Usally,d -> delete current word or character D -> delete cursor to end of line
    3d -> delete 3 lines

    a	append at begin line
    A	append at end of line
    gi	insert at begin line (same as a)

Arithmetic

    ctrl-a	increase number
    ctrl-x	decrease number

Jpining Lines with Spaces

    J	join the current line with the next one
    gJ	join line without spaces
    3gJ	join 3 line without spaces

Replace Mode

    r	replace a chracter
    R	enter replace mode

Chaning Case

    <count>~	change a chracter case
    <count>g~	change current line and next line text case
    <count>g~~	change line case

    <count>gUU	change entire line case

19.Advanced Searching Using Regular Expressions

Searching Options

Case Sensitivity

    :set ignorecase		turn on ignorecase
    :set noignorecase	turn off	
    :set smartcase		WORD will be matches WORD

Instant Word Searches

    *	search under cursor word
    g*	go to searched words under cursor word
    g#	reverse

Search Offsets

    /nisekoi/2	go to searched nisekoi next 2 line position
    /nisekoi/b2(or s2 start)	moves the cursor to the beginning of the match
    /nisekoi/e	moves the cursor onto the last character of the match

家人 事故 保险 友人 自己 生活

昨天给老爸打电话要生活费,然后回答:先给你打1000,自己搞定下个月的生活费。我想,这肯定是家里又出什么事情了。

今早8点,老爸回过来电话,说了原因:开车碰到人了,要赔人家3-4W。就这个事情,开动脑筋,想下为什么会这样,以及我该怎么做。

家人 事故

家人会做什么事情,你是想不到的,然后做了的事情会产生什么后果,你也是想不到的,就开车碰到人这件事,会开车(可选),买车(可选),碰到了赔钱(必需,社会规则),因为赔钱,所以自己要赚钱,或者向友人借钱还(必需)。
这次是3-4W,按照老爸以往的挣钱记录,每个月能超过 4k 的可能性不大,然后减去家里3个人,外面我1个人的生活费,家里3人1800,我800,共2600,剩1400,显然每个月还人家1400肯定不够,So,把我的削掉600(剩200,然后我自己想办法先顶着),还人家2000,然后还是感觉很少。
先问友人借,然后自己每个月还友人。
这是个不错的方法,假设,可以用这种方法把 4w 碰到人的费用搞定,然后就是自己想办法搞定友人的4w。
同样假设老爸每个月还1600(我生活费还原到600),每年大概能还1.9w,也就是要还2年多,当然,这是理想情况,现实是:我老爸不可能一个月赚4k,然后还人家1.6k。
想到这里,后面的再想对我来说意义已经不大了,因为我改变不了事实,我只能改变未来。

保险 友人

谁再说保险没用,我…
不是说你每次做事之前不用上保险,因为你感觉自己会能出什么事情。然后,事实是你可能出什么事情,并且可能性和你不出事概率是一样的(出事,不出事,5 5开,就像成功和失败的概率是5 5开,你只能通过增加自己成功的概率来成功一样,并且就算你增加了成功的概率,还有其他一大堆因素可能造成你失败)。So,在做事之前,把最坏的情况想出来还是很有必要的。
而友人是你最大的保险。

我 生活

既然改变不了过去,那就去改变自己的未来。
你不能断定家里人的生活风平浪静,但是你可以让自己的生活过的更加有意义,然后你可以去影响别人的生活。
Talk is cheap ,show me your code.
写代码去。

写于 2015-03-21-8:56 午前

WWDC 14 Session 237 a strategy for great work

/

当你看到一些东西的时候,在你脑中应该会出现一个 idea,然后作出一个 Demo 去尝试实现它。

不要尝试去完全解决当前遇到的问题,别忘了当初自己是要干什么。

遇到的每一个问题都有一个解决的途径,重要的是怎样去发现这条路的 poi(将问题抽象化)。

去找聪明的朋友听听它们的意见。

这个 Session 简直就是在讲 iPhone 的虚拟键盘到底是怎样来的 poi

解决方案应该能够说明自己在解决什么问题。(用户最好已经知道怎么用)

去用简单优雅的方法解决这个问题。(因为我能够理解简单的东西)

/

Did you mean this one ? Did you mean that one ? Did you mean the another one ? Did you mean this one ? Did you mean…

选择可能管用的最简单的解决方案(最简单的通常解决速度是最快的)。

/
/
/

iPad Keyboard

/

原型最高!

/

Only show your best work(Don’t show people your second-best work)

展示你最棒的作品就好(别让人家看你的次 ~~二~~ 品)

/

这就是苹果软件质量下降的答案?

/

讲的内容的摘要的poi

博客迁移到 Github

静态站点不折腾

不需要管数据库,不必管 WordPress 漏洞,自己可以写主题

开始前的注意事项

  1. 说是用 Github Pages 生成漂亮的网页,其实官方文档说了,Github Pages 是用来生成展示项目的静态网页。
  2. 说是用 Jekyll 来生成站点,其实 Jekyll 是用来本地观看自己博客的效果的(Github 自己会选择用是用 Github Pages 还是 Jekyll 生成你的网站)

步骤:

  1. 创建一个 yourusername.github.io的 Repo

    很重要,必须是 yourusername.github.io 这个 Repo,只有这个 Repo Github 才会给你用 Jekyll 生成。官方原文
    我会给你说,我先是尝试用各种 Repo 命名的地址,搞了几个小时都没搞出效果,然后还是看官方文档才知道,原来 Repo 命名必须是这样才可以。

  2. Down 一个 Jekyll 主题,写好一个样例的 Post

    当然,你可以自己写主题

  3. 推送本地文件到该 Repo,好了,观看效果吧

Git命令

git init

git add .

git commit -m First Post

git remote add origin https://github.com/youusername/yourusername.github.io

git push -u origin master


至于自己怎样折腾出来的,看教程啊,查官方 Help 啊,一个字就是

参考:

OS X 下使用 Mjolnir 来快速切换 App

效果
/

Mjolnir 官网

我看的教程

我的配置

快速配置:

  • 從官網下載安裝 Mjolnir
  • 安裝依賴(首先你需要安裝過 brew)
brew install lua
brew install luarocks

echo 'rocks_servers = { http://rocks.moonscript.org }' > ~/.luarocks/config.lua

luarocks install mjolnir.hotkey
luarocks install mjolnir.application
luarocks install mjolnir.bg.grid
luarocks install mjolnir.th.hints
luarocks install mjolnir.cmsj.appfinder
luarocks install mjolnir.tiling
luarocks install mjolnir.sd.grid
luarocks install mjolnir.lb.itunes
luarocks install mjolnir._asm.ui.sound

mkdir ~/.mjolnir/
  • 把我的配置文件放到 ~/.mjolnir/ 下(完成後是:~/.mjolnir/init.lua)

PS: ~ 代表用戶文件夾

此 App 可用来作为一个 Window Manager 用,不过我已经买了 Divvy 了,不想花时间配置,所以現在只用來切換應用,并且 OS X 这个系统,很多组合键都已经预先分配好了,自定義組合鍵很痛苦。