在 FreeBSD 里我们轻松对付英文

在 FreeBSD 里我们轻松对付英文

英语是世界语,但对那些母语非英语的人们,做到熟练的读写和交流往往需要长时间的学习。

FreeBSD 提供了一些 ports,帮助我们对付英文。它们是

chinese/stardict-dict-zh_CN (英汉和汉英辞典)
textproc/sdcv (命令行查辞典)
textproc/queequeg (英文语法检查)
aspell (英文拼写检查)
reciteword(背英文单词的工具,delphij老大维护的)

我不太推荐在FreeBSD环境安装机器翻译引擎,因为现在有很多的在线服务,如 google、百度、Yahoo(babel fish)等。

随着世界文化交流的日益频繁,跨语言交流早晚要成为主流,高质量的机器翻译服务必将成为竞争之地。

日本有公司为手机通讯提供机器翻译的后台服务,这边讲日文,那边出英文。我试过它们的产品,虽然翻译质量还很幼稚,但这种服务平台已经搭建起来,只待机器翻译的研究能跨上几个台阶达到实用水平。

用 aspell 检查单词拼写

如果你使用 bash,请在 .bashrc 里加入

alias spell="aspell –lang=en -c"

检查英文文本 sample.txt 里英文单词的拼写,只需

IOU@~$ spell sample.txt

vim 里对付英文

在 .vimrc 里加入下面的设置。在 vim 里,将光标放在欲查的英文单词上,键入 ctrl+\,则 sdcv 将查阅英汉辞典,给出中文解释。

set spell         "" highlight the typos
nmap <C-\> : !sdcv -n <C-R>=expand("<cword>")<CR><CR>

emacs 里对付英文

增加 emacs 的设置,

;;;;;;;;;;;;;;;;;;;;;;;;;;;                                                                                     
;; Automatic spell check ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq-default ispell-program-name "aspell")
(autoload ‘flyspell-mode "flyspell" "On-the-fly spelling checker." t)

用 qq 检查英文语法

在 FreeBSD 网站摘录一段话, FreeBSD® is an advanced operating system for modern server, desktop, and embedded computer platforms. FreeBSD’s code base has undergone over thirty years of continuous development, improvement, and optimization. It is developed and maintained by a large team of individuals. FreeBSD provides advanced networking, impressive security features, and world class performance and is used by some of the world’s busiest web sites and most pervasive embedded networking and storage devices.

将之存为 sample.txt,然后用 queequeg 工具(简称 qq)来检查这段英文的语法。qq 有彩色的显示,来标注可能的语法错误。

IOU@~$ qq -Wall sample.txt
— sample.txt
sample.txt:0: … system for (modern server) , desktop …
sample.txt:0: (FreeBSD) Â ® …
sample.txt:0: … advanced operating (system) for modern …
sample.txt:0: … server , (desktop) , and …
sample.txt:0: … has undergone (over thirty years) of continuous …
sample.txt:0: … years of (continuous development) , improvement …
sample.txt:0: (FreeBSD) ‘s code …
sample.txt:0: … development , (improvement) , and …
sample.txt:0: … , and (optimization) .
sample.txt:0: … sites and (most pervasive embedded networking) and storage …
sample.txt:0: … , and (world class performance) and is …
sample.txt:0: FreeBSD provides (advanced networking) , impressive …
sample.txt:0: (FreeBSD) provides advanced …

原文链接:http://wiki.freebsdchina.org/doc/e/english

FreeBSD下Vim的语法高亮与自动补全

FreeBSD下Vim的语法高亮与自动补全

vim 是与 emacs 齐名的超级编辑器(二者的使用哲学不同,没有高低贵贱之分)。我喜欢将 /usr/local/share/vim/vim73/colors/torte.vim 中的 ctermbg 设置为 NONE,这样 vim 就使用桌面背景显得“透明”(当然,这是假透明)。

vim 的功能十分强大,语法高亮和命令的自动补全更是不在话下。下面,我们逐一介绍它们。我们所用的 vim 版本在 7.0 以上。

语法高亮

