vim 使用、设置笔记

一、设置.vimrc( windows下通常为_vimrc)

1、设置vim中tab的缩进

  set ts=4  (注:ts是tabstop的缩写,设TAB宽4个空格)
  set expandtab (注:用4个空格代替一个TAB, 不设置的话就是一个宽为4的TAB)

 

二、插件

1、Vundle  插件安装器,http://github.com/VundleVim/Vundle.Vim

2、NERDTree  树形目录,https://github.com/scrooloose/nerdtree

3、NERDCommenter  注释插件,https://github.com/scrooloose/nerdcommenter

4、delimitMate  引号、括号等补全,https://github.com/Raimondi/delimitMate  

5、cppcomplete  c/c++代码补全,http://www.vim.org/scripts/script.php?script_id=527

6、taglist  符号列表插件,需同ctags生成的tags一起工作,https://github.com/vim-scripts/taglist.vim

7、AutoComplPop  补全时自动弹出窗口,https://github.com/vim-scripts/AutoComplPop

8、CtrlP  文件查找,https://github.com/kien/ctrlp.vim

9、EasyGrep  全局搜索,https://github.com/dkprice/vim-easygrep

 

三、使用

1、缩进

  < 或 >  注:一个向左缩进,一个向右缩进

  =    注:自动缩进(默认使用c-indenting或lisp函数来格式化)

  例子:gg=G (gg:回到文本首部,=:缩进, G:文本尾部, 整体意思,全文缩进)

  具体的使用看vim的手册, :help <  或 :help >  或 :help =

 

2、快速注释/反注释

  注释: ctrl + v 进入块可视化模式, 选择要注释行的第一个字符, I 进入向前插入模式,插入注释符号,如//, 此时再按一下Esc,即完成选中行的注释

  反注释: ctrl + v 进入块可视化模式,选择要删除的注释符,再 x,即可删除所有

  注:使用辅助插件,如:NERD_commenter

      参考文章:http://blog.csdn.net/xiajun07061225/article/details/8488210

 

3、设置窗口大小

  set lines=35 columns=118

  set lines=999 columns=999   "表示全屏

  vim中窗口宽用columns, 高用lines

  参考文章:http://lemoncyb.iteye.com/blog/1615983

 

4、gvim中设置配置方案

  colorscheme industry

  参考文章:http://lemoncyb.iteye.com/blog/1615983

 

5、gf 命令

  goto file

  Edit the file whose name is under or after the cursor.

    可以跳转到光标下的文件中,前提是这个文件在搜索路径path中

  详细请参考:help gf, help path

 

6、宏录制

  q{0-9a-zA-Z}    开始宏录制, help q 查看

      q   结束录制

      @{0-9a-zA-Z}   播放宏

  例子:

  比如要在以下3行字符串的后面分别加一个分号    

hello, one
hello, two
hello, three

  正常模式下输入 qa, (q表示开始录制, 存放的寄存器名为a)

  正常模式下输入 A (A表示在行尾追加)

  输入;

  正常模式下输入 j  (j表示光标移到下一行)

  q (结束录制)

  播放宏:光标移到第一行, 在正常模式下输入3@a 

 

7、多窗口大小的调整

  resize +2  "高度增加2,使用头号就减少2

  vertical resize +2  “宽度增加2,使用减号就减少2

  使用按键映射则可在配置文件中加入以下配置:

" 调整窗口大小
"nnoremap <C-7> <C-w>+
"nnoremap <C-8> <C-w>-
nnoremap <C-7> :resize +2<CR>
nnoremap <C-8> :resize -2<CR>
nnoremap <C-9> :vertical resize +2<CR>
nnoremap <C-0> :vertical resize -2<CR>

此时Ctrl+7: 表示高度加2,其它的类同

 

8、Session\View保存加载

  mksession 保存当前会话

  vim -S Session.vim 加载会话

 

  mkview 1 保存视图1

  :loadview 1 加载视图1

  

  具体的请看:help mksession 及help mkview

 

9、vim 设置编码

  set fileencodings=ucs-bom,utf-8,cp936
  set fileencoding=utf-8

  具体参见:http://www.cnblogs.com/jaiho/archive/2011/08/24/2056375.html

  或help fileencodings 查看相关说明

  

  

 

posted @ 2016-12-10 13:06  shanql  阅读(663)  评论(0)    收藏  举报