鉴于 window 下基本用不到 vim,所以下面内容不再提及 window,具体可以在相应 github 中查看手册
操作基础:已装有上有 nodejs(npm)。没装的可以移步官网:https://nodejs.org/en/
<!--善其事利其器(3) - -->
另有 sublime 配置方式,请移步:sublime配置及使用技巧

插件管理工具 pathogen

github地址: github

mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

插件

安装插件都在 ~/.vim/bundle/ 中安装,以下部分操作可能需要 root 权限

  • vim-sensible vim新人专属 github
cd ~/.vim/bundle/
git clone git://github.com/tpope/vim-sensible.git
cd ~/.vim/bundle/
git clone https://github.com/vim-airline/vim-airline-themes.git
cd ~/.vim/bundle/
git clone https://github.com/vim-airline/vim-airline-themes ~/.vim/bundle/vim-airline-themes
  • Emmet 快速建立html树 github
cd ~/.vim/bundle/
git clone https://github.com/mattn/emmet-vim.git
  • editorconfig 编辑器配置 github
cd ~/.vim/bundle/
git clone https://github.com/editorconfig/editorconfig-vim.git

新建文件 vim ~/.vim/.editconfig (可自定义,通常放在项目根目录),键入以下设置:

root = true

indent_style = space
indent_size = 2
tab_width = 2
end_of_line = lf
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
  • vim-multiple-cursors 支持多行编辑 github
cd ~/.vim/bundle/
git clone https://github.com/terryma/vim-multiple-cursors.git
  • unite-vim 快速管理项目中的文件 github
cd ~/.vim/bundle/
git clone https://github.com/Shougo/unite.vim.git
  • vim-javascript 缩进和语法支持 github
cd ~/.vim/bundle/
git clone https://github.com/pangloss/vim-javascript.git
  • jsDoc 对 vim-javascript 的补充,支持 es6和 TypeScirpt github
cd ~/.vim/bundle/
git clone https://github.com/heavenshell/vim-jsdoc.git
  • Fugitive git版本控制 github
git clone git://github.com/tpope/vim-fugitive.git
vim -u NONE -c "helptags vim-fugitive/doc" -c q
cd ~/.vim/bundle/
git clone --depth=1 https://github.com/vim-syntastic/syntastic.git

syntastic 需要一些其他的

npm install -g jslint
npm install -g csslint
cd ~/.vim/bundle/
git clone https://github.com/hail2u/vim-css3-syntax.git
brew install tidy-html5
  • vim-css-color 自动预览颜色 github
cd ~/.vim/bundle/
git clone https://github.com/skammer/vim-css-color.git
  • vim-snipmate 自动完成代码块 github
cd ~/.vim/bundle/
git clone https://github.com/tomtom/tlib_vim.git
git clone https://github.com/MarcWeber/vim-addon-mw-utils.git
git clone https://github.com/garbas/vim-snipmate.git
# Optional:
git clone https://github.com/honza/vim-snippets.git
  • vim-surround 辅助格式控制(用于括号、引号等) github
cd ~/.vim/bundle/
git clone git://github.com/tpope/vim-surround.git
  • jsbeauty-vim 自动美化代码,可配合 vim-autoformat 使用 github
cd ~/.vim/bundle/
git clone https://github.com/maksimr/vim-jsbeautify.git
cd vim-jsbeautify && git submodule update --init --recursive
  • vim-markdown 把高亮功能推广到 markdown github
cd ~/.vim/bundle/
git clone https://github.com/plasticboy/vim-markdown.git
  • vim-instant-markdown 预览 markdown githjub
npm -g install instant-markdown-d
  • vim-markdown-toc 为 markdown 生成标题 github
cd ~/.vim/bundle/
git clone https://github.com/mzlogin/vim-markdown-toc.git
  • youcompleteme 代码提示和补全 github

这个放在最后因为它比较复杂。属于可选的插件,根据自己需求安装。
首先,在 vim normal 模式输入 :version 查看其版本,要求版本大于7.4.143, 否则更新它。
其次,在 vim normal 模式输入 :echo has('python') || has('python3'), 如果输出为0,请更新 vim 以支持 python。
之后,在终端输入:

