tutorial on adding a status hint bar to the command line interface and VIM in Mac OS

Source: Internet
Author: User
Tags git clone

What is powerline

If you're not searching through a search engine for this article, you may not have heard of powerline. And you happen to be a *unix party, or vim party, so strongly suggest you understand and use powerline. Powerline is a stateless status line, a global status/hint bar. If you succeed in powerline for your bash,terminal,iterm2,vim configuration, then the effect will be this:

The prompt for bash will be like this:

Vim's status bar will be like this:

Vim's overall effect chart:

I believe that after watching the above several screenshots, the function of powerline is self-evident. He provides a status hint for each app in every environment, which greatly improves productivity.

Start installing Powerline on Mac

First we need to download and install powerline. Before the formal installation, a few words of powerline code structure, GitHub on the powerline project covers a variety of app (Bash,vim, etc.) code. Therefore, you can download the code package from anywhere in the Mac, and then use the same path for different app configurations to load in plugin form. In order to facilitate the reader's selective installation, this article will separately give the installation path and configuration for different programs.

First determine that the native environment has a set of versions greater than or equal to 2.7 of the Python environment. If there is no suitable environment, can be installed through the homebrew, there is no more to repeat.

The code is as follows:

Shell> python-v

Python 2.7.9

Then install powerline via PIP:

The code is as follows:

shell> pip Install Powerline-status[code]

After the installation is complete, view the specific path of the powerline through the PIP show Powerline-status. Note: This path is important and will be used in the following configuration steps:

[code]shell> PIP Show Powerline-status

Name:powerline-status

version:2.0

Location:/library/python/2.7/site-packages

Requires:

Configure Bash to use powerline

The configuration method is simple, just add a line to the bindings/bash/powerline.sh in the Bash configuration file (for example:/etc/bashrc,~/.bashrc,~/.bash_profile) to invoke the installation path. This will automatically execute the contents of the powerline.sh file each time a new bash window is generated. Here's an example of ~/.bash_profile:

The code is as follows:

shell> echo << EOF >> ~/.bash_profile

. /library/python/2.7/site-packages/powerline/bindings/bash/powerline.sh

Eof

Shell>. /library/python/2.7/site-packages/powerline/bindings/bash/powerline.sh

Note: Depending on how Python is installed, your powerline path may also be different. If you are installing Python via the Python website or the Apple Store, then your powerline installation path is/library/python/2.7/site-packages/powerline/. If you are using brew install Python, your powerline path may be different. Please revise the above order according to the actual situation.

Teriminal Font Configuration

After performing the above two steps, no accident powerline has begun to work. But you'll find that the bash prompt will be some very disgusting symbol like the following image.

The reason for this is that powerline has made some symbols for the sake of beauty, and these symbols are not in the Unicode font (if you do not know what the Unicode font is, you can look at the previous blogger's introduction). So if you want to powerline the normal display, you need to install the specially processed fonts. Fortunately, with the help of an enthusiastic person, he put most of the program ape commonly used in the same width of the font is Powerline patch make our configuration will be extremely simple. First we download and install fonts from GitHub:

The code is as follows:

shell> git clone https://github.com/powerline/fonts.git

Shell> CD Fonts

Shell>./install.sh

After the installation is complete, we can see and select multiple XXX for powerline fonts in the ITerm2 or terminal font options. * Note: For both ASCII fonts and non-ascii fonts, you need to select a for powerline font. The following figure:

Vim related configuration

In this section we will describe how to configure powerline for Vim. First you need to make sure that your vim turns on Python support at compile time. If there is no result through Python--version|grep +python, then you need to recompile the installation vim through brew install vim--with-python--with-ruby--with-perl Or install Macvim using the Brew install Macvim--env-std--override-system-vim.

Then, you only need to add the following part to the ~/.VIMRC, vim can load the powerline function normally:

Note: The set Rtp+=/library/python/2.7/site-packages/powerline/bindings/vim and above need to be adjusted according to their own actual situation.

The code is as follows:

Set Rtp+=/library/python/2.7/site-packages/powerline/bindings/vim

"These lines are setup the environment to show graphics and colors correctly.

Set nocompatible

Set t_co=256

Let g:minbufexplforcesyntaxenable = 1

Python from Powerline.vim import setup as Powerline_setup

Python Powerline_setup ()

Python del Powerline_setup

if! Has (' gui_running ')

Set ttimeoutlen=10

Augroup Fastescape

autocmd!

Au Insertenter * Set timeoutlen=0

Au Insertleave * Set timeoutlen=1000

Augroup End

endif

Set laststatus=2 "Always display" Statusline in all windows

Set Guifont=inconsolata for powerline:h14

Set Noshowmode "Hide The default mode text (e.g.--INSERT--below the Statusline)

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.