OpenSource For You

Explore gVim as an IDE

gVim is a text editor that meets everyone’s needs. It is a modified version of the Vi Editor that is shipped with UNIX. This article was inspired by the impact that gVim made upon the author after he had used it for a few weeks. It simplifies the task of

- By: Pritesh Manohar Ugrankar

In a previous article, we looked at how to install gVim along with Pathogen and Git. Let us begin today’s task with a few more installati­ons. • Vundle - To manage the plug-ins through Vim. • Lightline - To make a more informativ­e and better looking status bar. NERDTree – For a tree-like view of your files. Syntastic – A syntax-checking plug-in NeoComplCa­che - For auto completion. PerlOmni - The Perl Omnicomple­tion plug-in that we will use in tandem with the NeoComplCa­che plug-in.

Note: This article is for gVim version 7.4 on Windows 7. What’s shown here might or might not work through console Vim. Most of the settings given below are taken from the respective plug-in documentat­ion and modified as per my needs. You might need to tweak them according to your preference­s. The _vimrc options and other settings given below are exactly what I have been using for the past few days, so they should work. But in case they do not, please go through the settings documentat­ion or search the Net. I had to fiddle around with the Vundle settings to make it point to the correct folder, but everything else in the documentat­ion should work. If you know a better way of installing the plug-ins or configurin­g the settings, please do let me know. Like I said in the earlier article, I am no Vim expert.

Vundle: This plug-in is written by ‘Gmarik’. It allows the installati­on of plug-ins from within gVim itself. Vundle is meant to be used on a Linux or a UNIX system. We will have to make a few changes so that it works fine on Windows. Let’s first install Vundle, then make a few changes to the _vimrc and vundle.vim file, and take it ahead from there. Basically, rather than going to the command prompt and running the git clone command, we will use the :BundleInst­all command at the gVim command prompt to install the plug-ins.

Note: Ensure that you are in the bundle directory while running this command.

To install Vundle, run the following command:

git clone https://github.com/gmarik/vundle.git vundle

Here’s what it looks like on my laptop: C:\Users\Admin\Vim\vimfiles\bundle>git clone https://github. com/gmarik/vundle.git vundle Cloning into ‘vundle’... remote: Counting objects: 2484, done. remote: Compressin­g objects: 100% (1610/1610), done. remote: Total 2484 (delta 844), reused 2402 (delta 779) Receiving objects: 100% (2484/2484), 301.02 KiB | 124.00 KiB/s, done. Resolving deltas: 100% (844/844), done.

Checking connectivi­ty... done

Now, let’s check if the plug-in is installed correctly: C:\Users\Admin\Vim\vimfiles\bundle\vundle>dir Volume in drive C is Windows7_OS Volume Serial Number is 52DF-20FF

Directory of C:\Users\Admin\Vim\vimfiles\bundle\vundle 30-11-2013 18:16 <DIR>. 30-11-2013 18:16 <DIR>. 30-11-2013 18:16 22 .gitignore 30-11-2013 18:16 <DIR> autoload 30-11-2013 18:16 <DIR> doc 30-11-2013 18:16 1,075 LICENSE-MIT.txt 30-11-2013 18:16 4,577 README.md 30-11-2013 18:16 <DIR> test 3 File(s) 5,674 bytes 5 Dir(s) 102,582,751,232 bytes free

C:\Users\Admin\Vim\vimfiles\bundle\vundle>

The above output indicates that the plug-in has been installed correctly. Remember the _vimrc file we had modified in our first article? Add this under the Personal Settings section. These are required settings without which Vundle will not work as expected. Please look up the Vundle documentat­ion for more details/options. “Personal Settings. “More to be added soon. “Vundle settings start filetype off set rtp+=C:\Users\Admin\Vim\vimfiles\bundle\vundle call vundle#rc() Bundle ‘gmarik/vundle’ “Vundle settings end

Now let’s make a couple of changes in the vundle.vim file so that the plug-ins get correctly installed. This file is located under the ‘autoload’ folder under the ‘vundle’ folder (not the ‘autoload’ under ‘vimfiles’ folder, which is a different one). In my case, the ‘vundle.vim’ file is located as shown below:

C:\Users\Admin\Vim\vimfiles\bundle\vundle\autoload\vundle.vim

Copy the file and save it with a different name in the same location so that in case something goes wrong, we can revert to it. This is the file we will not touch. I have named it ‘vundle_ orig.vim’. You can give it any name. Now, open the ‘vundle. vim’ file and at line 43, you will find the following text:

let g:bundle_dir = len(a:000) > 0 ? expand(a:1, 1) :

expand('$HOME/.vim/bundle', 1)

Change the ‘$HOME/.vim/bundle’ to wherever you have the ‘bundle’ folder. In my case, it's ‘C:\Users\Admin\Vim\ vimfiles\bundle’. Note the single quotes—they are required. After making the change, the line will look like what follows: let g:bundle_dir = len(a:000) > 0 ? expand(a:1, 1) : expand(‘C:\Users\Admin\Vim\vimfiles\bundle’, 1)

Save the vundle.vim file. Now open gVim. If you get any errors, please recheck if you’ve followed the steps correctly. We will now install the plug-ins using Vundle. You can still use Pathogen if you want to, but I like the way Vundle lets me install the plug-ins from gVim itself. Plug-ins can be removed or cleaned using Vundle, and you can include the plug-in names in the _vimrc file to install them.

For example, we can install all the plug-ins given in here at one go by adding the following to _vimrc and running the :BundleInst­all command by itself: “Extra Bundles Bundle ‘itchyny/lightline.vim’ Bundle ‘scrooloose/nerdtree’ Bundle ‘scrooloose/syntastic’ Bundle ‘Shougo/neocomplca­che.vim’ Bundle ‘c9s/perlomni.vim’ But for now, we will install these one by one, as shown below. Vim lightline: This plug-in has been written by ‘itchyny’. It enhances the status bar and shows a lot of useful informatio­n. It’s an excellent plug-in. Go to github.com and search for Vim lightline. Click on the first link there so that it leads you to https://github.com/itchyny

Now, open gVim and type the following at the command mode:

:BundleInst­all ‘itchyny/lightline.vim’

You will see some message in the status bar stating ‘processing’ and so on. Once it’s installed, it will show a ‘Done’ message. Whenever you install any plug-ins, you have to just put in the plug-in name right after the BundleInst­all command.

Reopen gVim and you’ll see a nice Status line. Depending on the mode you are in and the file you have opened, the status bar will change colour and show the mode, the file name, the file type and some more informatio­n.

If you want to turn off the status mode that appears below the status bar, add the ‘set noshowmode’ option in your _vimrc.

Syntastic: This plug-in has been written by ‘Scrooloose’. Once again, go to github.com and search for the keyword ‘syntastic’ or type :BundleInst­all at the command mode, and then type syntastic. Tab completion works for many of the

bundles, including this one, so try that out.

Given below are the Syntastic settings I have added in my _vimrc. You might have to change some of them, depending on your settings. “Syntastic Settings set statusline+=%#warningmsg# set statusline+=%{SyntasticS­tatuslineF­lag()} set statusline+=%* let g:syntastic_check_on_open=1 let g:syntastic_enable_balloons=1 let g:syntastic_always_populate_loc_list=1 let g:syntastic_echo_current_error=1 let g:syntastic_enable_highlighti­ng=1 let g:syntastic_auto_jump=1 let g:syntastic_auto_loc_list=1 let g:syntastic_loc_list_height=5 let g:syntastic_perl_checkers=[‘perl’ , ‘perlcritic’] let g:syntastic_id_checkers=1 let g:syntastic_python_checkers=[‘python’, ‘pyflakes’] “Enable below in case you want the error line highlighte­d highlight SyntasticE­rrorLine guibg=#6D6968 highlight SyntasticW­arningLine guibg=#6D6968 “Sytanstic Error Signs” let g:syntastic_error_symbol=”E>” let g:syntastic_warning_symbol=”W>” “End of Syntastic Settings

NERDTree: This plug-in also has been written by ‘Scrooloose’. It gives a nice treelike view of the files you are in.

Install it using Vundle as follows: :BundleInst­all ‘scrooloose/nerdtree’. Once done, add the following settings in the _vimrc. “NERDTree Settings “Open gVim with NERDTree autocmd vimenter * if !argc() | NERDTree | endif “Close NERDTree if the last file is closed. autocmd bufenter * if (winnr(“$”) == 1 && exists(“b:NERDTreeTy­pe”) && b:NERDTreeTy­pe == “primary”) | q | endif “Give a nice look to NERDTree let NERDChrist­masTree = 1 “Show nice arrows instead of + scriptenco­ding utf-8 set encoding=utf-8 let NERDTreeDi­rArrows = 1

Check out the screenshot­s in Figure 1. Just save the script file with a ‘:w’ in the command prompt and the errors/ warnings will show up.

NeoComplCa­che: This plug-in has been written by ‘Shougo’. This has the ‘autocomple­te as you type’ feature to gVim, giving that final touch to the IDE-like behaviour. Type :BundleInst­all ‘Shougo/neocomplca­che.vim’ in the command mode and you are done! I have disabled the auto turn-on for the NeoComplCa­che plug-in so it does not kick off right after gVim loads. Type :NeoComplCa­cheEnable at the gVim command prompt and then you can start using it. Alternativ­ely, change the set Neocomplca­che_enable_at_ startup to 1 instead of 0.

PerlOmni: This plug-in has been written by Pedro. If you are into Perl Scripting, the PerlOmni plug-in will be quite helpful. Search Github and do a BundleInst­all to get it installed; otherwise, just disable the perlomni settings (the last two lines in the code snippet below) if you don’t install it.

The _vimrc settings given below are for both NeoComplCa­che and PerlOmni. “NeoComplCa­che settings. let g:acp_enableAtSt­artup = 0 “Use neocomplca­che. let g:neocomplca­che_enable_at_startup = 0 “Use smartcase. let g:neocomplca­che_enable_smart_case = 1 “Set minimum syntax keyword length. let g:neocomplca­che_min_syntax_length = 3 let g:neocomplca­che_lock_buffer_name_pattern = ‘\*ku\*’ “Define keyword. if !exists(‘g:neocomplca­che_keyword_patterns’)

let g:neocomplca­che_keyword_patterns = {} endif let g:neocomplca­che_keyword_patterns[‘default’] = ‘\h\w*’ “Recommende­d key-mappings. “<CR>: close popup and save indent. inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR> function! s:my_cr_function() return neocomplca­che#smart_close_popup() . “\<CR>” “For no inserting <CR> key. “return pumvisible() ? neocomplca­che#close_popup() : “\<CR>” endfunctio­n “<TAB>: completion. inoremap <expr><TAB> pumvisible() ? “\<C-n>” : “\<TAB>” “<C-h>, <BS>: close popup and delete backword char. inoremap <expr><C-h> neocomplca­che#smart_close_ popup().”\<C-h>” inoremap <expr><BS> neocomplca­che#smart_close_ popup().”\<C-h>” inoremap <expr><C-y> neocomplca­che#close_popup() inoremap <expr><C-e> neocomplca­che#cancel_popup() “Close popup by <Space>. “inoremap <expr><Space> pumvisible() ? neocomplca­che#close_ popup() : “\<Space>” “Enable omni completion. autocmd FileType css setlocal omnifunc=csscomplet­e#CompleteC SS

autocmd FileType html,markdown setlocal omnifunc=htmlcomple­te #CompleteTa­gs autocmd FileType javascript setlocal omnifunc=javascript­compl ete#CompleteJS autocmd FileType python setlocal omnifunc=pythoncomp­lete#Com plete autocmd FileType xml setlocal omnifunc=xmlcomplet­e#CompleteT ags “Enable heavy omni completion. if !exists(‘g:neocomplca­che_omni_patterns’)

let g:neocomplca­che_omni_patterns = {} endif let g:neocomplca­che_omni_patterns.php = ‘[^. \t]->\h\w*\|\ h\w*::’ let g:neocomplca­che_omni_patterns.c = ‘[^.[:digit:] *\t]\%(\.\|->\)’ let g:neocomplca­che_omni_patterns.cpp = ‘[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::’ “For perlomni.vim setting. “https://github.com/c9s/perlomni.vim let g:neocomplca­che_omni_patterns.perl = ‘\h\w*->\|\h\w*>\h\w*\|\h\w*::\|\h\w*::\h\w*’

There are a few more settings to make your Vim experience more enriching.

Clear off the search highlights: This helps to clear off the search highlights. Just hit the F3 key when you want to disable the highlight. Hit it once again to turn it on. Just add the following code to your _vimrc file: “Press <F3> to disable/enable search highlight nnoremap <F3> :set hlsearch!<CR>

You might want to disable the movement of arrows while using the Normal or Insert mode. Here are the _vimrc settings to do that. Comment it out if you don’t like it or remove it; that’s up to you. “Disable arrows keys. Inoremap <Up> <NOP> inoremap <Down> <NOP> inoremap <Left> <NOP> inoremap <Right> <NOP> noremap <Up> <NOP> noremap <Down> <NOP> noremap <Left> <NOP> noremap <Right> <NOP> Need the current line background highlighte­d? No issues. Just stick ‘set cul’ somewhere in the _vimrc and it will highlight the line the cursor currently is at. Here's my _vimrc file. Its got all the settings given here in this article- https://github.com/pmugit/ osfygvim/blob/master/_vimrc Go ahead and use it in case the options you added by hand don't work. That's all for now. The author’s interest in gVim was born after using it for a few weeks and he has blogged about it at http://nomadbyte. wordpress.com. This and the previous article were originally part of a small text file that the author kept for his own reference. You can reach him at pmu.rwx@gmail.com.

 ??  ??
 ??  ??
 ??  ??
 ??  ?? Figure 1 : NERDTree Syntastic
Figure 1 : NERDTree Syntastic
 ??  ??

Newspapers in English

Newspapers from India