cd ~/.vim/bundle/
git clone https://github.com/Valloric/YouCompleteMe.git
cd ~/.vim/bundle/YouCompleteMe/
git submodule update --init --recursive
cd ~/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tern_runtime
npm install --production

如果你需要支持 typescript,安装:

npm install -g typescript
cd ~/.vim/bundle/
git clone https://github.com/groenewege/vim-less

到这里还没有完,作为前端人,这个还不能正常工作,它需要一些依赖,下面我们来安装这些依赖:

回到 bundle 目录 安装

cd ~/.vim/bundle
git clone https://github.com/ternjs/tern_for_vim.git
cd ~/.vim/bundle/tern_for_vim
npm install

之后需要在您的项目根目录建立一个 .tern-project 文件,没有内容,空白即可。该文件内部结构如下:

{ "libs": [ "browser", "jquery" ], "loadEagerly": [ "importantfile.js" ], "plugins": {
"requirejs": {
"baseURL": "./",
"paths": {}
}
}
}

此部分详细配置在此 http://ternjs.net/doc/manual.html

  • apt-vim 自动管理插件 github

这里再安装一个插件自动管理插件,也比较麻烦,根据自己需求安装:

  1. 自动安装
curl -sL https://raw.githubusercontent.com/egalpin/apt-vim/master/install.sh | sh

2.手动安装
需要Python2.7.x或Python3.0+

cd ~/.vim/bundle/
git clone https://github.com/egalpin/apt-vim.git
cd apt-vim
sudo ./apt-vim init

编辑 ~/.bashrc 或 ~/.bash_profile , 添加下面一句话

export PATH=$PATH:~/.vimpkg/bin

编辑 ~/.vimrc 添加:

execute pathogen#infect()
call pathogen#helptags()

继续在终端执行:

source ~/.bashrc
apt-vim install

如果这里提示了:Completed successfully. 那就大功告成了。

到此为止,作为一个前端人的 vim 就基本搭建好了,如果还有什么好用的插件欢迎分享交流,如果你觉得这些插件还足够,可以去知乎、stackoverflow、或 github 上再挖掘一些。一些更高级插件会随着博主的积累,不断更新这篇内容的,欢迎关注。

下面附了我 .vimrc.editorconfig 文件的内容:

