Sublime实用技巧(Win)

Alt + R : 开启正则表达式功能
Alt + Enter: 找到匹配目标后全部选择
Ctrl + R:前往 method(mac 下 ⌘ + R
Ctrl + M:跳转到对应括号
Ctrl + Shift + ↑/↓:与上/下一行交换位置

Ctrl + D:选择单词,重复可增加选择下一个相同的单词
Ctrl + L:选择行,重复可依次增加选择下一行

Ctrl + Shift + P:打开命令面板

Ctrl + P:搜索项目中的文件(mac 下 ⌘ + P),在里面输入:
admi@auto 可以定位到相应文件夹(admin.html)下的相应方法(auto)。

Ctrl + G:跳转到第几行
Ctrl + W:关闭当前打开文件
Ctrl + Shift + W:关闭所有打开文件
Ctrl + Shift + V:粘贴并格式化
Ctrl + Shift + L:选择多行
Ctrl + Shift + Enter:在当前行前插入新行
Ctrl + X:删除当前行
Ctrl + U:软撤销,撤销光标位置
Ctrl + Shift + J:选择标签内容
Ctrl + F:查找内容
Ctrl + Shift + F:查找并替换
Ctrl + H:替换
Ctrl + N:新建窗口
Ctrl + K + B:开关侧栏
Ctrl + Shift + M:选中当前括号内容,重复可选择括号本身
Ctrl + F2:设置/删除标记
Ctrl + /:注释当前行
Ctrl + Shift + /:当前位置(对选中内容)插入块注释
Ctrl + Alt + /:块注释,并 Focus 到首行,写注释说明用的
Ctrl + Shift + A:选择当前标签前后,修改标签用的
F11:全屏
Shift + F11:全屏免打扰模式,只编辑当前文件
Alt + F3:选择所有相同的词
Alt + .:闭合标签
Alt + Shift + 数字:分屏显示
Alt + 数字:切换到第 N 个文件
Shift + 右键拖动:上下拖动设置多个光标位并在多行选中相同长度内容,用来更改或插入列内容
鼠标的前进后退键:可切换 Tab 文件
Ctrl + 左键点击:选择多个位置
Ctrl + shift + D: 复制并粘贴光标所在行
Ctrl + shift + T: 恢复已经关闭的标签页

Editing

Keypress Command

Ctrl + X Delete line
Ctrl + ↩ Insert line after
Ctrl + ⇧ + ↩ Insert line before
Ctrl + ⇧ + ↑ Move line/selection up
Ctrl + ⇧ + ↓ Move line/selection down
Ctrl + L Select line - Repeat to select next lines
Ctrl + D Select word - Repeat select others occurrences
Ctrl + M Jump to closing parentheses Repeat to jump to opening parentheses
Ctrl + ⇧ + M Select all contents of the current parentheses
Ctrl + KK Delete from cursor to end of line
Ctrl + K + ⌫ Delete from cursor to start of line
Ctrl + ] Indent current line(s)
Ctrl + [ Un-indent current line(s)
Ctrl + ⇧ + D Duplicate line(s)
Ctrl + J Join line below to the end of the current line
Ctrl + / Comment/un-comment current line
Ctrl + ⇧ + / Block comment current selection
Ctrl + Y Redo, or repeat last keyboard shortcut command
Ctrl + ⇧ + V Paste and indent correctly
Ctrl + Space Select next auto-complete suggestion
Ctrl + U soft undo; jumps to your last change before undoing change when repeated

Windows
Ctrl + Alt + Up Column selection up
Ctrl + Alt + Down Column selection down

Linux
Alt + ⇧ + Up Column selection up
Alt + ⇧ + Down Column selection up

Keypress Command

Ctrl + P Quick-open files by name
Ctrl + R Goto symbol
Ctrl + ; Goto word in current file
Ctrl + G Goto line in current file

General

Keypress Command

Ctrl + ⇧ + P Command prompt
Ctrl + KB Toggle side bar
Ctrl + ⇧ + Alt + P Show scope in status bar

Find/Replace

Keypress Command

Ctrl + F Find
Ctrl + H Replace
Ctrl + ⇧ + F Find in files

Tabs

Keypress Command

Ctrl + ⇧ + t Open last closed tab
Ctrl + PgUp Cycle up through tabs
Ctrl + PgDn Cycle down through tabs
Ctrl + ⇆ Find in files
Alt + [NUM] Switch to tab number [NUM] where [NUM] <= number of tabs

Split window

Keypress Command

Alt + ⇧ + 2 Split view into two columns
Alt + ⇧ + 1 Revert view to single column
Alt + ⇧ + 5 Set view to grid (4 groups)
Ctrl + [NUM] Jump to group where num is 1-4
Ctrl + ⇧ + [NUM] Move file to specified group where num is 1-4

Bookmarks

Keypress Command

Ctrl + F2 Toggle bookmark
F2 Next bookmark
⇧ + F2 Previous bookmark
Ctrl + ⇧ + F2 Clear bookmarks

Text manipulation

Keypress Command

Ctrl + KU Transform to Uppercase
Ctrl + KL Transform to Lowercase

Configure SublimeLinter-html-tidy

Ready Works:

  1. Install Sublime Text 3
  2. Install SublimeLinter
  3. Download tidy.zip from HTML Tidy for Windows
  4. Install SublimeLinter HTML Tidy

Step 2 and 4 install from Package Control: Install Package. Not introduce here.

Configure

  • 解压第3步下载的文件得到 tidy.exe,拷贝到目录C:/Users/Username/tidy,其它目录也可以。

  • 依次打开:Preferences > Package Settings > SublimeLinter > Settings

  • 下滑找到 paths 节点,如下:

    1
    2
    3
    4
    5
    6
    7
    {
    "paths": {
    "linux": [],
    "osx": [],
    "windows": []
    }
    }
  • 拷贝 tidy.exe 所在的目录到 windows 项:

    1
    2
    3
    4
    5
    6
    7
    {
    "paths": {
    "linux": [],
    "osx": [],
    "windows": ["~/tidy"]
    },
    }

    注意:路径 "~/tidy" 是相对用户目录的路径,即 C:/Users/Username,路径不包含 tidy.exe 程序本身。当然,用绝对路径其它目录也是可以的(如:d:/tidy)。

  • Done!!


阅读原文

Change Lanunchpad Icon Size

How to Adjust the Icon Grid Count of Launchpad in Mac OS X

replacing the X numbers for the appropriate columns and grid icon counts

1
defaults write com.apple.dock springboard-columns -int X;defaults write com.apple.dock springboard-rows -int X;defaults write com.apple.dock ResetLaunchPad -bool TRUE;killall Dock

For example, to set the Launchpad grid to 8 × 7 you’d use the following syntax:

1
defaults write com.apple.dock springboard-columns -int 7;defaults write com.apple.dock springboard-rows -int 8;defaults write com.apple.dock ResetLaunchPad -bool TRUE;killall Dock

If you want to return to the default setting, just change the column and row counts back to what yours was originally. The default on my MacBook Pro Retina display is a 5 x 7 grid, but yours may be different depending on screen size and screen resolution.

1
defaults write com.apple.dock springboard-columns -int 7;defaults write com.apple.dock springboard-rows -int 5;defaults write com.apple.dock ResetLaunchPad -bool TRUE;killall Dock

The commands for customizing the Launchpad layout can also be split apart if desired like so:

Set the Launchpad Column Icon Count

1
defaults write com.apple.dock springboard-columns -int 7

Set the Launchpad Row App Icon Count

1
defaults write com.apple.dock springboard-rows -int 8

Reset Launchpad

1
defaults write com.apple.dock ResetLaunchPad -bool TRUE;

Relaunch the Dock with killall

1
killall Dock

You can also choose to just set a custom row or just a custom column count, but you must reset and refresh the Launchpad, and finally killall Dock to relaunch the Dock in Mac OS X and have the changes to take effect regardless of how you customize it.

Multiple MySQL Versions with Homebrew

CONTENT

For homebrew version 2.1.2

1
brew -v # => Homebrew 2.1.2

Install the current version of mysql.

1
2
3
4
5
6
# Install current mysql version
brew install mysql

# Start agent for current version of mysql (including on login)
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Install the older version of mysql.

1
2
3
4
5
6
7
8
9
# Find older mysql versions
brew search mysql

# Install older mysql version
brew install mysql@5.6

# Start agent for older version of mysql (including on login)
ln -sfv /usr/local/opt/mysql@5.6/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql@5.6.plist

Then to switch to the older version.

1
2
3
4
5
6
7
8
9
10
# Unlink current mysql version
brew unlink mysql

# Check older mysql version
ls /usr/local/Cellar/mysql@5.6 # => 5.6.43

# Link the older version
brew switch mysql@5.6 5.6.43
# If the above didn't working, try this:
brew link mysql@5.6 --force

And to switch back to the current version.

1
2
3
4
5
6
7
8
# Unlink older mysql version
brew unlink mysql@5.6

# Check current mysql version
ls /usr/local/Cellar/mysql # => 8.0.16

# Link the current version
brew switch mysql 8.0.16

To verify which mysql version you’re on at any time.

1
2
3
4
5
# Check which version of mysql is currently symlinked
ls -l /usr/local/bin/mysql # => /usr/local/bin/mysql@ -> ../Cellar/mysql56/5.6.43/bin/mysql

# Or using the mysql command
mysql --version

And to unload a mysql agent for a given version.

1
2
3
4
5
6
7
# Stop agent for current version of mysql
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

# Stop agent for older version of mysql
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql@5.6.plist
rm ~/Library/LaunchAgents/homebrew.mxcl.mysql@5.6.plist

Caution

jpmelguizo:
Went with mysql@5.6 and I’m getting: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) Although brew services list says mysql@5.6 is started, there’s no mysqld process running and no mysql.sock file anywhere. Any ideas on how to fix it? should I just go with the deprecated mysql56 instead?