下面,以矩阵计算工具 octave 和符号计算工具 maxima 为例,说明如何使编程语言在 vim 中语法高亮。

Octave 在 vim 中的语法高亮

我们怎么设置才能使得 vim 在编辑 foo.m 和 foo.oct 文件时做到语法高亮呢? 首先,找到文件 filetype.vim,打开它,看看后缀为 .m 和 .oct 是否被其他程序占用。 在我的 FreeBSD 中,.m 的后缀果真被 matlab 占用。matlab 没有 BSD 版本,我的机器上也没装 matlab 的 linux 版,所以干脆就把文件 filetype.vim 中的 matlab 替换为 octave。特别地,把 “*.oct” 加到 “*.m” 之后

" Octave or Objective C
au BufNewFile,BufRead *.m,*.oct         call s:FTm()

func! s:FTm()
  let n = 1
  while n < 10
    let line = getline(n)
    if line =~ ‘^\s*\(#\s*\(include\|import\)\>\|/\*\)’
      setf objc
      return
    endif
    if line =~ ‘^\s*%’
      setf octave
      return
    endif
    if line =~ ‘^\s*(\*’
      setf mma
      return
    endif
    let n = n + 1
  endwhile
  if exists("g:filetype_m")
    exe "setf " . g:filetype_m
  else
    setf octave
  endif
endfunc

把文件 octave.vim 拷贝到 syntax/matlab.vim 所在的目录。

maxima 在 vim 中的语法高亮

我希望所有后缀为 .mxm 的文件都被当做maxima文件语法高亮。

首先确保 maxima.vim 文件存在于 /usr/local/share/vim/vim72/syntax 目录下。编辑文件/usr/local/share/vim/vim72/filetype.vim,加入语句

" Maxima
au BufNewFile,BufRead *.mxm         setf maxima

命令的自动补全

到/usr/local/share/vim/vim72/autoload/目录下,看系统为哪些环境提供了命令的自动补全。也可以 locate ccomplete.vim,找到这个目录。

FreeBSD7.0下有ccomplete.vim、htmlcomplete.vim、……。然后,我们在 $HOME/.vimrc 中加入

"""""""""" 自动补全命令 """"""""""
autocmd Filetype c      set omnifunc=ccomplete#Complete
autocmd Filetype html   set omnifunc=htmlcomplete#CompleteTags
autocmd Filetype xml    set omnifunc=xmlcomplete#CompleteTags
autocmd Filetype python set omnifunc=pythoncomplete#CompleteTags
autocmd Filetype tex    set omnifunc=syntaxcomplete#Complete

.vimrc 的设置

$HOME/.vimrc 的普通设置,如下。

set nocompatible  "" not compatible with VI
set spell         "" highlight the typos
"" 在 vim 中查英文单词
nmap <C-\> : !sdcv -n <C-R>=expand("<cword>")<CR><CR>

"" Encodings and fonts
set encoding=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set langmenu=zh_CN.UTF-8
language messages zh_CN.UTF-8
set guifontset=wenquanyi,-*-16-*-*-*

"" Tab and Backspace
set sw=2
set tabstop=4
set shiftwidth=4
set cindent
set smartindent
set autoindent
set backspace=indent,eol,start  "" set backspace

"" Display
set number        "" show line number
set ruler         "" always show current position
set cursorline    "" highlight the current line
set showcmd

"" Searching
set ignorecase    "" search setting
set incsearch
set hlsearch
set showmatch
set history=100
highlight Search term=reverse ctermbg=4 ctermfg=7

"" Syntax and color scheme
syntax enable
filetype plugin indent on
highlight Comment ctermfg=darkcyan
colorscheme torte

"""""""""" 自动补全命令 """"""""""
autocmd Filetype c      set omnifunc=ccomplete#Complete
autocmd Filetype html   set omnifunc=htmlcomplete#CompleteTags
autocmd Filetype xml    set omnifunc=xmlcomplete#CompleteTags
autocmd Filetype python set omnifunc=pythoncomplete#CompleteTags
autocmd Filetype tex    set omnifunc=syntaxcomplete#Complete

原文链接:http://wiki.freebsdchina.org/software/v/vim