"vimrc
"vim original config
set ignorecase " ignore upper- or lowercase in search model
set smartcase " if there is uppercase in search string ignore 'ignorecase' setting. it only works with 'ignorecase' setting
set autowrite " auto write changes into file after :next、:rewind、:last、:first、:previous、:stop、:suspend、:tag、:!、:make、<C-]> or <C-^> runs, as well as jumps to another file with :buffer、<C-O>、<C-I>、'{A-Z0-9}' or `{A-Z0-9}`
set nocompatible "Donot compate with vi, to avoid some bugs
filetype on "check the file type
set autoindent " use auto-indentation
set smartindent " use smart indentation
set tabstop=2 " set the width of tab key
set softtabstop=2 " set the width of soft key
set shiftwidth=2 " auto-indent with 2 spaces
set backspace=2 " enable to use backspace
set showmatch " show the matched braces
set linebreak " wrap without breakword
set whichwrap=b,s,<,>,[,] "jump to previous/next line when cursor at the head/end of line when input 'b'/'w' in normal model
set relativenumber " show relative line number
set previewwindow " show preview window
set history=1000 " set command history to 1000
set laststatus=2 " show the last activited window's status line always
set ruler " show line number and column number in status line "command line setting
set showcmd " show inputted command in command line
set showmode " show current model in command line
set showmatch "show match brace
set guioptions=T "remove the toolbar in GUI
filetype on "check the file type "finding setting
set incsearch " show matched words when input string
set hlsearch "pathongen
execute pathogen#infect()
syntax on
filetype plugin indent on "airline
let g:airline_theme='molokai' "use a theme called 'molokai'
let g:airline#extensions#tabline#enabled=1 "show the tab line on the top
let g:airline_powerline_fonts=1 "use powerline fonts "emmet
let g:user_emmet_mode='n' "only enable normal mode functions.
let g:user_emmet_mode='inv' "enable all functions, which is equal to
let g:user_emmet_mode='a' "enable all function in all mode.
let g:user_emmet_install_global=0
autocmd FileType html,css EmmetInstall "enable for just html/css
let g:user_emmet_leader_key='<C-Z>' "change the default key(<C-Y>) to <C-Z>, the trailing ',' still needs to be entered as well "editConfig
let g:EditorConfig_exclude_patterns = ['fugitive://.*'] "ensure that this plugin works well with Tim Pope's fugitive
let g:EditorConfig_exclude_patterns = ['scp://.*'] "avoid loading EditorConfig for any remote files over ssh
let g:EditorConfig_exec_path = '~/.vim/.editorconfig'
let g:editorconfig_Beautifier = '~/.vim/.editorconfig'
"vim-javascript
let g:javascript_plugin_jsdoc=1 "Enables syntax highlighting for JSDocs.
let g:javascript_plugin_ngdoc=1 "Enables some additional syntax highlighting for NGDocs. Requires JSDoc plugin to be enabled as well. "jsDoc
let g:jsdoc_enable_es6=1 "Enable to use ECMAScript6's Shorthand function, Arrow function.
let g:javascript_plugin_flow=1 "Enables syntax highlighting for Flow. "syntastic
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_enable_highlighting=1 "apt-vim
execute pathogen#infect()
call pathogen#helptags() "jsbeautify
autocmd FileType javascript noremap <buffer> <c-f> :call JsBeautify()<cr>
autocmd FileType json noremap <buffer> <c-f> :call JsonBeautify()<cr>
autocmd FileType jsx noremap <buffer> <c-f> :call JsxBeautify()<cr>
autocmd FileType html noremap <buffer> <c-f> :call HtmlBeautify()<cr>
autocmd FileType css noremap <buffer> <c-f> :call CSSBeautify()<cr> "vimCSS3syntsx
augroup VimCSS3Syntax
autocmd!
autocmd FileType css setlocal iskeyword+=-
augroup END "vimCSScolor
let g:cssColorVimDoNotMessMyUpdatetime = 1 "YCM
let g:ycm_semantic_triggers = { 'scss,css': [ 're!^\s{2,4}', 're!:\s+' ], 'html': ['<', '"', '</', ' '] } "less2css
let g:less_autocompile = 1 " 这是开关 设置1保存less自动生成css 设置0关闭
function! s:auto_less_compile() " {{{
if g:less_autocompile != 0
try
let css_name = expand("%:r") . ".css"
let less_name = expand("%")
if filereadable(css_name) || 0 < getfsize(less_name)
let cmd = ':!lessc '.less_name.' 'css_name.' '
silent execute cmd
endif
endtry
endif
endfunction " }}}
autocmd BufWritePost *.less call s:auto_less_compile()
;.editorconfig
root = true indent_style = space
indent_size = 2
tab_width = 2
end_of_line = lf
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true [**.js]
path=~/.vim/bundle/js-beautify/js/lib/beautify.js
bin=node [**.jsx]
e4x = true

