Who says VIM is not an IDE?

Source: Internet
Author: User
Tags autoload file copy format definition


The words of the operating system, programming language and editor seem to be the eternal topic of the programmer's spat, and the technology has developed over the decades, and we have been discussing these "battles" with anger and relish. Someone described Emacs and VI programmers, everyone along the different roads and goals forward, but always at some point cross meet, throw stones, hit each other black and blue, and then clean up the mood and continue to move forward.

A while ago I wrote a micro blog on the microblog reply, is about vim and the IDE discussion:vim and those IDE's application is still different, in my opinion vim is also the IDE, is one of the necessary skills of programmers. This basically expresses my point of view.

The original micro-blog is @ Yuber also called Condor released, this microblog forwarded a review hundreds of times. In fact, the meaning of the expression is very clear, and mainly for the front-end development, but 140 words is too little, so that there is no time to explain, a lot of service-side programmers have already washed their arms rushed up, Yuber later or on GitHub wrote a long text, just counted over. Article is very good, interested in children's boots do not look at the micro Bo, tired, directly read this article is good.

The direct consequences of this matter, or left me the sequela is that each time their own use of vim is always pondering this matter, are programmers, are editors, how is that so big difference? Is there such a big difference? The more you think about writing an article about Vim. Non-controversial, only to explain and share, because work for more than 10 years I have never used a programming tool to do everything Zhu Er, different scenarios under the various editors have used. It has been a great achievement to use the most suitable tool in the most suitable scenario by missing and using the right tools. Every good editor has some legendary stories that are worth particularize, but this time I just want to talk about Vim.

Many people equate vim with Emacs, some say that Emacs is a bundle of text editor operating system, I seldom use Emacs, not familiar, but feel this words majestic. Vim, although not the operating system, but also formed its own ecological environment. Seemingly simple tool, it seems to be a text editor full of shortcut keys and speed sense, once in-depth, but full of endless fun ...

As for why this is a name for this article, the reader is as good a gimmick. In fact, Vim, Emacs, ST2 and so on have not much difference with the IDE.

Programming Life

My personal contact with Vim began in 2000, at the time of the first wave of the internet, I just graduated soon, as now passionate young people, into the melting pot of the internet (of course, and now the Internet is not the same, most of us have been melted down), I participated in the first Internet product is Hongen online.

At that time Hongen gathered a lot of Tsinghua University students, there are a lot of technical cattle, such as baby, Star, Panpan and so on, are big figures, and then some of these people left to create their own business, and some stay in Hongen formed the perfect World game platform technology team. At that time are need I look at the role, they exclusively use VIM in the server-side programming, even syntax highlighting are not set, the BBS is also the same year smth, through the terminal Telnet access. In the office, exclusively are dark screen, lacquer green word, crackling in there tapping the keyboard, very rhythmic, I think, this is simply cool.

The server-side operating system used to remember is Redhat Linux and FreeBSD, and the programming language is Perl, HTML4, and JavaScript. In this environment, for me such a perennial use EditPlus rookie, the pressure is very big, others development, compilation and release environment are on the server side, and I need to write a good program locally, through the EditPlus FTP function upload to the server side, and then debug, test and release, Very troublesome. So in addition to learning programming skills, I also need to master the Linux operation and vim editor. At that time Eat live in the company, enough to let you do not learn all embarrassed, so quickly mastered the basic operation of Linux and Vim, the code when the hands on the keyboard and fly a very fulfilling feeling. I have a special interest in grammar, often put their own interface configuration of colorful, nothing to see is also a pleasure.

Since then, more than 10 years have passed, their work has not left vim,2001 years to start using Java, JSP, then Eclipse, Idea, NetBeans "artifact" has not yet risen, we are still in the server-side programming, through make compilation and debugging, Integrate testing and publishing by writing shell scripts, including product installation. Later, with the development of these cow Ides, most of the Java EE-related work was transferred to the IDE, followed by a two-year script such as Python, and began to use vim in large numbers, and the programming environment was Solaris. Since then the work involved a lot of technology, VIM has been used intermittently. By the year 2009, I began to completely switch the work environment to the MAC, remember to open the Mac terminal, ecstatic thinking, this is not the perfect combination of vim, shell and IDE? Later, I wrote a blog to introduce this experience.

Until now, VIM is still an indispensable tool platform for my work and study, and there is so much to learn from Vim alone.

Usage Scenarios

I advocate the use of the most appropriate tools in different scenarios, which is consistent with @ Yuber also known as Condor. Then someone asked, what is vim suitable for the scene? To put it simply, VIM is more suitable for Unix/linux server-side programming, which is of course individual. My personal use of vim is mainly used for SHELL/PYTHON/C programming. Ruby also writes, but uses textmate more. Unix/linux server-side editing and modification of the file is also inseparable from vim, in addition, because my personal working environment is a Mac, so change a text file or something, also use vim handy to do.

And the reality of a lot of programmers to communicate, you will think that without vim can modify the server-side files, FTP pull down, and then transfer up. This is certainly a scenario, but not the best solution. And in extreme cases you need to solve the problem directly on the client server, you can not say sorry I do not edit the file under Linux, down a copy down first? This is like using Vim to write markdown files, can be used, of course, some people have already developed the MD plugin for Vim, can be written by shortcut keys to view the translated HTML text, but this is obviously not as good as Mou+byword.

Writing Java EE, Html/css/js, objective-c, the best solution may be eclipse, idea, Xcode, and so on, these excellent tools can help us improve efficiency and reduce errors, but if you want to further, then vim is definitely worth it.

Vim has been used for many years, has not been summed up (this person is very lazy), I would like to just use this article to share the experience and usage. The introduction of VIM on the network of articles voluminous, a variety of sophisticated usage of countless, it seems more time-consuming and laborious. Vim itself is out of the box, nothing is configured or can use its basic functions, if you have mastered the basic operation, the following can help improve efficiency, create your own vim.

< To be continued, the next article introduces the basic concepts and configuration of vim, then the plugin, then the VIM programming ......>

Environment configuration

"If you think Vim is just a text editor, you Lose"--from the VIM veteran

VIM provides a rich set of configuration features in a concise manner, and the main configuration system consists of a file and a folder. On a vim-installed OS X/linux/unix machine, enter the user's home directory to find the. vimrc file and the. Vim folder, which is all the configuration information for vim.

(1). VIMRC Introduction

The. vimrc file in the user directory is the main profile of vim for the current user, which is not required and is created without it. The file is located in the current user's home directory and can be ~/.vimrc found, and when Vim starts, it automatically runs each command in the file.
Through. VIMRC we can personalize vim for use, display style, write functions and run plug-ins, and so on. All commands in the VIMRC can be run dynamically in a similar way during Vim runtime :comm args[=args1] and take effect immediately.
Here is a. VIMRC sample script that contains some common configurations, followed by a brief description.

The comments of the. VIMRC are denoted by double quotation marks ("), and the braces in the sample represent only the Ribbon, which is part of the comment and has no other meaning
The configuration of the. VIMRC is very rich, you can define a variety of macros, functions, plugins and mappings, I have seen the longest. VIMRC configuration has more than 1000 lines, here The example is relatively simple, suitable for entry-level users

syn on                        "Grammar support  " common conf {{               General Configuration  set ai                        Auto Indent  set  bs=2                      Delete with backspace key in insert mode  set showmatch                 "Code matching  set laststatus=2              Always show status lines  set expandtab                 "The following three configurations work together to set tab and indent spaces  set shiftwidth=4 set  tabstop=4 set cursorline               "underline the line where the cursor is located  set number                    "Show line numbers  set autoread                  "file has been modified outside of vim, automatically re-read into   set ignorecase                "Ignore case  set fileencodings=uft-8 when retrieving, gbk  "Open file with Utf-8 or GBK  set hls                       highlight matches when retrieving  set helplang=cn               Help system set to Chinese  set foldmethod=syntax         "code folding  }} " conf for tabs,  the Configuration for the tab page, via CTRL &NBSP;H/L Switch Labels  let mapleader =  ', '  nnoremap <C-l> gt nnoremap <C-h> gT  nnoremap <leader>t : tabe<cr>  "conf for plugins {{  plugin-related configuration   Configuration of the status bar    Powerline{ set guifont=powerlinesymbols\ for\ powerline set  nocompatible set t_Co=256 let g:Powerline_symbols =  ' Fancy '   '}  ' Pathogen is a plugin used by Vim to manage plugins   "pathogen{ call pathogen#infect ()  "}  "}}

(2). Vim folder

Vim is the master Configuration folder for Vim, which is located in the current user's home directory and can be cd ~/.vim accessed. This folder is typically used to place plug-ins and related help documents, and the common directory structure includes:

Doc//Help document directory AutoLoad//vim plug-in catalog plugin//plugins loaded automatically at startup When you use VIM, you usually call out by command

Of course, if you have enough plug-ins installed, the directory will become a lot more, syntax, snippets, indent and other folders will pop up. A plug-in contains files are often distributed in a number of folders, management is more troublesome, later we will introduce a management plugin plug-in, so that the directory becomes clean and tidy, easy to manage, the name of the plugin is pathogen!

Enter the command in VIM to enter the :help help page, the default is English help, if you like to see Chinese, you can install the Chinese Help content in the following ways:

    1. Download the Chinese Help file compression package

    2. Unzip, copy the files under the doc directory to ~/.vim/doc

    3. Confirm that the VIMRC is set in the.set helplang=cn

    4. Enter the command to :help enter Chinese help

Basic concepts

Let's take a look at some of the basic concepts of vim: Buffer, window, and Tab-page.

    1. buffer: Files opened with VIM are loaded into memory, and in memory we use Buffer to describe the edited file. A buffer corresponds to a copy of the file being edited. When we have finished editing a buffer, we can save the file. Buffer not only contains the contents of the file, but also records the configuration information such as the editing status of the file, such as activation, hiding, last edited line number, etc., can consult the help document.
      with VIM can open multiple files at the same time to edit, you can also turn off the unnecessary files, but then the file copy is still stored in the buffer, we can pass the   : ls or : buffers To view these buffer, you can also reopen the file by using a similar : buffer n (n = ordinal of buffer). Of course, we have a better way to deal with these buffer, that is commandtbuffer, to use Commandtbuffer, first to install the Commandt plug-in, please remember the name of this plugin, described later.

    2. window: is a display window corresponding to buffer. A buffer can correspond to multiple windows, for example, we can open a file in multiple windows by : Split filename or : vsplit filename command, when the file of a window is modified, Other windows will be updated synchronously. Of course, we can open more than one file in multiple windows, edit and then use : Wq to save the exit, but remember, as long as not finally quit the VIM process, the open file buffer is still in the buffer, can be opened again at any time.

    3. tab-page:tab-page is relatively easy to understand, corresponding to a set of Windows, we can through ': tabedit filename ' Open a file in another tab, and in this tab you can open multiple windows.

The relationship between buffer, window, and tab-page can be clearly expressed:

Understanding these three concepts and the relationship between the three, for our good use of vim is very helpful.

To be continued, the next one is vim plug-in article ...

The reason that vim formed its own ecological environment, is because VIM has an open plug-in system, developers in order to improve development efficiency, for VIM to write tens of thousands of plug-ins, we can choose any choice, or based on the Vimscript language to develop their own proprietary plugins.

Each plugin is a vim-suffix script file, and the language used to write the plugin is generally Vimscript. Vimscript is Vim's own programming language, and we'll introduce it in a follow-up. Although Vimscript can do almost anything for vim, there are still some scenes that are better and faster in other languages. With this in mind, Vim's developers have designed interfaces for other scripting languages to write Vim plugins, such as Perl,python and Ruby, and we'll show you how to use the Python language to write vim plugins for the go language and execute the GO program in vim.

Common plug-ins are divided into four types:

  1. Universal Plug-in: Applies to all types of files and can be paged out via plugin commands when using VIM. For example, to quickly locate a file plug-in Commandt, use to :CommandT start the function, for any type. This type of plug-in is typically placed under the. vim/plugin/directory.

  2. File type plug-ins: For specific types of files, such as C, Java, XML and other files. Plug-in functionality is enabled when editing a specific type of file, and the plug-in is typically placed under the. vim/ftplugin/directory. For example, we commonly used to edit xml/html/jsp files such as plug-in Xmledit, after installing the plugin, when editing the XML file, type <modules> , when finished > , Xmledit will automatically add a closed tag for you, <modules></modules> if you enter the last >, the label expands automatically, allowing you to enter sub-labels or text content. If you open a TXT file with VIM, these functions will disappear. Of course, the Xmledit function is much more than that, and we'll cover it later.

  3. Syntax plug-in: As the name implies, syntax plug-ins mainly provide syntax highlighting for programming languages, usually placed under the. vim/syntax/. Vim already provides syntax highlighting for most languages by default, but for some newer languages, developers are required to write plugins that support syntax highlighting, such as the Go language.

  4. Compiler plug-ins: Compiler plugins written for different languages, primarily used to set compiler options for the relevant language. For example, for C, C + +, Java, Python can write their own compiler plug-ins, plug-in content is not complex, the main definition of "Errorformat" (Error format definition) and "MAKEPRG" (compiler and parameters) content can be. :makeyou can compile the file that you are editing by.

Understand the basic concept of VIM plug-ins, and then the following common plug-ins, it is more easily understood.

Pathogen

Let's start by introducing this plugin--pathogen for managing plugins.

1.

Https://github.com/tpope/vim-pathogen

2. Function description

A plug-in package often has a variety of functions, each file according to the path of the vim of the directory will be placed in different directories, the general plug-in into the plugin, the syntax highlighting plug-in syntax, the automatic loading plug-in autoload, file type plug-in Ftplugin, encoding format Put the plugin into the indent ... If you are a heavy plug-in user, you will find that there will be a lot of folders in the. Vim home directory, whether you want to install a new plugin, or want to delete the old plugin, is very troublesome, you have to find the relevant vim file under each folder.

Pathogen is a plug-in that manages plug-ins that are primarily used to address these issues. Pathogen uses the concept of bundles to manage plug-ins, and if you're familiar with OSGi or OS X, you're not unfamiliar with bundles. OSGi encapsulates Java programs and resource files in the form of bundles, and most of the applications in OS X are bundles, and it is the concept of bundles that allows OSGi to dynamically manage Java components, and most of the OS X installations are "green installations".

Pathogen the .vim bundle file in the directory, all plugins will be managed under that directory. When Vim starts, the Vim script in the folder contained in the Runtimepath (RTP) list is automatically executed, and pathogen will ./vim/bundle load the plug-ins in the folder below in a certain order recursively into RTP at startup, so that when Vim starts, Plug-ins that are managed through pathogen are in effect.

With pathogen, there are .vim only three folders under the General folder: AutoLoad, Bundle, and Doc, and the other plugins will be installed under the bundle folder:

If no special instructions, the plug-ins mentioned later are installed in pathogen mode, I will use the Nerdtree plugin as an example of how to install.

3. Installation
    1. .vimCreate AutoLoad and bundle directories under folders

    2. From getting the Pathogen.vim file, copy it to the AutoLoad directory

    3. .vimrcAdd the following code to the file:

      Call Pathogen#infect ()
4. Instructions for use

No

5. Precautions

After installing the new plugin into the bundle directory, if the plugin contains doc, you will need to run it in vim :Helptags to generate online help tags.

Nerdtree

When we introduced pathogen, we used a graph to show the directory structure of the plugin, which was implemented based on the Nerdtree plugin.

1.

Https://github.com/scrooloose/nerdtree

2. Function description

Nerdtree is one of the most commonly used plug-ins of vim, it can display the directory and file structure in vim runtime, similar to the file browser on the left side of TextMate, but it is more convenient to operate, you can quickly browse the files without leaving the keyboard, and switch between files and folders.

3. Installation
    1. Go to .vim/bundle Catalog

    2. Performgit clone git://github.com/scrooloose/nerdtree.git

    3. After the download is complete, a Nerdtree folder is created under the bundle, and all related plugins are in the folder

    4. Run in vim :Helptags to generate Nerdtree online Help tags

4. Instructions for use

Turn on vim and enter :NERDTree to exhale the file directory of the current directory where the VIM command is executed. For ease of use, I have defined shortcut keys in. VIMRC, you can use Ctrl+t to open nerdtree, you can define your own custom shortcuts.

Nerdtree provides a rich keyboard operation to browse and open files, I briefly introduce some common shortcut keys:

As with the edit file, move the cursor through the H J k L to open the closed file or directory, if it is a file, the cursor appears in the open file in the go effect, but the cursor remains in the file directory, similar to preview the contents of the file features I and S can be split horizontally or vertically split window open file, The front plus g like go function t in the tab open T in the Background tab open p to the upper directory p to the root directory K to the same directory the first node J to the same directory the last node m display file System menu (add, delete, move operation)? Help Q Close

Want to know more ways to operate, can pass? See the detailed help information.

Command-t1.

Https://wincent.com/products/command-t

2. Function description

COMMAND-T is a plug-in for fast file browsing based on Ruby and C extensions, similar to the textmate go to file (command+t out) feature, or the Open Resource (command+shift+r) feature of Eclipse , you can quickly locate and open a file with fuzzy matching.

3. Installation
    1. From downloading the latest version of the VBA file, the latest version is currently 1.4, so the installation file is Command-t-1.4.vba

    2. ~/.vim/bundleCreate a folder under the directory Command-t

    3. Open Command-t-1.4.vba with Vim

    4. Perform:UseVimball ~/.vim/bundle/command-t

    5. Go to the Ruby directory to compile the C extension

      CD ~/.vim/bundle/command-t/ruby/command-t Ruby extconf.rb make
4. Instructions for use

Input: Commandt can enter the file quick location function:

    1. ctrl+j/k Select File, select and enter to open file

    2. Ctrl+t opening a file in tab mode

    3. ctrl+s/v can open a file horizontally or vertically in a split window

    4. CTRL + C to exit the mode

The plugin also has a common command that :CommandTBuffer can browse the buffer file and reopen it. Operation is the same as above.

5. Precautions

The VIM version needs to support Ruby extensions. We can enter the check in Vim :ruby 1 , if E319: Sorry, the command is not available in this version it appears it is not supported.

If this is the case, we need to compile our own to support the vim of Ruby, it is troublesome to install Vim-nox directly, with Ruby support, the installation command in Ubuntu is as follows: sudo apt-get install vim-nox .

ruby extconf.rbIf the MKMF package is not found when the command is executed, you will need to install the Ruby-dev package and install the command under Ubuntu as follows: sudo apt-get install ruby1.8-dev .

Powerline1.

Https://github.com/Lokaltog/vim-powerline

2. Function description

Powerline is the vim of a very beautiful status bar plug-in, after the installation of Powerline, VIM will appear on the bottom of a enhanced status bar, when vim in normal, INSERT, block, etc., the status bar will be rendered different colors, The status bar also displays the format of the currently edited file (uft-8, etc.), the file type (Java, XML, and so on), and the cursor location, as you like.

3. Installation
    1. Go to .vim/bundle Catalog

    2. Performgit clone git://github.com/Lokaltog/vim-powerline.git

    3. .vimrcset the status bar theme in

      "Powerline{set guifont=powerlinesymbols\ for\ powerline Set nocompatible set t_co=256 let G:powerline_symbols = ' fancy '" }
4. Instructions for use

Once installed, turn on Vim again and you'll see that there's already a colored status bar on the bottom.

To be continued, the fourth chapter intends to talk about Ctags, TagList, Foldmethod, Xmledit, Visualmark, Vim-markdown and so on, the fifth is about Python, go-related plug-ins, the sixth chapter on VIM programming skills, seventh chapter ...


Who says VIM is not an IDE?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.