jsweeney:

(NOTICE: If you see \@, it is just @, remove the backslash(\) when you copy.)
I also had your problem. My issue was that the mysql@5.6 was trying to boot the mysql 5.7 database (installed in the default /usr/local/var folder). If you want to run both in parallel on their own distinct databases, there are a few more steps to do.

  1. Create a new (separate) data directory and database for the 5.6 version
    Run /usr/local/Cellar/mysql\@5.6/5.6.36/bin/mysql_install_db --user=root --datadir=/usr/local/var/mysql56
  2. Change the configuration to start the 5.6 version pointing to this database
    Edit /usr/local/Cellar/mysql\@5.6/5.6.36/homebrew.mxcl.mysql\@5.6.plist to change both /usr/local/var/mysql instances to /usr/local/var/mysql56 (I didn’t put the @ in the folder name just in case it would cause issues).
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    <plist version="1.0">
    <dict>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>homebrew.mxcl.mysql@5.6</string>
    <key>ProgramArguments</key>
    <array>
    <string>/usr/local/opt/mysql@5.6/bin/mysqld_safe</string>
    <string>--bind-address=127.0.0.1</string>
    <string>--datadir=/usr/local/var/mysql56</string> <!-- <<<<<<<<<<<<<<<<<< HERE -->
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>WorkingDirectory</key>
    <string>/usr/local/var/mysql56</string> <!-- <<<<<<<<<<<<<<<<<< AND HERE -->
    </dict>
    </plist>
  3. Change the port of the 5.6 server - if ever you want to start both at the same time.
    Edit /usr/local/Cellar/mysql\@5.6/5.6.36/my.cnf, uncomment port and change it to some other value than 3306.
    1
    2
    3
    4
    5
    6
    # These are commonly set, remove the # and set as required.
    # basedir = .....
    # datadir = .....
    port = 3356
    # server_id = .....
    # socket = .....
    NOTE A little caveat about connecting to the MySQL instances after such a setup. Using any kind of driver will > work out of the box if you set the correct port. However, at the command line, mysql ignores the --port > value by default, so you need something like this>
    1
    mysql -uroot --port=3356 --protocol=TCP
    See this article for more details: https://dev.mysql.com/doc/refman/5.7/en/connecting.html

