Skip to content

Instantly share code, notes, and snippets.

@yi
Created November 13, 2011 16:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yi/1362270 to your computer and use it in GitHub Desktop.
Save yi/1362270 to your computer and use it in GitHub Desktop.
VIM settings for JavaScript editing

VIM settings for JavaScript

VIM 用户环境

Windows

  • 配置文件: %HOMEPATH%/_vimrc
  • 插件目录: %HOMEPATH%/vimfiles/

代码自动缩进

命令: gg=G

JS 代码检查

安装

  1. install jslint http://www.javascriptlint.com/download.htm
  2. install vim script for jslint http://www.vim.org/scripts/script.php?script_id=2578

如何使用

jslint在每次保存文件的时候进行自动的代码检查

JS 代码中关键字列表

安装

  1. 安装 ctags 5.5 以上版本 http://ctags.sourceforge.net/
  2. 将 catgs 的可执行文件路径加入到系统 path 变量
  3. 安装 tagbar vim插件: http://www.vim.org/scripts/script.php?script_id=3465
  4. 如果(2)的设置不起作用,那么在 _vimrc 中显性定义 ctags 路径: let g:tagbar_ctags_bin = 'C:\ctags58\ctags.exe'
  5. 在 _vimrc 中定义 tagbar 的快捷键到F8:

nnoremap :TagbarToggle

如何使用

在使用 vim 编辑 js 文件时,按 F8 显示和隐藏文件中的 tags 列表

Better JS file indention

set up

  1. use better js syntax file: http://www.vim.org/scripts/script.php?script_id=1491
  2. enable auto indent in .vimrc

set cindent

set smartindent

set autoindent

set expandtab

set softtabstop=4

set shiftwidth=2

set cinkeys=0{,0},:,0#,!,!^F

将 VIM 的自动完成功能的快捷改成 Ctrl-Space

if has("gui")

" C-Space seems to work under gVim on both Linux and win32
inoremap <C-Space> <C-n>

else " no gui

if has("unix")

inoremap <Nul> <C-n>

else

" I have no idea of the name of Ctrl-Space elsewhere

endif

endif

@yi
Copy link
Author

yi commented Jan 13, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment