Image

Vim

How to auto-complete CSS syntax in Vim

By  •  Vim

Being the language used in website designs, CSS is one of the language supported by Vim’s auto-complete feature.

To start using the feature, enter the following while in Vim’s command mode.

:set omnifunc=csscomplete#CompleteCSS

That will enable CSS auto-completion in Vim. To use it, press Ctrl + x followed by Ctrl + o while partially typing CSS codes.

The following is a sample screenshot.

You can use the arrow key to navigate through the list to choose your desired auto-complete suggestion.

How to auto-complete PHP code in Vim

By  •  Vim

Vim is able to auto-complete syntax for some of the most popular programming languages, but it’s not enabled by default.

While in command mode, enter the following

:set omnifunc=phpcomplete#CompletePHP

To start using PHP auto completion, press the Ctrl + x followed by Ctrl + o keys while writing some PHP functions.

Below is an example screenshot when pressing Ctrl + x followed by Ctrl + o after typing dat

Do note the function description provided at the top of the screen.

How to use Vim auto-complete

By  •  Vim

Beginning version 7, Vim started to introduce its auto-complete feature. By default it works by being able to auto-complete words that already existed in the file being edited. If enabled, it can also auto-complete syntax for various programming languages.

To use the Vim auto-complete feature, just hit Ctrl + n while in insert mode, and you’ll get a list of word suggestions as in the following example;

To make the list cycle backwards, hit Ctrl + p. You can also use the arrow keys to move up and down the list.

How to enable auto complete for Python in Vim

By  •  Vim

Beginning version 7 of vim, it has this nice auto completion feature. It is by default however limited to words that has already been in the current workspace. To use it, simply press [ctrl] +n or [ctrl] + p key while in edit mode. For example:

We can however *teach* vim to autocomplete a whole bunch of other stuffs as well, by using something so called Dictionaries. With this idea we can have auto completion for Python, Ruby, PHP, Bash, and any other programming languages code.

For an example, let’s try to install Python dictionary, by downloading it from here:

http://www.vim.org/scripts/script.php?script_id=850

The next thing to do is to extract the downloaded file to the appropriate folder:

[email protected] ~ $ mkdir ~/.vim
[email protected] ~ $ tar xf pydiction-0.5.tar.gz -C ~/.vim

and add this lines to your ~/.vimrc (be sure to replace “/home/shakir” to your own home directory)

if has("autocmd")
    autocmd FileType python set complete+=k/home/shakir/.vim/pydiction-0.5/pydiction isk+=.,(
endif " has("autocmd"

and let’s see the result:

There are many other scripts available at Vim’s script page worth trying as well.

How to auto-complete JavaScript syntax in Vim

By  •  Vim

JavaScript is the scripting language for the web. Vim in the other hand is the editor of choice for many programmers. Being feature-rich, Vim is able to auto-complete JavaScript syntaxes. To use the feature, you’ll need to enable it first.

Enter the following while in Vim’s command mode to enable the feature.

:set omnifunc=javascriptcomplete#CompleteJS

You can now auto-complete JavaScript syntaxes by pressing Ctrl + x followed by Ctrl + o while partially typing JavaScript codes.

The following is a sample screenshot.

You can use the arrow key to navigate through the list to choose your desired auto-complete suggestion.

How to auto-complete HTML code in Vim

By  •  Vim

Vim can auto-complete syntax for popular programming languages, including HTML. It is however not enabled by default in most installation.

Entering the following while in Vim’s command mode will enable auto-completion for HTML language.

:set omnifunc=htmlcomplete#CompleteTags

To start using the feature, press Ctrl + x followed by Ctrl + o keys while writing HTML syntaxes.

The following screenshot is an example in auto-completing <!

You can use the arrow key to navigate through the list to choose your desired auto-complete suggestion.

How to change color scheme in Vim

By  •  Vim

Instead of displaying in just black and white text and background combo, Vim can display in other colors as well. This can be done by changing the color scheme.

To change the color scheme, follow any of the following methods;

How to enable line numbering in Vim

By  •  Vim

Vim has the ability to display line numbers on the left side of the text, but normally is not enabled by default.

You can set Vim to display line number by following any of the following methods;

How to enable syntax highlighting in Vim

By  •  Vim

Vim can perform syntax highlighting for various file formats. You can enable it with these steps if it’s not currently enabled;

  1. Make sure full version of Vim with support for syntax highlighting is installed.

  2. Manually enable syntax highlighting while in Vim.
    1. Enter command mode by pressing Esc.
    2. Type :syntax on|off and press Enter.

      :syntax on
  3. Manually set syntax for file if required.
    1. Enter command mode by pressing Esc
    2. Type :set syntax=<filetype> and press Enter.

      :set syntax=php
    3. To view the list of supported file types, issue :echo getcompletion while also in the command mode.

      :echo getcompletion('' 'filetype')
  4. Permanently enable syntax highlighting by adding :syntax on in your ~/.vimrc file.

Top