mysql_downgrade:

1
2
3
4
5
6
7
8
9
10
11
12
13
# Kill rails server and guard
bin/spring stop
brew services stop mysql
brew uninstall mysql
brew install mysql@5.5
brew link mysql@5.5 --force
brew services start mysql@5.5
rbenv uninstall 2.3.3
rbenv install 2.3.3
gem install bundle
gem install rubocop-rspec rubocop scss_lint rails_best_practices # (optional)
bundle install
be rails db:migrate:reset

via:
from: https://gist.github.com/benlinton/d24471729ed6c2ace731
mysql_downgrade: https://gist.github.com/6temes/3c52f8a472f61d9676e7218a98812286

Linux文本流

文本流

在计算机中,所谓的数据就是0或1的二进制序列,但严格来说,Unix以字节(byte)来作为数据的单位,也就是说这个序列每八位(bit)为一个单位。八位的二进制数字,会落在十进制从0到255的范围内。利用ASCII编码,可以把这一个字节转换成为256个字符中的一个。所以,在Unix中,数据完全可以用字符的形式表示出来,也就是所谓的文本(text)。

实际上,如果以位为单位的话,机器会更容易读懂和传输。但Unix系统坚持用字节为单位来表示数据。原因在于,相对于以位为单位的二进制数据,以字节为单位文本直接就人类可读(human readable)。这样的话,无论是计算机配置信息,还是别人写的一首诗,用户都可以直接读懂。当然,并不是所有的数据都是设计来让人读懂的。很多编译好的可执行文件中包含的内容,只有机器能读懂。打开这个文件,尽管也能看到一个个字符,但这些字符并不能组成什么有意义的文本。但Unix系统不会给这种“读不懂”的文件开后门。所有文件都是统一的形式,就能以相同的方法存储,也能共用一套处理工具,从而减少程序开发的难度。

