Showing posts with label Vim. Show all posts
Showing posts with label Vim. Show all posts

Saturday, January 4, 2014


Eventhough there are more than one way to compile/execute programs in Vim/Gvim, the normal method to compile and execute C,C++,Java,Python programs are:

C:

 !gcc % -o %:r
 !./%:r

C++:

!g++ % -o %:r
!./%:r

Python:

!python %

Java:

!javac %
!java %:r

To do all these things you've to type the commands repeatedly everytime you want to compile and execute. To prove the laziness of a programmer, there's a way to do all these things by pressing a single key in Vim/Gvim.

First of all check if you have ~/.vimrc, if you don't have create one using this command :
nano ~/.vimrc

Now after creating this, put the following commands in your .vimrc :

autocmd filetype python nnoremap <F4> :w <bar> exec '!python '.shellescape('%')<CR>
autocmd filetype c nnoremap <F5> :w <bar> exec '!gcc '.shellescape('%').' -o '.shellescape('%:r').' && ./'.shellescape('%:r')<CR>
autocmd filetype cpp nnoremap <F6> :w <bar> exec '!g++ '.shellescape('%').' -o '.shellescape('%:r').' && ./'.shellescape('%:r')<CR>
autocmd filetype java nnoremap <F7> :w <bar> exec '!javac '.shellescape('%').' && java '.shellescape('%:r')<CR>

Here's a screenshot of compiling a program in Vim/Gvim :



If you want to know the execution time of your program too, then use the following code instead of the previous one :


autocmd filetype python nnoremap <F4> :w <bar> exec '!time python '.shellescape('%')<CR>
autocmd filetype c nnoremap <F5> :w <bar> exec '!gcc '.shellescape('%').' -o '.shellescape('%:r').' && time ./'.shellescape('%:r')<CR>
autocmd filetype cpp nnoremap <F6> :w <bar> exec '!g++ '.shellescape('%').' -o '.shellescape('%:r').' && time ./'.shellescape('%:r')<CR>
autocmd filetype java nnoremap <F7> :w <bar> exec '!javac '.shellescape('%').' && time java '.shellescape('%:r')<CR>

To compile and execute the programs, press:
F4 for Python
F5 for C
F6 for C++
F7 for Java



You can change the default key-mappings, just make sure that it didn't conflict with the original Vim/Gvim key-mappings.
That's it enjoy your programming in Vim.

Sunday, December 29, 2013

GVim
GVim
The default syntax highlighting VIM Editor is not that much upto the expectation of the programmers. It's also one of my favourite text editor. So, i've modified the original source code of the syntax highlighting files of the VIm  and able to improved it.

I'm going to share the improved syntax highlighting  files. So, please download the files from my GIT repository. Languages for syntax highlighting  that i've modified are Python, C , C++, JAVA.
and i would like to encourage you to contribute in it which is hosted in GITHUB.

Please clone the following GIT repository :


or download the zip file from here.

Screenshots after using the changed original files:

Python:



C++ :

      


C :



JAVA: