前言
作為一個研究僧,一直有記筆記的習慣烤礁,之前在用OneNote讼积,后來因為要開發(fā)ROS,徹底放棄了Windows陣營,在Mac和linux下來回切換脚仔,好在倆系統(tǒng)通用bash勤众,考慮到兼容性、輕量性鲤脏、以及最重要的優(yōu)(zhuang)雅(bi)性就嘗試著用vim寫Markdown來記筆記(我已經(jīng)隱忍OneNote很久了:臃腫们颜,占系統(tǒng)資源大,默認字體bug不修復凑兰,時不時來個閃退掌桩。我只想優(yōu)雅高效地記筆記而已边锁,OneNote的功能我80%都用不到)姑食。Mac下我還是以xcode自帶的編輯器為主,如果后期要看筆記的話茅坛,通過vim來預覽(主要是看大量代碼音半,其實xcode自帶編輯器基本能滿足查看需求),linxu下還是通過vim來編輯和預覽贡蓖。
BOM
-
Xcode:自帶的編輯器編寫markdown文檔肥腸好用曹鸠。雖然不能完全的預覽,但是已經(jīng)進行了一些處理斥铺,比如標題大小會自動調(diào)整彻桃,也有語法的高亮,自帶的目錄也能快速的定位晾蜘,還有是Mojave系統(tǒng)的暗黑主題邻眷,蘋果自家的軟件優(yōu)先適配,非常舒服剔交。
Xcode編輯器效果圖 vim:基本所有的UNIX like 系統(tǒng)都自帶肆饶,在終端輸入vim 就可以進去vim模式
vundle:一個管理vim插件的管理器, 以下所有的插件都是用vundle來管理安裝和卸載。
vim-instant-markdown:一個在瀏覽器中預覽markdown文檔的vim插件
vim-markdown:vim的 markdown語法高亮插件
安裝vundle
- 用下面的指令把vundle安裝在~/.vim/bundle/ 目錄下
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
- 在~/.vimrc 中添加一下的代碼
看到這么多代碼不用慌岖常,其實就是告訴你在指定的地方加上例如:“Plugin 'VundleVim/Vundle.vim“驯镊,來安裝你需要的vim插件,文末會貼上我自己的vimrc竭鞍,復制粘貼就可以板惑。
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
- 安裝插件
在vim的命令行模式下輸入:PluginInstall,就會自動安裝vundle偎快,以下的vim插件都是通過vundle安裝的洒放。
安裝vim-instant-markdown
安裝vim-instant-markdown插件首先要安裝node.js。
- 安裝 node.js
- Mac 去官網(wǎng)安裝 node.js,下載完成后是一個pkg文件滨砍,雙擊安裝完成往湿。測試是否安裝完成如果顯示版本號則表示成功了妖异。
終端輸入
node -v
npm -v
- linux下安裝node.js
sudo apt-get install nodejs
sudo apt-get install npm
- npm安裝instant-markdown-d
sudo npm -g install instant-markdown-d
- vim下安裝instant-markdown-d插件
其實就是在vimrc中添加下面的語句,大家可以復制文末的vimrc 然后用:PluginInstall一并安裝所有的插件领追。
Plugin 'suan/vim-instant-markdown'
兩個重要參數(shù)
接下來介紹兩個比較常用的設(shè)置參數(shù)他膳,更多參數(shù)詳見github主頁
- g:instant_markdown_slow
這個參數(shù)決定了你寫的markdown會不會實時地在瀏覽器上更新預覽(實時預覽可能會占用一些計算機性能)。如果你不希望實時預覽在 ~/.vimrc中設(shè)置 g:instant_markdown_slow = 1绒窑。一旦設(shè)置之后這個預覽更新只會在你停止輸入一段時間后生效棕孙,以及離開vim編輯模式之后生效。 - g:instant_markdown_autostart
顧名思義些膨,這個是決定你打開vim的同時蟀俊,會不會自動在瀏覽器上開啟預覽。如果你不希望自動開啟預覽订雾,那么就在~/.vimrc設(shè)置:g:instant_markdown_autostart = 0肢预。如果你手動開啟預覽,則在vim命令模式下輸入:InstantMarkdownPreview(我們當然可以用vim的鍵值映射來替換掉這個復雜輸入洼哎,比如我就替換成了F1)
安裝vim-markdown
本人在mac下用xcode 作為markdown的主要編輯器烫映,只把vim作為預覽查看器。但是考慮到vim的通用性噩峦,在linux下還是要用vim來寫锭沟。所以順帶也把語法高亮的插件也安排了。安裝過程也是用vundle安裝:
Plugin 'godlygeek/tabular'
Plugin 'plasticboy/vim-markdown'
vimrc
下面是我的vimrc配置识补,主要包含了vundle所需的一些插件族淮,以及vim的一些實用配置:顯示行號,配色凭涂。我默認markdown的預覽不自動開啟祝辣,通過F1來啟動。同時為了降低計算機負擔把實時預覽關(guān)了导盅。復制到~/.vimrc 后在vim中輸入:PluginInstall就會自動安裝所有的插件较幌。
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" alternatively, pass a path where Vundle should install plugins
"let path = '~/some/path/here'
"call vundle#rc(path)
" let Vundle manage Vundle, required
Plugin 'gmarik/vundle'
Plugin 'godlygeek/tabular'
Plugin 'plasticboy/vim-markdown'
Plugin 'suan/vim-instant-markdown'
" The following are examples of different formats supported.
" Keep Plugin commands between here and filetype plugin indent on.
" scripts on GitHub repos
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
" scripts from http://vim-scripts.org/vim/scripts.html
" git repos on your local machine (i.e. when working on your own plugin)
" ...
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - list configured plugins
" :PluginInstall(!) - install (update) plugins
" :PluginSearch(!) foo - search (or refresh cache first) for foo
" :PluginClean(!) - confirm (or auto-approve) removal of unused plugins
"
" see :h vundle for more details or wiki for FAQ
" NOTE: comments after Plugin commands are not allowed.
" Put your stuff after this line
syntax enable
syntax on
set autoindent
set nu
set tabstop=4
" 總是顯示狀態(tài)欄
set laststatus=2
" 顯示光標當前位置
set ruler
" 高亮顯示當前行/列
set cursorline
" 高亮顯示搜索結(jié)果
hi Search term=standout cterm=bold ctermfg=7 ctermbg=1
let g:instant_markdown_slow = 1
let g:instant_markdown_autostart = 0
map <F1> :InstantMarkdownPreview<CR>
set nofoldenable
效果圖
-
vim配置完之后的效果
效果圖 -
瀏覽器預覽的效果
用瀏覽器可以保存成pdf離線查看
瀏覽器預覽圖