存储文本的文件,就相当于一个个存储数据的房子。在Unix的设计哲学中,一向有“万物皆文件”(Everything is a file)的说法。大部分的文件都对应了存储设备,也就是树莓派的SD卡上的信息。就连表示文件位置的目录,也是一种文件。此外,程序的配置信息,也都存储在文件中。对于Unix系统来说,文件可以广义的认为是可以提供或接收数据的对象。既然这样,Unix系统干脆把提供或接收数据的硬件也表示成文件。这其中,既有外部连接的USB设备,也包括树莓派内部的内存等硬件。在/dev目录下,就可以找到很多这样代表硬件的文件。

但托瓦兹对“万物皆文件”的说法作出过纠正,改为“万物皆文本流”(Everything is a stream of bytes)。系统运行时,数据并不是在一个文件里定居。数据会在CPU的指挥下不断地流动,就好像一个勤劳的上班族。有时数据需要到办公室上班,因此被读入到内存,有时会去酒店休假,传送到外部设备。有的时候,数据需要搬个家,转移到另一个文件。在这样跑来跑去的过程中,数据像是排着队走路的人流,我们叫它文本流(text stream,或者byte stream)。然而,计算机不同设备之间的连接方法差异很大,从内存到文件的连接像是爬山,从内存到外设像是游过一条河。为此,Unix定义了流 (stream),作为连接操作系统各处的公路标准。有了“流”,无论是从内存到外设,还是从内存到文件,所有的数据公路都是相同的格式。至于公路下面是石头还是土地,就都交给操作系统处理,不劳用户操心。

(说句题外话,如果看过骇客帝国的话,一定会对文本流印象深刻。)

骇客帝国

标准输入,标准输出,标准错误与重新定向

当Unix执行一个程序的时候,会自动打开三个流,标准输入(standard input),标准输出(standard output),标准错误(standard error)。比如说你打开命令行的时候,默认情况下,命令行的标准输入连接到键盘,标准输出和标准错误都连接到屏幕。对于一个程序来说,尽管它总会打开这三个流,但它会根据需要使用,并不是一定要使用。

想象一下敲击一个

1
$ls

键盘敲击的文本流(“ls\n”,\n是回车时输入的字符,表示换行)命令行 (命令行实际上也是一个程序)。命令行随后调用/bin/ls得到结果(“a.txt”),最后这个输出的文本流(“a.txt”)流到屏幕,显示出来,比如说:

1
a.txt

假设说我们不想让文本流流到屏幕,而是流到另一个文件,我们可以采用重新定向(redirect)的机制。

1
$ls > a.txt

重新定向标准输出。这里的>就是提醒命令行,让它知道我现在想变换文本流的方向了,我们不让标准输出输出到屏幕,而是要到a.txt这个文件 (好像火车轨道换轨)。此时,计算机会新建一个a.txt的文件,并将命令行的标准输出指向这个文件。

有另一个符号:

1
$ls >> a.txt

这里>>的作用也是重新定向标准输出。如果a.txt已经存在的话,ls产生的文本流会附加在a.txt的结尾,而不会像>那样每次都新建a.txt

我们下面介绍命令echo

1
$echo IamVamei

echo 的作用是将文本流导向标准输出。在这里,echo的作用就是将IamVamei输出到屏幕上。如果是

1
$echo IamVamei > a.txt

a.txt中就会有IamVamei这个文本。

