前言
作为一个研究僧,一直有记笔记的习惯,之前在用OneNote,后来因为要开发ROS,彻底放弃了Windows阵营,在Mac和linux下来回切换,好在俩系统通用bash,考虑到兼容性、轻量性、以及最重要的优(zhuang)雅(bi)性就尝试着用vim写Markdown来记笔记(我已经隐忍OneNote很久了:臃肿,占系统资源大,默认字体bug不修复,时不时来个闪退。我只想优雅高效地记笔记而已,OneNote的功能我80%都用不到)。Mac下我还是以xcode自带的编辑器为主,如果后期要看笔记的话,通过vim来预览(主要是看大量代码,其实xcode自带编辑器基本能满足查看需求),linxu下还是通过vim来编辑和预览。
BOM
Xcode:自带的编辑器编写markdown文档肥肠好用。虽然不能完全的预览,但是已经进行了一些处理,比如标题大小会自动调整,也有语法的高亮,自带的目录也能快速的定位,还有是Mojave系统的暗黑主题,苹果自家的软件优先适配,非常舒服。
Xcode编辑器效果图
vim:基本所有的UNIX like 系统都自带,在终端输入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 去官网安装 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'
两个重要参数
接下来介绍两个比较常用的设置参数,更多参数详见github主页
g:instant_markdown_slow
这个参数决定了你写的markdown会不会实时地在浏览器上更新预览(实时预览可能会占用一些计算机性能)。如果你不希望实时预览在 ~/.vimrc中设置 g:instant_markdown_slow = 1。一旦设置之后这个预览更新只会在你停止输入一段时间后生效,以及离开vim编辑模式之后生效。
g:instant_markdown_autostart
顾名思义,这个是决定你打开vim的同时,会不会自动在浏览器上开启预览。如果你不希望自动开启预览,那么就在~/.vimrc设置: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来启动。同时为了降低计算机负担把实时预览关了。复制到~/.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
" 总是显示状态栏
set laststatus=2
" 显示光标当前位置
set ruler
" 高亮显示当前行/列
set cursorline
" 高亮显示搜索结果
hi Search term=standout cterm=bold ctermfg=7 ctermbg=1
let g:instant_markdown_slow = 1
let g:instant_markdown_autostart = 0
map :InstantMarkdownPreview
set nofoldenable
效果图
vim配置完之后的效果
效果图
浏览器预览的效果
用浏览器可以保存成pdf离线查看
浏览器预览图