面向web前端及node开发人员的vim配置的更多相关文章

  1. Web前端与移动开发学习路线图

    文章转载自「开发者圆桌」一个关于开发者入门.进阶.踩坑的微信公众号 这里整理的Web前端与移动开发学习路线图包含初中级两个部分,你可以通过百度云盘下载观看对应的视频 链接: http://pan.ba ...

  2. Web前端和后端开发的区别和要求

    Web前端和后端开发的区别和要求 有时候自己会分不清,其实是因为前后端都了解,类似于全栈工程师,但又什么都不是很精通.那到底什么是前端.后端呢,我整理了一些企业要求级别的前端/后端基础,开发框架等. ...

  3. HTML5纯Web前端也能开发直播,不用开发服务器(使用face2face)

    前段时间转载了某位大神的一篇文章,开发Web版一对一远程直播教室只需30分钟 - 使用face2face网络教室.非常有意思.看起来非常简单,但作为一名前端开发人员来说,还是有难度.因为要开发服务器端 ...

  4. 从零开始,学习web前端之HTML5开发

    什么是HTML5 HTML5是HTML最新的修订版本,2014年10月由万维网联盟(W3C)完成标准制定.是下一代 HTML 标准. 为什么要学习HTML5 HTML5定义了一系列新元素,如新语义标签 ...

  5. 开发者福音!面向Web场景的云开发服务正式开放!

    导 语 继支持小程序开发之后,云开发也支持Web使用啦!开发者们可以使用云开发提供的云端能力,直接开发网站应用,如PC端网页.公众号中的网页等.由此开发者可以在网站应用中借助云函数实现业务逻辑,通过与 ...

  6. web前端之html5开发中常用的开发工具

    正所谓“工欲善其事,必先利其器”,对Web开发人员来说,好工具的使用总会给人带来事半功倍的效果.正准备学习HTML5或者已经进行了一段时间的HTML5开发的童鞋,都有必要了解下,HTML5都有哪些开发 ...

  7. Web前端,HTML5开发,前端资源,前端网址,前端博客,前端框架整理 - 转改

    Web前端/H5开发,前端资源,前端网址,前端博客,前端框架整理 综合类 前端知识体系 前端知识结构 Web前端开发大系概览 Web前端开发大系概览-中文版 Web Front-end Stack v ...

  8. web前端,移动开发规范概述

    以下规范建议,均是Alloyteam在日常开发过程中总结提炼出的经验,规范具备较好的项目实践,强烈推荐使用 字体设置 使用无衬线字体 body { font-family: "Helveti ...

  9. 前端系列——React开发必不可少的eslint配置

    项目需要安装的插件 "babel-eslint": "^8.0.3", "eslint": "^4.13.1", &qu ...

随机推荐

  1. vue中v-on支持的事件总结

    资源事件 事件名称 何时触发 error 资源加载失败时. abort 正在加载资源已经被中止时. load 资源及其相关资源已完成加载. beforeunload window,document 及 ...

  2. PAT甲级——1002 A+B for Polynomials

    PATA1002 A+B for Polynomials This time, you are supposed to find A+B where A and B are two polynomia ...

  3. scala编程(七)——内建控制结构

    几乎所有的 Scala 的控制结构都会产生某个值.这是函数式语言所采用的方式,程序被看成是计算值的活动,因此程序的控件也应当这么做.另外,指令式语言经常具有三元操作符(如 C,C++和 Java 的? ...

  4. linux文件系统与链接

    Linux的文件属性图1 图1   linux的文件属性 ls -lhi -l 长格式 -h 人性化 -i inodo -d 看目录自己的信息 inode 源自于文件系统 分区 平面设计图 格式化 施 ...

  5. 96)PHP,文件上传(2)

    (1)那么既然看到文件即使上传成功,但是只是在脚本周期内有效,脚本只要结束(脚本结束其实很快的),文件就会自动消失,那么怎么才能永久存储文件呢: 函数: Move_uploaded_file(上传临时 ...

  6. KUKA机器人常见十大问题及解决方法

    1 开机坐标系无效 世界坐标系是以枪头为基点,在这种坐标系中,机器人所有的动作都是按照以枪头为顶点来完成移动,XYZ方向切割枪方向不改变,如果机器人在世界坐标系中移动,枪头也随着改变方向,那就是我们在 ...

  7. struts 2.1.8.1的sx:datetimepicker标签出现NaN错误的原因和解决办法

     作者:Junsan.Jin 邮箱:junsanjin@gmail.com QQ:1305896503 本文原始地址:http://www.rsky.com.cn/Article/java/201 ...

  8. 在HADOOP中使用MRUNIT进行单元测试

    在HADOOP中使用MRUNIT进行单元测试 前提 1. 了解JUnit4.x的使用. 2. 了解Mock的概念在单元测试中的应用. 3. 了解Hadoop中MapReduce的编程模型. 如果您对J ...

  9. Web前端性能

    6.1前端性能示例 性能测试工具: Apache Benchmark(ab)得到的响应时间仅为从请求发出开始到接收到HTML的最后一个字节所消耗的全部时间.ab命令行如下: ab -c [并发用户数] ...

  10. js 实现排序算法 -- 归并排序(Merge Sort)

    原文: 十大经典排序算法(动图演示) 归并排序 归并排序是建立在归并操作上的一种有效的排序算法.该算法是采用分治法(Divide and Conquer)的一个非常典型的应用.将已有序的子序列合并,得 ...