我们也可以用<符号来改变标准输入。比如cat命令,它可以从标准输入读入文本流,并输出到标准输出:

1
$cat < a.txt

我们将cat标准输入指向a.txt,文本会从文件流到cat,然后再输出到屏幕上。当然,我们还可以同时重新定向标准输出:

1
$cat < a.txt > b.txt

这样,a.txt的内容就复制到了b.txt中。

我们还可以使用>&来同时重新定向标准输出和标准错误。假设我们并没有一个目录void。那么

1
$cd void > a.txt

会在屏幕上返回错误信息。因为此时标准错误依然指向屏幕。当我们使用:

1
$cd void >& a.txt

错误信息被导向a.txt。

如果只想重新定向标准错误,可以使用2>:

1
$cd void 2> a.txt > b.txt

标准错误对应的总是2号,所以有以上写法。标准错误输出到a.txt,标准输出输出到b.txt。

管道 (pipe)

理解了以上的内容之后,管道的概念就易如反掌。管道可以将一个命令的输出导向另一个命令的输入,从而让两个(或者更多命令)像流水线一样连续工作,不断地处理文本流。在命令行中,我们用|表示管道:

1
$cat < a.txt | wc

wc命令代表word count,用于统计文本中的以及字符的总数。a.txt中的文本先流到cat,然后从cat的标准输出流到wc的标准输入,从而让wc知道自己要处理的是a.txt这个字符串。

Linux的各个命令实际上高度专业化,并尽量相互独立。每一个都只专注于一个小的功能。但通过pipe,我们可以将这些功能合在一起,实现一些复杂的目的。

总结

文本流,标准输入,标准输出,标准错误

1
2
3
cat, echo, wc

>, >>, <, |

reference:
http://www.cnblogs.com/vamei/archive/2012/09/14/2683756.html

Mac中安装配置Python2、Python3及自由切换

安装Python2

Mac系统已经默认带有Python2.7了,所以无需安装它。

1
2
3
which python
# 输出如下:
# /usr/bin/python

安装Python3

1
2
3
4
5
6
# 安装 python3
brew install python3

which python3
# 输出如下:
# /usr/local/bin/python3

不同版本Python路径

1
2
/System/Library/Frameworks/Python.framework/Versions/2.7  # 系统默认
/usr/local/Cellar/python # brew安装

