Ex­plore gVim as an IDE

gVim is a text ed­i­tor that meets ev­ery­one’s needs. It is a mod­i­fied ver­sion of the Vi Ed­i­tor that is shipped with UNIX. This ar­ti­cle was in­spired by the im­pact that gVim made upon the au­thor af­ter he had used it for a few weeks. It sim­pli­fies the task of

OpenSource For You - - CONTENTS - By: Pritesh Manohar Ugrankar

In a pre­vi­ous ar­ti­cle, we looked at how to in­stall gVim along with Pathogen and Git. Let us be­gin today’s task with a few more in­stal­la­tions. • Vun­dle - To man­age the plug-ins through Vim. • Light­line - To make a more in­for­ma­tive and bet­ter look­ing sta­tus bar. NERDTree – For a tree-like view of your files. Syn­tas­tic – A syn­tax-check­ing plug-in NeoCom­plCache - For auto com­ple­tion. Per­lOmni - The Perl Om­ni­com­ple­tion plug-in that we will use in tan­dem with the NeoCom­plCache plug-in.

Note: This ar­ti­cle is for gVim ver­sion 7.4 on Win­dows 7. What’s shown here might or might not work through con­sole Vim. Most of the set­tings given be­low are taken from the re­spec­tive plug-in doc­u­men­ta­tion and mod­i­fied as per my needs. You might need to tweak them ac­cord­ing to your pref­er­ences. The _vimrc op­tions and other set­tings given be­low are ex­actly what I have been us­ing for the past few days, so they should work. But in case they do not, please go through the set­tings doc­u­men­ta­tion or search the Net. I had to fid­dle around with the Vun­dle set­tings to make it point to the cor­rect folder, but ev­ery­thing else in the doc­u­men­ta­tion should work. If you know a bet­ter way of in­stalling the plug-ins or con­fig­ur­ing the set­tings, please do let me know. Like I said in the ear­lier ar­ti­cle, I am no Vim ex­pert.

Vun­dle: This plug-in is writ­ten by ‘Gmarik’. It al­lows the in­stal­la­tion of plug-ins from within gVim it­self. Vun­dle is meant to be used on a Linux or a UNIX sys­tem. We will have to make a few changes so that it works fine on Win­dows. Let’s first in­stall Vun­dle, then make a few changes to the _vimrc and vun­dle.vim file, and take it ahead from there. Ba­si­cally, rather than go­ing to the com­mand prompt and run­ning the git clone com­mand, we will use the :BundleIn­stall com­mand at the gVim com­mand prompt to in­stall the plug-ins.

Note: En­sure that you are in the bun­dle di­rec­tory while run­ning this com­mand.

To in­stall Vun­dle, run the fol­low­ing com­mand:

git clone https://github.com/gmarik/vun­dle.git vun­dle

Here’s what it looks like on my lap­top: C:\Users\Ad­min\Vim\vim­files\bun­dle>git clone https://github. com/gmarik/vun­dle.git vun­dle Cloning into ‘vun­dle’... re­mote: Count­ing ob­jects: 2484, done. re­mote: Com­press­ing ob­jects: 100% (1610/1610), done. re­mote: To­tal 2484 (delta 844), reused 2402 (delta 779) Re­ceiv­ing ob­jects: 100% (2484/2484), 301.02 KiB | 124.00 KiB/s, done. Re­solv­ing deltas: 100% (844/844), done.

Check­ing con­nec­tiv­ity... done

Now, let’s check if the plug-in is in­stalled cor­rectly: C:\Users\Ad­min\Vim\vim­files\bun­dle\vun­dle>dir Vol­ume in drive C is Win­dows7_OS Vol­ume Se­rial Num­ber is 52DF-20FF

Di­rec­tory of C:\Users\Ad­min\Vim\vim­files\bun­dle\vun­dle 30-11-2013 18:16 <DIR>. 30-11-2013 18:16 <DIR>. 30-11-2013 18:16 22 .git­ig­nore 30-11-2013 18:16 <DIR> au­toload 30-11-2013 18:16 <DIR> doc 30-11-2013 18:16 1,075 LI­CENSE-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


The above out­put in­di­cates that the plug-in has been in­stalled cor­rectly. Re­mem­ber the _vimrc file we had mod­i­fied in our first ar­ti­cle? Add this un­der the Per­sonal Set­tings sec­tion. These are re­quired set­tings without which Vun­dle will not work as ex­pected. Please look up the Vun­dle doc­u­men­ta­tion for more de­tails/op­tions. “Per­sonal Set­tings. “More to be added soon. “Vun­dle set­tings start file­type off set rtp+=C:\Users\Ad­min\Vim\vim­files\bun­dle\vun­dle call vun­dle#rc() Bun­dle ‘gmarik/vun­dle’ “Vun­dle set­tings end

Now let’s make a cou­ple of changes in the vun­dle.vim file so that the plug-ins get cor­rectly in­stalled. This file is lo­cated un­der the ‘au­toload’ folder un­der the ‘vun­dle’ folder (not the ‘au­toload’ un­der ‘vim­files’ folder, which is a dif­fer­ent one). In my case, the ‘vun­dle.vim’ file is lo­cated as shown be­low:


Copy the file and save it with a dif­fer­ent name in the same lo­ca­tion so that in case some­thing goes wrong, we can re­vert 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 ‘vun­dle. vim’ file and at line 43, you will find the fol­low­ing text:

let g:bundle_dir = len(a:000) > 0 ? ex­pand(a:1, 1) :

ex­pand('$HOME/.vim/bun­dle', 1)

Change the ‘$HOME/.vim/bun­dle’ to wher­ever you have the ‘bun­dle’ folder. In my case, it's ‘C:\Users\Ad­min\Vim\ vim­files\bun­dle’. Note the sin­gle quotes—they are re­quired. Af­ter mak­ing the change, the line will look like what fol­lows: let g:bundle_dir = len(a:000) > 0 ? ex­pand(a:1, 1) : ex­pand(‘C:\Users\Ad­min\Vim\vim­files\bun­dle’, 1)

Save the vun­dle.vim file. Now open gVim. If you get any er­rors, please recheck if you’ve fol­lowed the steps cor­rectly. We will now in­stall the plug-ins us­ing Vun­dle. You can still use Pathogen if you want to, but I like the way Vun­dle lets me in­stall the plug-ins from gVim it­self. Plug-ins can be re­moved or cleaned us­ing Vun­dle, and you can in­clude the plug-in names in the _vimrc file to in­stall them.

For ex­am­ple, we can in­stall all the plug-ins given in here at one go by adding the fol­low­ing to _vimrc and run­ning the :BundleIn­stall com­mand by it­self: “Ex­tra Bun­dles Bun­dle ‘itchyny/light­line.vim’ Bun­dle ‘scrooloose/nerdtree’ Bun­dle ‘scrooloose/syn­tas­tic’ Bun­dle ‘Shougo/neocom­plcache.vim’ Bun­dle ‘c9s/per­lomni.vim’ But for now, we will in­stall these one by one, as shown be­low. Vim light­line: This plug-in has been writ­ten by ‘itchyny’. It en­hances the sta­tus bar and shows a lot of use­ful in­for­ma­tion. It’s an ex­cel­lent plug-in. Go to github.com and search for Vim light­line. Click on the first link there so that it leads you to https://github.com/itchyny

Now, open gVim and type the fol­low­ing at the com­mand mode:

:BundleIn­stall ‘itchyny/light­line.vim’

You will see some mes­sage in the sta­tus bar stat­ing ‘pro­cess­ing’ and so on. Once it’s in­stalled, it will show a ‘Done’ mes­sage. When­ever you in­stall any plug-ins, you have to just put in the plug-in name right af­ter the BundleIn­stall com­mand.

Re­open gVim and you’ll see a nice Sta­tus line. Depend­ing on the mode you are in and the file you have opened, the sta­tus bar will change colour and show the mode, the file name, the file type and some more in­for­ma­tion.

If you want to turn off the sta­tus mode that ap­pears be­low the sta­tus bar, add the ‘set noshow­mode’ op­tion in your _vimrc.

Syn­tas­tic: This plug-in has been writ­ten by ‘Scrooloose’. Once again, go to github.com and search for the key­word ‘syn­tas­tic’ or type :BundleIn­stall at the com­mand mode, and then type syn­tas­tic. Tab com­ple­tion works for many of the

bun­dles, in­clud­ing this one, so try that out.

Given be­low are the Syn­tas­tic set­tings I have added in my _vimrc. You might have to change some of them, depend­ing on your set­tings. “Syn­tas­tic Set­tings set sta­tusline+=%#warn­ingmsg# set sta­tusline+=%{Syn­tas­ticS­ta­tuslineFlag()} set sta­tusline+=%* let g:syn­tas­tic_check­_on_open=1 let g:syn­tas­tic_en­able_bal­loons=1 let g:syn­tas­tic_al­ways_pop­u­late_loc_list=1 let g:syn­tas­tic_e­cho_cur­ren­t_er­ror=1 let g:syn­tas­tic_en­able_high­light­ing=1 let g:syn­tas­tic_au­to_jump=1 let g:syn­tas­tic_au­to_loc_list=1 let g:syn­tas­tic_loc_list_height=5 let g:syn­tas­tic_per­l_check­ers=[‘perl’ , ‘perl­critic’] let g:syn­tas­tic_id_check­ers=1 let g:syn­tas­tic_python_check­ers=[‘python’, ‘pyflakes’] “En­able be­low in case you want the er­ror line high­lighted high­light Syn­tas­ticEr­rorLine guibg=#6D6968 high­light Syn­tas­ticWarn­ingLine guibg=#6D6968 “Sy­tanstic Er­ror Signs” let g:syn­tas­tic_er­ror_sym­bol=”E>” let g:syn­tas­tic_warn­ing_sym­bol=”W>” “End of Syn­tas­tic Set­tings

NERDTree: This plug-in also has been writ­ten by ‘Scrooloose’. It gives a nice tree­like view of the files you are in.

In­stall it us­ing Vun­dle as fol­lows: :BundleIn­stall ‘scrooloose/nerdtree’. Once done, add the fol­low­ing set­tings in the _vimrc. “NERDTree Set­tings “Open gVim with NERDTree au­tocmd vi­menter * if !argc() | NERDTree | en­dif “Close NERDTree if the last file is closed. au­tocmd bufen­ter * if (winnr(“$”) == 1 && ex­ists(“b:NERDTreeType”) && b:NERDTreeType == “pri­mary”) | q | en­dif “Give a nice look to NERDTree let NERDChrist­masTree = 1 “Show nice ar­rows in­stead of + scrip­ten­cod­ing utf-8 set en­cod­ing=utf-8 let NERDTreeDirAr­rows = 1

Check out the screen­shots in Fig­ure 1. Just save the script file with a ‘:w’ in the com­mand prompt and the er­rors/ warn­ings will show up.

NeoCom­plCache: This plug-in has been writ­ten by ‘Shougo’. This has the ‘au­to­com­plete as you type’ fea­ture to gVim, giv­ing that fi­nal touch to the IDE-like be­hav­iour. Type :BundleIn­stall ‘Shougo/neocom­plcache.vim’ in the com­mand mode and you are done! I have dis­abled the auto turn-on for the NeoCom­plCache plug-in so it does not kick off right af­ter gVim loads. Type :NeoCom­plCacheEn­able at the gVim com­mand prompt and then you can start us­ing it. Al­ter­na­tively, change the set Neo­com­plcache_en­able_at_ startup to 1 in­stead of 0.

Per­lOmni: This plug-in has been writ­ten by Pe­dro. If you are into Perl Script­ing, the Per­lOmni plug-in will be quite help­ful. Search Github and do a BundleIn­stall to get it in­stalled; oth­er­wise, just dis­able the per­lomni set­tings (the last two lines in the code snip­pet be­low) if you don’t in­stall it.

The _vimrc set­tings given be­low are for both NeoCom­plCache and Per­lOmni. “NeoCom­plCache set­tings. let g:acp_en­ableAtS­tartup = 0 “Use neocom­plcache. let g:neo­com­plcache_en­able_at_s­tartup = 0 “Use smart­case. let g:neo­com­plcache_en­able_s­mart_­case = 1 “Set min­i­mum syn­tax key­word length. let g:neo­com­plcache_min_syn­tax_length = 3 let g:neo­com­plcache_lock­_buffer­_­name_­pat­tern = ‘\*ku\*’ “De­fine key­word. if !ex­ists(‘g:neo­com­plcache_key­word_­pat­terns’)

let g:neo­com­plcache_key­word_­pat­terns = {} en­dif let g:neo­com­plcache_key­word_­pat­terns[‘de­fault’] = ‘\h\w*’ “Rec­om­mended key-map­pings. “<CR>: close popup and save in­dent. in­oremap <silent> <CR> <C-r>=<SID>my_cr_­func­tion()<CR> func­tion! s:my_cr_­func­tion() re­turn neocom­plcache#smart_­close_popup() . “\<CR>” “For no in­sert­ing <CR> key. “re­turn pumvis­i­ble() ? neocom­plcache#close_popup() : “\<CR>” end­func­tion “<TAB>: com­ple­tion. in­oremap <expr><TAB> pumvis­i­ble() ? “\<C-n>” : “\<TAB>” “<C-h>, <BS>: close popup and delete back­word char. in­oremap <expr><C-h> neocom­plcache#smart_­close_ popup().”\<C-h>” in­oremap <expr><BS> neocom­plcache#smart_­close_ popup().”\<C-h>” in­oremap <expr><C-y> neocom­plcache#close_popup() in­oremap <expr><C-e> neocom­plcache#can­cel_popup() “Close popup by <Space>. “in­oremap <expr><Space> pumvis­i­ble() ? neocom­plcache#close_ popup() : “\<Space>” “En­able omni com­ple­tion. au­tocmd File­Type css set­lo­cal om­ni­func=css­com­plete#Com­pleteC SS

au­tocmd File­Type html,mark­down set­lo­cal om­ni­func=html­com­plete #Com­pleteTags au­tocmd File­Type javascript set­lo­cal om­ni­func=javascript­compl ete#Com­pleteJS au­tocmd File­Type python set­lo­cal om­ni­func=python­com­plete#Com plete au­tocmd File­Type xml set­lo­cal om­ni­func=xml­com­plete#Com­pleteT ags “En­able heavy omni com­ple­tion. if !ex­ists(‘g:neo­com­plcache_om­ni_­pat­terns’)

let g:neo­com­plcache_om­ni_­pat­terns = {} en­dif let g:neo­com­plcache_om­ni_­pat­terns.php = ‘[^. \t]->\h\w*\|\ h\w*::’ let g:neo­com­plcache_om­ni_­pat­terns.c = ‘[^.[:digit:] *\t]\%(\.\|->\)’ let g:neo­com­plcache_om­ni_­pat­terns.cpp = ‘[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::’ “For per­lomni.vim set­ting. “https://github.com/c9s/per­lomni.vim let g:neo­com­plcache_om­ni_­pat­terns.perl = ‘\h\w*->\|\h\w*>\h\w*\|\h\w*::\|\h\w*::\h\w*’

There are a few more set­tings to make your Vim ex­pe­ri­ence more en­rich­ing.

Clear off the search high­lights: This helps to clear off the search high­lights. Just hit the F3 key when you want to dis­able the high­light. Hit it once again to turn it on. Just add the fol­low­ing code to your _vimrc file: “Press <F3> to dis­able/en­able search high­light nnoremap <F3> :set hlsearch!<CR>

You might want to dis­able the move­ment of ar­rows while us­ing the Nor­mal or In­sert mode. Here are the _vimrc set­tings to do that. Comment it out if you don’t like it or re­move it; that’s up to you. “Dis­able ar­rows keys. In­oremap <Up> <NOP> in­oremap <Down> <NOP> in­oremap <Left> <NOP> in­oremap <Right> <NOP> noremap <Up> <NOP> noremap <Down> <NOP> noremap <Left> <NOP> noremap <Right> <NOP> Need the cur­rent line back­ground high­lighted? No is­sues. Just stick ‘set cul’ some­where in the _vimrc and it will high­light the line the cur­sor cur­rently is at. Here's my _vimrc file. Its got all the set­tings given here in this ar­ti­cle- https://github.com/pmugit/ os­fygvim/blob/master/_vimrc Go ahead and use it in case the op­tions you added by hand don't work. That's all for now. The au­thor’s in­ter­est in gVim was born af­ter us­ing it for a few weeks and he has blogged about it at http://no­mad­byte. word­press.com. This and the pre­vi­ous ar­ti­cle were orig­i­nally part of a small text file that the au­thor kept for his own ref­er­ence. You can reach him at [email protected]

Fig­ure 1 : NERDTree Syn­tas­tic

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.