2011年11月19日星期六

Vim 捣鼓笔记 1

昨天晚上终于下定决心要开始用 vim 了,于是开始学习,在这里记录一些东西备忘。

一些命令:
  • Vim 的各种文件路径可通过命令 :ver 来找到。
  • 用户向导 :vimtutor
  • h j k l 就不用再说是什么作用了。
  • 常用复制命令:
    yy 复制整行。或大写一个 Y。
    2yy 复制两行,y2y 也可以。
    y^ 复制至行首,或 y0。不含光标所在处字符。
    y$ 复制至行尾。含光标所在处字符。
    yw 复制一个 word。
    y2w 复制两个字。
    yG 复制至档尾。
    y1G 复制至档首。
    p 贴至光标后(下)。
    P 贴至光标前(上)。
    "ayy 将本行文字覆盖到 a 缓冲区。大写 A 则为添加到 a 缓冲区。
    "ap 将 a 缓冲区的内容贴上。
    5"ayy 复制五行内容至 a 缓冲区(覆盖)。
  • 打开文件时自动改变工作路径到当前文件的路径:在 ~/.vimrc 文件中加入 set autochdir 即可[1]
目前用 vim 来干的事情主要是用 LaTeX 写我的数学作业。这需要 LaTeX 的插件。我使用的是 VIM-LaTeX.

安装:
  1. 把下载的压缩包里的文件解压到 ~/.vim 中;
  2. 修改 ~/.vimrc 文件,在下面添加:

    " REQUIRED. This makes vim invoke Latex-Suite when you open a tex file. filetype plugin on " IMPORTANT: win32 users will need to have 'shellslash' set so that latex " can be called correctly. set shellslash " IMPORTANT: grep will sometimes skip displaying the file name if you " search in a singe file. This will confuse Latex-Suite. Set your grep " program to always generate a file-name. set grepprg=grep\ -nH\ $* " OPTIONAL: This enables automatic indentation as you type. filetype indent on " OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to " 'plaintex' instead of 'tex', which results in vim-latex not being loaded. " The following changes the default filetype back to 'tex': let g:tex_flavor='latex'

  3. 新建文件 ~/.vim/ftplugin/tex.vim 如下:

    " this is mostly a matter of taste. but LaTeX looks good with just a bit " of indentation. set sw=2 " TIP: if you write your \label's as \label{fig:something}, then if you " type in \ref{fig: and press you will automatically cycle through " all the figure labels. Very useful! set iskeyword+=:

  4. 安装帮助文件,命令:helptags ~/.vim/doc
这就安装完成了,接下来就是使用了。这里有在线的用户手册,不懂的时候要多看。

大概就是这样了。希望可以早日脱离鼠标。

[1]更新于 11-11-19 22:42:28

没有评论:

发表评论