配置Python2 和Python3

  1. 指定对应路径,控制台输入:vi ~/.zshrc
    按一下键盘 I 键,变成可编辑状态后,在末尾加上如下内容:

    1
    2
    3
    4
    5
    # Setting PATH for Python 2.7
    PATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
    export PATH
    # Setting PATH for Python 3.7.2_2(修改为实际安装的版本号,下同)
    PATH="/usr/local/Cellar/python/3.7.2_2/bin:${PATH}"

    编辑完后,按 esc 退出编辑状态,然后输入 :wq 并回车,这样就保存了所修改的 ~/.zshrc 文件

  2. 添加alias(zsh 环境可以省略这一步),控制台输入:vi ~/.zshrc

    1
    2
    3
    alias python2='/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7'
    alias python3='/usr/local/Cellar/python/3.7.2_2/bin/python3.7'
    # alias python=python3
  3. 上述步骤的修改,虽然保存了,但是系统还没让其生效,所以我们需要source一下。控制台输入:source ~/.zshrc 然后按回车键。最后关闭终端,重新打开,即生效。

  4. 输入对应的命令,即可自由选择使用对应的Python版本。

    1
    2
    3
    4
    5
    $ python # (或者 python2),进入python2 环境
    Python 2.7.10 (default, Oct 6 2017, 22:29:07)
    [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    1
    2
    3
    4
    5
    $ python3 # 进入python3 环境
    Python 3.7.2 (default, Feb 12 2019, 08:16:38)
    [Clang 10.0.0 (clang-1000.11.45.5)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
  5. 退出Python控制台

    1
    2
    3
    4
    5
    6
    7
    8
    # 方法 1:
    quit()

    # 方法 2:
    exit()

    # 方法 3:
    ctrl + D

epub电子书制作杂录

工具准备:Calibre,Calibre 中文轉換插件 TradSimpChinese

编辑书籍/Edit Book 简介

打开 Calibre,软件右上角工具栏中即可找到编辑书籍/Edit Book

  • 左侧:文件浏览,双击任何一个文件可在中间区域查看文件源码或图片
  • 右侧:文件预览区,查看html页面预览效果

让 ibooks 支持内置字体

第一步,修改 content.opf 文件,新增一行:<meta property="ibooks:specified-fonts">true</meta>

第二步,创建xml文件: com.apple.ibooks.display-options.xml,内容如下:

1
2
3
4
5
<display_options>
<platform name="*"> <!-- allowed values for platform "iphone", "ipad", or "*" for all -->
<option name="specified-fonts">true</option> <!-- must be set to "true" for embedded fonts -->
</platform>
</display_options>

第三步,点击 calibre 中的 编辑书籍/Edit Book 打开 Edit Book 工具,点击 新增文件/New File

  • 在弹窗中输入 meta-inf/com.apple.ibooks.display-options.xml
  • 点击 导入文件(图片/字体等)/Import resource file,定位到第二步创建的xml文件选择打开,点 确定 后xml文件就添加好了。

第四步,点击 工具栏 中的 管理字体(TTF) > 安装字体,添加字体后可通过重命名更改字体路径:Fonts/FontName.ttf

第五步,在样式表中添加内置字体:

1
2
3
4
@font-face {
font-family: "FontName"; /* FontName 可设定为任意名字 */
src: url(../Path/FontName.ttf); /* 注意将 Path 和 FontName 修改为你创建的路径名和字体名称 */
}

竖排,从右向左翻页

第一步,修改 content.opf 文件,新增一行:<meta content="vertical-rl" name="primary-writing-mode"/>

第二步,修改 content.opf 文件, 给 spine 标签增加一属性:page-progression-direction=”rtl”

第三步,修改样式表,为 body 增加一属性: writing-mode: vertical-rl;

有时需要局部横排显示,例如图片的说明文字可以横排显示在图片下方,可为说明文字单独设置css:writing-mode: horizontal-tb

添加弹注效果

flowing footnote

1
2
3
4
5
6
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
...
<p>
<a href="chapter.xhtml#myNote" epub:type="noteref">1</a>
</p>
<aside id="myNote" epub:type="footnote">Text in popup</aside>

注意,必须有这几个属性:

  • html 标签: xmlns:epub="http://www.idpf.org/2007/ops"
  • a (注释序号):epub:type="noteref"
  • aside (注释):epub:type="footnote"

aside 标签会自动隐藏,如果希望注释正常显示出来,可用 div/p 等标签替代。
ios 中为整屏弹注,多看等其它阅读器不支持这种方式。

繁体标点替换

  • 替换成
  • 替换成
  • 替换成
  • 替换成

修改语言

1
<dc:language>zh-Hans</dc:language>
  • 繁体zh-Hant
  • 大陆繁体:zh-Hant-CN
  • 香港繁体:zh-Hant-HK
  • 澳门繁体:zh-Hant-MO
  • 新加坡繁体:zh-Hant-SG
  • 台湾繁体:zh-Hant-TW
  • 简体zh-Hans
  • 大陆简体:zh-Hans-CN
  • 香港简体:zh-Hans-HK
  • 澳门简体:zh-Hans-MO
  • 新加坡简体:zh-Hans-SG
  • 台湾简体:zh-Hans-TW

body 样式设置参考

1
2
3
4
5
6
7
8
body {
margin: 5%;
text-align: justify;
writing-mode: vertical-rl;
-webkit-writing-mode:vertical-rl;
-epub-writing-mode: vertical-rl;
-epub-line-break: auto;
}

epub目录树结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
├── META-INF
│   ├── com.apple.ibooks.display-options.xml
│   └── container.xml
├── OEBPS
│   ├── Fonts
│   │   └── kangxidict.ttf
│   ├── Images
│   │   ├── Image00000.jpg
│   │   ├── Image00001.jpg
│   │   ├── ...
│   │   └── Image00200.jpg
│   ├── OEBPS
│   │   └── cover.jpg
│   ├── Styles
│   │   ├── flow0001.css
│   │   ├── flow0002.css
│   │   ├── ...
│   │   └── flow0005.css
│   ├── Text
│   │   ├── text00000.html
│   │   ├── text00001.html
│   │   ├── ...
│   │   └── text00090.html
│   ├── content.opf
│   └── toc.ncx
└── mimetype

reference:
http://guidohenkel.com/2015/04/custom-fonts-in-ibooks/ (Custom Fonts)
https://help.apple.com/itc/booksassetguide/en.lproj/static.html (Section:Pop-up Footnotes
https://bookfere.com/post/204.html

vim-replacement

vim批量替换命令

语法:

1
:[addr]s/源字符串/目的字符串/[option]

全局替换命令:

1
:%s/源字符串/目的字符串/g

源字符串可以用正则表达式,特殊变量需要转义(加\,比如: \(
目的字符串引用方式:

  • \0&:表达式匹配的全部文本;
  • \1:编号为 1 的捕获分组匹配的文本;
  • \2:编号为 1 的捕获分组匹配的文本;
  • \L:将之后的所有字符转换为小写;
  • \U:将之后的所有字符转换为大写;
  • \E\e\U\L 的作用结束;
  • \l:将此后一个字符转换为小写;
  • \u:将此后一个字符转换为大写。

参数说明:

[addr] 表示检索范围,省略时表示当前行。

  • 1,20:表示从第1行到20行;
  • %: 表示整个文件,同 1,$
  • . ,$:从当前行到文件尾;

s : 表示替换操作

[option] : 表示操作类型

  • g 表示全局替换;
  • c 表示进行确认
  • p 表示替代结果逐行显示(Ctrl + L恢复屏幕);
  • 省略option时仅对每行第一个匹配串进行替换;
  • 如果在源字符串和目的字符串中出现特殊字符,需要用 \ 转义 如 \t

例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#==================================================
#将That or this 换成 This or that
:%s/\(That\) or \(this\)/\u\2 or \l\1/

#==================================================
#将句尾的child换成children
:%s/child\([ ,.;!:?]\)/children\1/g

#==================================================
#将mgi/r/abox换成mgi/r/asquare
:g/mg\([ira]\)box/s//mg//my\1square/g <=> :g/mg[ira]box/s/box/square/g

#==================================================
#将多个空格换成一个空格
:%s/ */ /g

#==================================================
#使用空格替换句号或者冒号后面的一个或者多个空格
:%s/\([:.]\) */\1 /g

#==================================================
#删除所有空行
:g/^$/d

#==================================================
#删除所有的空白行和空行
:g/^[ ][ ]*$/d

#==================================================
#在每行的开始插入两个空白
:%s/^/> /

#==================================================
#在接下来的6行末尾加入.
:.,5/$/./

#==================================================
#颠倒文件的行序
:g/.*/m0O <=> :g/^/m0O

#==================================================
#寻找不是数字的开始行,并将其移到文件尾部
:g!/^[0-9]/m$ <=> g/^[^0-9]/m$

#==================================================
#将文件的第12到17行内容复制10词放到当前文件的尾部
:1,10g/^/12,17t$
#~~~~重复次数的作用

#==================================================
#将chapter开始行下面的第二行的内容写道begin文件中
:g/^chapter/.+2w>>begin

#==================================================
:/^part2/,/^part3/g/^chapter/.+2w>>begin

#==================================================
:/^part2/,/^part3/g/^chapter/.+2w>>begin|+t$

MAC下终端走代理的几种方法

方法1:

在终端中直接运行命令

1
export http_proxy=http://proxyAddress:port

这个办法的好处是简单直接,并且影响面很小(只对当前终端有效)。

方法2:

把代理服务器地址写入shell配置文件.bashrc或者.zshrc
直接在.bashrc或者.zshrc添加下面内容

1
2
export http_proxy="http://localhost:port"
export https_proxy="http://localhost:port"

以使用shadowsocks代理为例,ss的代理端口为1080,那么应该设置为

1
2
export http_proxy="http://127.0.0.1:1080"
export https_proxy="http://127.0.0.1:1080"

localhost就是一个域名,域名默认指向 127.0.0.1,两者是一样的。
然后 ESC:wq 保存文件,接着在终端中执行 source ~/.bashrc
或者退出当前终端再起一个终端。 这个办法的好处是把代理服务器永久保存了,下次就可以直接用了。

方法3:

改相应工具的配置,比如apt的配置

1
sudo vim /etc/apt/apt.conf

在文件末尾加入下面这行

1
Acquire::http::Proxy "http://proxyAddress:port"

保存apt.conf文件即可。关于apt的代理设置可以参考这里
关于git的代理设置看这里:用shadowsocks加速git clone

方法4:

利用proxychains在终端使用socks5代理

补充:

如果代理服务器需要登陆,这时可以直接把用户名和密码写进去

1
http_proxy=http://userName:password@proxyAddress:port

搜索引擎常用技巧

搜索入门

多个关键字

搜索结果要求包含两个及以上关键字,以空格分隔;

1
搜索引擎 历史

不包含特定关键字

搜索结果不包含某些特定资讯,用减号-操作;

1
2
搜索引擎 历史 -文化 -中国历史 -世界历史
// 注意:减号后面没有空格

或搜索

搜索结果至少包含多个关键字中的任意一个,用大写的OR操作;

1
2
搜索引擎 历史 archie OR 蜘蛛 OR lycos OR yahoo -文化
// 至少包含 [archie]、[蜘蛛]、[lycos]、[yahoo]中的一个,不包含[文化]

通配符

目前可以用*来代替单个字元,而且必须用英文的双引号””引起来;

1
“以*治国”

字母大小写不敏感

GODgod搜索的结果是一样的;

搜整个短语或句子

关键字可以是单词(中间没有空格),也可以是短语(中间有空格)。但是,用短语做关键字,必须加英文引号””,否则空格会被当作操作符。

1
“world war I”

忽略字元及强制搜索

搜索引擎忽略的字元以及强制搜索,如icomwww等,以及一些符号如*.等,作忽略处理。

1
2
www的历史 internet
// 搜索结果中不会有与[www]相关的结果

搜索引擎实际上把www的历史这个短语分成三部分:www历史,分别来检索,这就是搜索引擎的分词。所以尽管你输入了连续的www的历史,但搜索引擎还是把这个短语当成三个关键字分别检索。

要对忽略的关键字进行强制检索,可以用英文双引号””引起来:

1
2
“www的历史” internet
// 搜索结果中会有与[www]相关的结果

注意:大部分常用英文符号(如问号,句号,逗号等)无法成为搜索关键字,加强制也不行。

搜索进阶

特定网站

对搜索的网站进行限制——site:

1
2
3
4
5
// eg1:
搜索引擎 技巧 site:edu.cn

// eg2:
“search engine” tips site:www.zhihu.com OR site:www.douban.com

site表示搜索结果局限于某个具体网站或者网站频道,如http://www.zhihu.comedu.sina.com.cn,或者是某个顶级域名,如com.cncom等等。如果是要排除某网站或者顶级域名范围内的页面,只需用“–网站/顶级域名”。

注意:site:中的冒号后面不能有空格。

特定文档

在某一类档中查找资讯——filetype:

1
2
3
4
5
// eg1:
资产负债表 filetype:doc OR filetype:xls OR filetype:ppt

// eg2:
冰与火之歌 filetype:mkv OR filetype:mp4

filetype:是Google开发的非常强大实用的一个搜索语法。也就是说,Google不仅能搜索一般的文字页面,还能对某些二进位文档进行检索。

包含在URL链接中

搜索的关键字包含在URL链接中——inurl:allinurl:

1
2
3
4
5
// eg1:
inurl:mp3 “这个世界会好吗”

// eg2:
allinurl:”cgi-bin” phf +com

网页链接中包含第一个关键字mp3,第二个关键字这个世界会好吗出现在链接中或网页文档中。

allinurl返回的网页链接中包含所有关键字。

包含在网页标题中

搜索的关键字包含在网页标题中——intitle:allintitle:

intitle:allintitle:的用法类似于上面的inurlallinurl,只是后者对URL进行查询,而前者对网页的标题栏(即标签中的内容)进行查询。

1
2
3
4
5
// eg1:
intitle:重庆 “轨道交通”

// eg2:
allintitle:重庆 “轨道交通”

包含在网页锚点内

搜索的关键字包含在网页的“锚”(anchor)点内——inanchorallinanchor
用法与URL和TITLE类似。

链接到某URL的网页

搜索所有链接到某个URL位置的网页——link:

1
2
link:www.zhihu.com
// 搜索所有链接到http://www.zhihu.com的网页。

如果你拥有一个个人网站,想知道有多少人对你的网站做了链接,link:可以迅速达到这个目的。

link:不能与其他语法混合操作;另外,link只列出Google索引链接很小一部分,而非全部。

link的妙用:一般来说,做友情链接的网站都有相似的地方。这样,你可以通过友情链接,找到一大批具有相似内容的网站。

页面结构相似的页面

查找与某个页面结构内容相似的页面——related:

1
related:www.zhihu.com

从缓存页面查询

从Google伺服器上缓存页面中查询资讯——cache: