Vim 介绍

Vim 是什么?高度可定制的文本编辑器。

Vim 的配置

工欲善其事, 必先利其器.

插件

Vundle 管理插件,从而每个插件使用不同的目录,方便更新/删除等。

  • NerdTree
  • Taglist

YouCompleteMe 主要用于 C-family 语义补全:

g:ycm_global_ycm_extra_conf option
g:ycm_confirm_extra_conf option

其他配置

  • :set all # 查看所有配置

Tab 相关的配置

  • tabstop: Tab 等同的空格数目
  • expandtab: 使用空格代替制表符 Tab
  • retab!: 将已经存在的 Tab 转换为空格

缩进相关的配置

内置的缩进 C-indenting 的配置参考如下 链接

  • shiftwidth: 缩进时移动的空格长度
  • set cindent: 最佳选择

Vim 的使用

参考以下文章 简明 VIM 练级攻略, 是文章 Learn Vim Progressively 的翻译。 多说一句,Linux 命令家族中还有 sedawk 值得学习。下面是一些例子说明。

Remove ^M

Brief:

:%s/<Ctrl-V><Ctrl-M>//g

Detail:

The line terminator expected for each file format is:

  • unix LF only (each line ends with an LF character). Unix based systems and Mac OS X and later.
  • dos CRLF (each line ends with CR then LF). DOS and Windows.
  • mac CR only (each line ends with a CR character). Mac OS version 9 and earlier

  • CR is carriage return (return cursor to left margin), which is Ctrl-M or ^M or hex 0D.

  • LF is linefeed (move cursor down), which is Ctrl-J or ^J or hex 0A. Sometimes, LF is written as NL (newline).

Link: Change_end-of-line_format_for_dos-mac-unix

Acess system clipboard

使用 vim --version 查看当前 vim 支持的特性. 如果不支持 clipboard, 需要安装 vim-gnome or vim-gtk.

  • gg"+yG – copy the entire buffer into + (normal mode)
  • "*dd – cut the current line into * (normal mode)
  • "+p – paste from + after the cursor (works in both normal and visual modes)
  • :%y * – copy the entire buffer into * (this one is an ex command)

In general using + and * is much more reliable than using CTRL-SHIFT-V.

Link: Accessing the system clipboard