配置vim
2015-08-29 12:42
567 查看
找到一个配置vim的好网站,收藏一下,以备后用:https://github.com/carlhuda/janus
It is designed to provide minimal working environment using the mostpopular plug-ins and the most common mappings.
The distribution is completely customisable using a
NOTE: If you ever have an error updating Janus relating to amissing commit in a submodule, please try running
GoogleGroups, please join it fordiscussion and announcements.
The distribution also requires
you need to use system-wide Python (If you are using python thatis):
If you're using pythonbrew: do
If you don't use Homebrew, you can still download MacVimhere.
Take a look at the
Pre-requisites wikipage for moreinformation.
automaticinstaller, which backs up any Vim files found in your home folder and installsJanus.
leader setting. You may also use
For example, to override the default color schemes:
If you want to do additional customization or add more Vim plugins,create a
Or, if you have a git repository in
If you would like to disable an included plug-in, you can do that withthe
WARNING: We've noticed over and over, that people fork Janus just tocustomize it. This is bad practice for several reasons and you shouldnot do that, and here's why:
Janus is fully customisable and there's no need to change the core forusing a different plugin fork or using a different mapping.
Forking means maintenance; maintenance means burden. Do not burdenyourself with maintaining a fork; that's what the
If you find yourself needing a customisation that is not possible withthe current setup, then please open an issue or consider submitting apull request to make it possible to continue using/improving the official repo.
WARNING: Any uncommited files inside the
janus folder will beremoved the next time you run
a submodule.
For more information on how to customize Janus, you might want to takea look at the
Customization wikipage.
Read the slides at
VIM: Walking Without Crutches.
Watch the screencasts at vimcasts.org
Watch Derek Wyatt's energetic tutorial videos at
his site
Read wycats' perspective on learning Vim atEveryone who tried to convince me to use vim was wrong
Read this and other answers to a question about vim at StackOverflow:Your problem with Vim is that you don't grok vi
Read the
Getting Started with Vim tutorial on SitePoint
Read the
Effective Rails Development with Vim tutorial on SitePoint
insert mode- stuff you type is added to the buffer
normal mode- keys you hit are interpreted as commands
visual mode- allows you to select blocks of text
To enter insert mode, hit
To exit insert mode, hit
To enter visual mode, hit
To exit visual mode, hit
Certain commands are prefixed with a
Keyboard cheat sheet.
Line numbers
Ruler (line and column numbers)
No wrap (turn off per-buffer via :set wrap)
Soft 2-space tabs, and default hard tabs to 2 spaces
Show trailing whitespace as
Make searching highlighted, incremental, and case insensitive unless acapital letter is used
Always show a status line
Allow backspacing over everything (indentations, eol, and startcharacters) in insert mode
Automatically resize splits when resizing the Vim window (GUI only)
Write a privileged file with
Remap
Customizations: Janus rebinds command-shift-f (
Command-T
Customizations: For users of Command-T Janus maps CtrlP to command-t (
Customizations: Janus binds command-/ (
Customizations: Janus adds a number of customizations to the coreNERDTree:
Use
Ignore compiled ruby, python, and java files
When opening vim with vim /path, open the left NERDTree to thatdirectory, set the vim pwd, and clear the right buffer
In general, assume that there is a single NERDTree buffer on the leftand one or more editing buffers on the right
Please check
find them.
Customizations: Janus binds
After typing in the method name, press tab again to put the cursor rightwhere you want it on the next line.
This repositoryhas a full list of the Snippets that are available in Janus.
When one of the available motions is triggered, all visible textpreceding or following the cursor is faded, and motion targets arehighlighted.
EasyMotion is triggered by one of the provided mappings.
check EasyMotion's
homepage for more information.
In the newbuffer, you can do a global replace, search or anything else to modifythat part. When you are finished, simply write that buffer (e.g. by|:w|) and your modifications will be put in the original buffer makingit accessible again.
Use
Use
customizations:
Customizations: Janus binds
a new window split (vertical or horizontal), or a newtab page.
Selected buffers can be "previewed", i.e. opened in a window or tabpage, but with focus remaining in the buffer catalog. Even better, youcan "walk" up and down the list of buffers shown in the catalog by using
Gary Bernhardt's vimconfigfor running your ruby tests/specs/features.
Imagine you're hacking on a Rails controller, when you switch to thetest or specs for the controller, you can use
Then benefits of this plugin are to centralize your workflow in onewindow, one software to do it all, which is a huge speedup over using
places another virtual cursor at the end of the visual selection.If you select multiple lines in Visual mode, pressing the key puts a virtualcursor at every line and leaves you in Normal mode.
More at
QuickStart
To fix the whitespace errors, just call :FixWhitespace. By default itoperates on the entire file. Pass a range (or use V to select some lines)to restrict the portion of the file that gets fixed.
Markdown (bound to *.markdown, *.md, and *.mk)
Markdown auto styling (disabled by setting
Mustache (bound to *.mustache)
Haml (bound to *.haml)
Sass (bound to *.sass)
SCSS (bound to *.scss)
An improved JavaScript syntax (bound to *.js)
Javascript for any file having
Map Gemfile, Rakefile, Vagrantfile, Procfile, Thorfile, config.ru and*.rake to Ruby.
Git commits (set your
publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:
The above copyright notice and this permission notice shall be includedin all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANYCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Janus: Vim Distribution
This is a distribution of plug-ins and mappings for Vim, Gvim andMacVim.It is designed to provide minimal working environment using the mostpopular plug-ins and the most common mappings.
The distribution is completely customisable using a
~/.vimrc.beforeand
~/.vimrc.afterVim RC files.
Updating to the latest version
To update to the latest version of the distribution, just runrakeinside your
~/.vimdirectory.
NOTE: If you ever have an error updating Janus relating to amissing commit in a submodule, please try running
rakeagain beforesubmitting an issue.
Mailing list
The mailing list is hosted atGoogleGroups, please join it fordiscussion and announcements.
Pre-requisites
The distribution is designed to work with Vim >= 7.3.The distribution also requires
ack,
ctags,
git,
rubyand
rake.For the most comfortable experience, use the GUI version of Vim. Linuxusers should install
gvim, OSX users should installMacVim. The recommended way ofinstalling MacVim is usingHomebrew, but before installingMacVim
you need to use system-wide Python (If you are using python thatis):
If you're using pythonbrew: do
pythonbrew off
$ brew install macvim
If you don't use Homebrew, you can still download MacVimhere.
Take a look at the
Pre-requisites wikipage for moreinformation.
Installation
To install Janus, please use ourautomaticinstaller, which backs up any Vim files found in your home folder and installsJanus.
$ curl -Lo- https://bit.ly/janus-bootstrap | bash
Customization
You can use~/.gvimrc.beforeand
~/.vimrc.beforefor settings Janus itself uses,such as the
leader setting. You may also use
~/.gvimrc.afterand
~/.vimrc.afterfor any additional settings; it is also a good place foroverriding Janus settings, as both files will be loaded at the end ofJanus.
For example, to override the default color schemes:
$ echo 'color desert' >> ~/.vimrc.after $ echo 'color molokai' >> ~/.gvimrc.after
If you want to do additional customization or add more Vim plugins,create a
~/.janusdirectory and add your plugins there, either with a
git cloneor by adding submodules to your own git repository there.This directory is treated like a normal pathogen directory. For example:
$ cd ~/.janus $ git clone https://github.com/vim-scripts/Rename2.git rename2
Or, if you have a git repository in
~/.janus, you can use a submodule:
$ cd ~/.janus $ git submodule add https://github.com/vim-scripts/Rename2.git rename2
If you would like to disable an included plug-in, you can do that withthe
janus#disable_plugin()function from inside your
~/.vimrc.before. This function takes a plug-in name as an argumentwithout the group. For example, if you would like to disable theNERDCommenter plug-in, you can do that with the command:
$ echo "call janus#disable_plugin('nerdcommenter')" >> ~/.vimrc.before
WARNING: We've noticed over and over, that people fork Janus just tocustomize it. This is bad practice for several reasons and you shouldnot do that, and here's why:
Janus is fully customisable and there's no need to change the core forusing a different plugin fork or using a different mapping.
Forking means maintenance; maintenance means burden. Do not burdenyourself with maintaining a fork; that's what the
~/.janusfolderis for.
If you find yourself needing a customisation that is not possible withthe current setup, then please open an issue or consider submitting apull request to make it possible to continue using/improving the official repo.
WARNING: Any uncommited files inside the
janus folder will beremoved the next time you run
rakeso make sure to either put them inthe custom folder (
~/.janus), or commit them. We clean the janusfolder in case we replace a manually installed plugin (using rake tasks)with
a submodule.
For more information on how to customize Janus, you might want to takea look at the
Customization wikipage.
Intro to VIM
Here're some tips in case you've never used VIM before:Tutorials
Typevimtutorinto a shell to go through a brief interactivetutorial inside VIM.
Read the slides at
VIM: Walking Without Crutches.
Watch the screencasts at vimcasts.org
Watch Derek Wyatt's energetic tutorial videos at
his site
Read wycats' perspective on learning Vim atEveryone who tried to convince me to use vim was wrong
Read this and other answers to a question about vim at StackOverflow:Your problem with Vim is that you don't grok vi
Read the
Getting Started with Vim tutorial on SitePoint
Read the
Effective Rails Development with Vim tutorial on SitePoint
Modes
VIM has three modes:insert mode- stuff you type is added to the buffer
normal mode- keys you hit are interpreted as commands
visual mode- allows you to select blocks of text
To enter insert mode, hit
i
To exit insert mode, hit
<ESC>
To enter visual mode, hit
v
To exit visual mode, hit
<ESC>
Useful commands
Use:qto exit vim
Certain commands are prefixed with a
<Leader>key, which maps to
\by default. You can, for example, use
let mapleader = ","to change this to a comma. If you want thisto be in effect for uses of
<Leader>in the .vimrc file, make sure to definethis in
~/.vimrc.before
Keyboard cheat sheet.
Features
This Vim distribution includes a number of packages built by others.Base Customizations
Janus ships with a number of basic customizations for vim:Line numbers
Ruler (line and column numbers)
No wrap (turn off per-buffer via :set wrap)
Soft 2-space tabs, and default hard tabs to 2 spaces
Show trailing whitespace as
.
Make searching highlighted, incremental, and case insensitive unless acapital letter is used
Always show a status line
Allow backspacing over everything (indentations, eol, and startcharacters) in insert mode
<C-P>inserts the directory of the current file into a command
Automatically resize splits when resizing the Vim window (GUI only)
<leader>ewexpands to
:e (directory of current file)/(open in thecurrent buffer)
<leader>esexpands to
:sp (directory of current file)/(open in ahorizontal split)
<leader>evexpands to
:vsp (directory of current file)/(open ina vertical split)
<leader>etexpands to
:tabe (directory of current file)/(open ina new tab)
Write a privileged file with
:SudoWor
:SudoWrite, it will promptfor sudo password when writing
<F4>toggles paste mode
<leader>fefformats the entire file
<leader>uconverts the entire word to uppercace
<leader>lconverts the entire word to lowercase
<leader>Uconverts the first char of a word to uppercase
<leader>Lconverts the first char of a word to lowercase
<leader>cdchanges the path to the active buffer's file
<leader>mdcreates the directory of the active buffer's file(For example, when editing a new file for which the path does notexist.)
gwswaps the current word with the following word
<leader>ulunderlines the current line with
=
<leader>twtoggles wrap
<leader>fcfinds the next conflict marker (tested with Gitconflicted files)
Remap
<Down>and
<Up>to
gjand
gk(Wrapped text is notconsidered a single long line of text.)
<leader>hstoggles highlight search
<leader>=adjusts viewports to the same size (
<C-w>=)
<A-[(
<D-[on MacVim) shifts current line or selected linesrightwards
<A-](
<D-]on MacVim) shifts current line or selected linesleftwards
<C-W>!invokes kwbd plugin; it closes all open buffers in the openwindows but keeps the windows open
Ack.vim
Ack.vim uses ack to search inside the current directory for a pattern.You can learn more about it with :help Ack.Customizations: Janus rebinds command-shift-f (
<D-F>) to bring up
:Ack.
CtrlP
Fuzzy file, buffer, mru and tag finder. ReplacesCommand-T
Customizations: For users of Command-T Janus maps CtrlP to command-t (
<D-t>)
NERDCommenter
NERDCommenter allows you to wrangle your code comments, regardless offiletype. View:help NERDCommenterfor all the details.
Customizations: Janus binds command-/ (
<D-/>) to toggle comments.
NERDTree
NERDTree is a file explorer plugin that provides "project drawer"functionality to your vim projects. You can learn more about it with:help NERDTree.Customizations: Janus adds a number of customizations to the coreNERDTree:
Use
<Leader>nto toggle NERDTree
Ignore compiled ruby, python, and java files
When opening vim with vim /path, open the left NERDTree to thatdirectory, set the vim pwd, and clear the right buffer
In general, assume that there is a single NERDTree buffer on the leftand one or more editing buffers on the right
Unimpaired
This plugin provides a lot of useful mappings, here's a brief example ofwhat it does provide:[bto go to the previous buffer
]bto go to the next buffer
[nto go to the previous SCM conflict marker
]nto go to the next SCM conflict marker
Please check
:helpunimpairedfor a complete list
SuperTab
In insert mode, start typing something and hit<TAB>to tab-completebased on the current context.
Syntastic
Syntastic is a syntax checking plugin that runs buffers through external syntaxcheckers as they are saved and opened. If syntax errors are detected, the useris notified and is happy because they didn't have to compile their code orexecute their script tofind them.
Tagbar
Tagbar is a vim plugin for browsing the tags of source code files.Customizations: Janus binds
<Leader>rtto toggle Tagbar.
SnipMate
SnipMate defines text snippets (a series of characters) that expand toa useful piece of code when tab is pressed. For example, in a Rubyfile, def<TAB>expands to:
def method_name end
After typing in the method name, press tab again to put the cursor rightwhere you want it on the next line.
This repositoryhas a full list of the Snippets that are available in Janus.
EasyMotion
EasyMotion provides a much simpler way to use some motions in vim. Ittakes the<number>out of
<number>wor
<number>f{char}by highlightingall possible choices and allowing you to press one key to jump directlyto the target.
When one of the available motions is triggered, all visible textpreceding or following the cursor is faded, and motion targets arehighlighted.
EasyMotion is triggered by one of the provided mappings.
check EasyMotion's
homepage for more information.
NrrwRgn
Narrowing means focussing on a region and making the rest inaccessible.You simply select the region, call :NarrowRegion and the selected partwill open in a new scratch buffer. The rest of the file will beprotected, so you won't accidentally modify that buffer.In the newbuffer, you can do a global replace, search or anything else to modifythat part. When you are finished, simply write that buffer (e.g. by|:w|) and your modifications will be put in the original buffer makingit accessible again.
Git Support (Fugitive)
Fugitive adds pervasive git support to git directories in vim. For moreinformation, use:help fugitive
Use
:Gstatusto view
git statusand type
-on any file to stage orunstage it. Type
pon a file to enter
git add -pand stage specifichunks in the file.
Use
:Gdiffon an open file to see what changes have been made to thatfile
customizations:
<leader>gbmaps to
:Gblame<CR>
<leader>gsmaps to
:Gstatus<CR>
<leader>gdmaps to
:Gdiff<CR>
<leader>glmaps to
:Glog<CR>
<leader>gcmaps to
:Gcommit<CR>
<leader>gpmaps to
:Git push<CR>
Git Gutter
A Vim plugin which shows a git diff in the 'gutter' (sign column). Itshows whether each line has been added, modified, and where lines havebeen removed. You can also stage and revert individual hunks.ZoomWin
When working with split windows, ZoomWin lets you zoom into a window andout again usingCtrl-W o
Customizations: Janus binds
<leader>zwto
:ZoomWin
BufferGator
Buffergator is a plugin for listing, navigating between, and selectingbuffers to edit. Upon invocation (using the command,:BuffergatorOpenor
BuffergatorToggle, or the provided key mapping,
<Leader>b), a
catalogof listed buffers are displayed in a separate new window split(vertical or horizontal, based on user options; default = vertical).From this "buffer catalog", a buffer can be selected and opened in anexisting window,
a new window split (vertical or horizontal), or a newtab page.
Selected buffers can be "previewed", i.e. opened in a window or tabpage, but with focus remaining in the buffer catalog. Even better, youcan "walk" up and down the list of buffers shown in the catalog by using
<C-N>(or
<SPACE>) /
<C-P>(or
<C-SPACE>). These keys select thenext/previous buffer in succession, respectively, opening it for previewwithout leaving the buffer catalog viewer.
Vroom
VRoom is a plugin inspired byGary Bernhardt's vimconfigfor running your ruby tests/specs/features.
Imagine you're hacking on a Rails controller, when you switch to thetest or specs for the controller, you can use
<leader>rto run all thespecs or
<leader>Rto run the closest spec, then you can jump back tothe controller hack on it and use
<leader>rto run the last spec youran last time, so you don't need to open the test again.
Then benefits of this plugin are to centralize your workflow in onewindow, one software to do it all, which is a huge speedup over using
tmuxor multiple terminal tabs.
vim-multiple-cursors
Out of the box, all you need to know is a single keyCtrl-n. Pressing the keyin Normal mode highlights the current word under the cursor in Visual mode andplaces a virtual cursor at the end of it. Pressing it again finds the nextoccurrence and
places another virtual cursor at the end of the visual selection.If you select multiple lines in Visual mode, pressing the key puts a virtualcursor at every line and leaves you in Normal mode.
More at
QuickStart
vim-trailing-whitespace
This plugin causes all trailing whitespace to be highlighted in red.To fix the whitespace errors, just call :FixWhitespace. By default itoperates on the entire file. Pass a range (or use V to select some lines)to restrict the portion of the file that gets fixed.
Additional Syntaxes
Janus ships with a few additional syntaxes:Markdown (bound to *.markdown, *.md, and *.mk)
Markdown auto styling (disabled by setting
g:disable_markdown_autostylein
~/.vimrc.before=>
letg:disable_markdown_autostyle = 1)
Mustache (bound to *.mustache)
Haml (bound to *.haml)
Sass (bound to *.sass)
SCSS (bound to *.scss)
An improved JavaScript syntax (bound to *.js)
Javascript for any file having
nodejsin the shebang.
Map Gemfile, Rakefile, Vagrantfile, Procfile, Thorfile, config.ru and*.rake to Ruby.
Git commits (set your
EDITORto
vim -for
mvim -fon OSX)
$ echo "export EDITOR='vim -f'" >> ~/.bashrc, you can also use Gitglobal config to set this if you have EDITOR set to something else
$ git config --global core.editor 'vim -f'
License
This code is free to use under the terms of the MIT license.
Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge,publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:
The above copyright notice and this permission notice shall be includedin all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANYCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
相关文章推荐
- jquery datatable使用
- Django之第一个app<13>
- eclipse里面使用github插件
- Linux文件系统损坏故障怎么办?故障修复方法
- 最小生成树算法—kcruscal算法
- 计算字符串的距离
- HTML URL 编码
- C# WinForm控件、自定义控件整理(大全)
- girdView数据导出Excel
- $root knockout
- 函数重载
- hadoop做HA后,hbase修改
- 最简单,又容易扩展的新功能引导
- HDOJ 题目4691 Front compression(后缀数组+RMQ最长前缀)
- JavaScript中常见的字符串操作函数及用法
- MySQL分页查询以及优化
- 大话设计模式之--简单工厂模式
- linux运维实战练习-2015年8月27日课程作业
- 开关控件UISwitch
- Java集合框架图