Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

2011-06-27

Some Customizations on the Blog for Displaying and Printing, Vim Helps

I have made some theme customizations and modified two previous posts targeting less JavaScript requirements, shorter load time and some aesthetic.

I save web pages. I always do. I do not bookmark everything, but I print pages in PDF format. This way I can read them later, without making my bookmarks fat. They are already fat enough. I see my readings as my data, and I want to store them. And I go angry against unprintable, very very long pages. I also use ScreenGrab to store the screen-shot of a web page, but it can get stuck with the long web pages.

And I was thinking, my simple blog should be easily printable too. But it was not. Sadly, it seems that Blogger pages(may be not Blogger, but all the themes I have ever used in Blogger) can not be completely printed. Also I am a PasteBin user, and I have used its feature of embedding code pieces to the blog. But that made printing much more difficult. Without PasteBin code embedding, a great site, PrintFriendly, was able to print, but with embedded code from PasteBin, even PrintFriendly could not print the pages. So, I have decided to modify the blog, and make it printable as much as possible.

The first was to remove the embedded code from PasteBin and directly putting the code inside the blog post body. This way I could also control the colors.

As I am a Vim user, it is not difficult to find a cool Vim plugin, ScreenShot.vim to convert code pieces to HTML. By this way, I can easily convert a portion of code to HTML. The output of ScreenShot.vim is different from the built-in "TOhtml" command. ScreenShot.vim provides 3 commands essentially.

Screenshot : Just like it says, it takes the screenshot of the Vim window.
Its output looks like this:

 31 # This is only the file name:
 32 db_name = "our_db.sqlite"
 33 
 34 # The protocol and full path to our database
 35 db = DAL('sqlite://' + db_name, folder=modul

 36 
 37 # Define the table "genre", note that the fi
 38 db.define_table("genre",
 39         Field("name"))

 40 db.genre.name.requires = IS_NOT_EMPTY()
 41 
 42 # Define the table "band", note that the fie
 43 # band.genre_id references to genre.id field
 44 db.define_table("band",

 45         Field("name"), 
raw.py                        40,1           42%


Second command, Text2Html, converts the selected text to HTML. Looks like the built-in TOhtml command, but, TOhtml command creates a page with <html>, <head> etc. On the other hand, Text2Html command creates a portion of an HTML page, starting with a <table> and ending with a </table>, ready to embed in the blog post body or somewhere else. See a modified, previous blog post to have an idea on how it looks like. This is the command I will be using frequently from now on.

And the third command, Diff2Html is used to display two files comparing with differences highlighted.

Also there had been some color inconsistencies in this blog, but finally there will be no more. I will be using Molokai color scheme for Vim, based on Monokai for TextMate, since I like it much and goes very well with the current dark theme of the blog.

The ScreenShot.vim plugin is configurable. Read its script page for more options. Here are my settings from my vimrc targeting saving the maximum screen space:

let g:ScreenShot = { 
    \ 'Title' : 0, 
    \ 'Icon' : 0, 
    \ 'Credits' : 0, 
    \} 

Note that I have deleted the line numbers in the code above using Vim, it has no configuration in ScreenShot.vim it seems, but was a piece of cake using Vim's columnar editing.

Want to see it on PrintFriendly.com? Click here. It will remove the gadgets and other giggling things, and you will see clean, printable version of this blog post. I highly recommend PrintFriendly by the way.

After this modifications, the blog site is faster, more accessible, has more width in the layout, will display anyway if you use a JavaScript blocker like NoScript and it looks better. Have an advice? You are welcome.

2011-03-31

Running Vim from Eclipse IDE

I needed to jump from Eclipse to Vim sometimes.

Although there are lots of ways to do this, my way is simple, I will just add a menu item to Eclipse to open the current file/resource in Vim, save it in Vim, and see the effect in Eclipse.

You can find some links to alternative methods and programs at the end of this blog according to your needs. By using these more powerful solutions, you will be able to emulate Vim in Eclipse, or you will have the Vi keys in Eclipse or even you can contain the Vim itself in Eclipse.

By the time, my Eclipse version is Helios Service Release 1 and I'm using the gVimPortable from PortableApps.

Now it is time to launch Eclipse. Eclipse has an external tools feature which we will be using. First, click Run and then External Tools and External Tools Configurations... as in the following figure.



This will open a dialog titled External Tools Configurations. Since we will be adding a new program configuration, choose Program and then click on the icon of New launch configuration at the top left as in the following figure.



Now, give a descriptive Name for the task. Here, I will use the name "Open with Vim". Also we need to indicate the Location which is the path to the executable. In my system, it was "C:\PortableApps\PortableApps\gVimPortable\gVimPortable.exe", but it can be different on your system. Set the Working Directory to "${container_loc}" and Arguments to "${resource_loc}". You can also have the same effect of changing working directory by using "set autochdir" in your vimrc. Sadly, I could not find a way to send the line number of the cursor from Eclipse. If I could, Vim could directly jump to that line like in my blog entry Running Vim from Lazarus IDE. The tab Main should look like as follows:



By the way, clicking on Variables will give you more options as follows. Keep in mind that you can use all of these options.



Now, jump to the tab Refresh and activate the option Refresh resources upon completion.. This way, you can also open other files of the project in Vim and Eclipse will refresh them. I also recommend to keep the option Recursively include sub-folders activated like this:



Now, apply and close the External Tools Configurations dialog. Open a file from your workspace, and click Run and Open with Vim (or whatever you have named it) to open your file in Vim as in the following figures:





This is a very very simple way to connect Eclipse and Vim. There are more approaches here:

Eclim

The primary goal of eclim is to bring Eclipse functionality to the Vim editor. The initial goal was to provide Eclipse’s java functionality in vim, but support for various other languages (c/c++, php, python, ruby, css, html, xml, etc.) have been added and several more are planned. That is where eclim comes into play. Instead of trying to write an IDE in Vim or a Vim editor in Eclipse, eclim provides an Eclipse plug-in that exposes Eclipse features through a server interface, and a set of Vim plug-ins that communicate with Eclipse over that interface.


Vimplugin

Vimplugin is an attempt to use the vim editor inside the eclipse IDE. This is handy especially for longtime vim users. But other users (say occasional vim users) can also profit: macros, regexes, syntax-highlighting for 1001 languages etcpp.


Vrapper - Vim-like editing in Eclipse

Vrapper is an eclipse plugin which acts as a wrapper for eclipse text editors to provide a Vim-like input scheme for moving around and editing text. Unlike other plugins which embed Vim in Eclipse, Vrapper imitates the behaviour of Vim while still using whatever editor you have opened in the workbench. The goal is to have the comfort and ease which comes with the different modes, complex commands and count/operator/motion combinations which are the key features behind editing with Vim, while preserving the powerful features of the different Eclipse text editors, like code generation and refactoring.

2010-03-10

Running Vim from Lazarus IDE

I would like to edit my program both in Lazarus IDE and Vim. Lazarus IDE is good, but Vim is faster for hard core text processing. Thanks to both of them, this task is easy.

First step is to launch Lazarus IDE, and selecting "Configure external tools ..." from the "Tools" menu.




Next step is trivial, just adding a new entry by clicking "Add".


In the final step, type the following information into specified fields.

Title: Edit with Vim

Program File Name: C:\PortableApps\PortableApps\gVimPortable\gVimPortable.exe

Parameters: +$Row() "$EdFile()"

Working Directory: $Path()

+$Row() allows Vim to directly locate the cursor when the file is opened so that you can keep going on, very useful for large files.

"$EdFile()" is the full path to the file. Note that this will work even though you have a single file on Lazarus, not a project. (If you want that, there are options for that too.)

$Path() is the working directory of the file. It will be useful to locate that directory so that you can easily open more files from Vim.


After all, your final screen should look like this:




You can now open a file from Lazarus IDE in Vim as follows:




Note that you should have a file opened it must be saved to appear in Vim.

2009-12-03

SNMP OID translator plugin for Vim

I have written an SNMP OID translator plugin for Vim.
By using this plugin, one can translate OIDs directly within Vim without exiting from the editor.
I find it useful for discovering the MIB files, and translating while reading them.

Note that you have to have Net-SNMP installed on your system.
http://www.net-snmp.org/

You can see the detais and download the plugin from the following link:

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


Here is a screenshot of the plugin.

FORTRAN valid line length plugin for Vim

I have written a Vim plugin to help my FORTRAN coding in Vim.

According to the file extension of a FORTRAN source file, this plugin sets a valid line length. Any characters occurring after this column are considered as error, and are matched so by highlighting.

This plugin is run automatically. But, if you want to use any other valid size for some reason, the commands are available.

You can download the plugin from the following link.
http://www.vim.org/scripts/script.php?script_id=2868

The following commands are available after installing this plugin.

:FORTRANLengthAccordingToExtension
Sets the valid line length according to the file extension.
This command is applied by default.
:FORTRANStandardLength72
The columns occurring after the 72nd character are marked.
:FORTRANCardImageLength80
The columns occurring after the 80th character are marked.
:FORTRANExtendedLength132
The columns occurring after the 132nd character are marked.
:FORTRANRemoveMatching
Removes the matching set by this plugin.

Here is the screenshot of the plugin. (Colorscheme is Molokai).




2009-06-29

Vim compiler plugin for FreeBASIC

I have uploaded a Vim compiler plugin for FreeBASIC.
You can download the fbc.vim at
http://www.vim.org/scripts/script.php?script_id=2691

For the following code:


the
:make
command produces an output as follows:


Traditonally, you can see the all error messages with
:cl

you can jump to next error with
:cn

and you can jump to the previous error message with
:cp


To install it, copy the script into your compiler folder. Assuming standart installations, it should be
C:\Program Files\Vim\vimfiles\compiler\
in Microsoft Windows, and
$HOME/.vim/compiler
in Linux operating systems.

In Vim, the compiler plugins are not automatically triggered unlike file type plugins. To set it whenever you need, use the command
1 :compiler fbc


To set it once and for all if a .bas file is edited, type the following into your VIMRC file:
1 autocmd BufNewFile,BufRead *.bas compiler fbc


If you need a syntax file for the upcoming FreeBASIC 0.21, you can download a syntax file at http://cubaxd.net/?en&p=syntaxfile.

2009-06-05

Delphi Pascal/Object Pascal editing in Vim

Here are a few Vim plugins for Pascal editing.

Compiler
fpc.vim : "Free Pascal Compiler" compiler plugin
It can already be bundled in your Vim. If it is not, you can download it. After opening a .pas file, type
:compiler fpc
Compiler plugins are not loaded automatically in Vim. You'll have to load them explicitly.

Syntax
Syntax file for Borlands Delphi/Kylix
Vim 7 is already bundled with Pascal syntax plugin. But Object Pascal is more than that. To colorize the keywords of Object Pascal, you can use this plugin which is derived from the original Pascal syntax plugin.

Note that although this plugin is a syntax file, if you look in the script, you will see that it also contains color codes. That is why you will not see the color scheme you selected if you have this plugin. To overcome this issue, you can delete the following lines from the delphi.vim :


261 hi pascalObject          ctermfg=white         guifg=white         gui=italic
262 hi pascalFunction        ctermfg=LightRed      guifg=Orange        gui=NONE
263 hi pascalStatement       ctermfg=Green         guifg=Green         gui=NONE
264 hi pascalNumber          ctermfg=LightBlue     guifg=LightBlue     gui=NONE
265 hi pascalByte            ctermfg=LightRed      guifg=LightRed      gui=bold
266 hi pascalString          ctermfg=LightBlue     guifg=LightBlue     gui=NONE
267 hi pascalMatrixDelimiter ctermfg=lightred      guifg=lightred      gui=NONE
268 hi pascalConditional     ctermfg=Green         guifg=Green         gui=NONE
269 hi pascalConstant        ctermfg=white         guifg=white         gui=NONE
270 hi pascalModifier        ctermfg=Green         guifg=Green         gui=NONE
271 hi pascalType            ctermfg=white         guifg=white         gui=NONE
272 hi pascalStructure       ctermfg=Green         guifg=Green         gui=NONE
273 hi pascalRepeat          ctermfg=Green         guifg=Green         gui=NONE
274 hi pascalOperator        ctermfg=Green         guifg=Green         gui=NONE
275 hi pascalAssignment      ctermfg=Magenta       guifg=Magenta       gui=NONE
276 hi pascalComment         ctermfg=LightBlue     guifg=#00A0A0       gui=italic
277 hi pascalLabel           ctermfg=Green         guifg=Green         gui=NONE
278 hi pascalDelimiter       ctermfg=Yellow        guifg=Yellow        gui=NONE
279 hi pascalComparator      ctermfg=Yellow        guifg=Yellow        gui=NONE

I should remind you that the colors are not bad though. Delete them if you want to use the color scheme selected; otherwise leave it as it is, it just works.
If you are curious, here is the screenshot of the colors provided by the syntax plugin:


Also the author of this plugin provides some code to be put on your .vimrc and it is quite useful.
This is the code to be put on your .vimrc:
 1 " Pascal / Delphi
 2 if (1==1) "change to 1==0 to use original syntax
 3   au BufNewFile,BufRead *.pas,*.PAS set ft=delphi
 4 else
 5   au BufNewFile,BufRead *.pas,*.PAS set ft=pascal
 6 endif
 7 " Delphi project file
 8 au BufNewFile,BufRead *.dpr,*.DPR set ft=delphi
 9 " Delphi form file
10 au BufNewFile,BufRead *.dfm,*.DFM set ft=delphi
11 au BufNewFile,BufRead *.xfm,*.XFM set ft=delphi
12 " Delphi package file
13 au BufNewFile,BufRead *.dpk,*.DPK set ft=delphi
14 " Delphi .DOF file = INI file for MSDOS
15 au BufNewFile,BufRead *.dof,*.DOF set ft=dosini
16 au BufNewFile,BufRead *.kof,*.KOF set ft=dosini
17 au BufNewFile,BufRead *.dsk,*.DSK set ft=dosini
18 au BufNewFile,BufRead *.desk,*.DESK set ft=dosini
19 au BufNewFile,BufRead *.dti,*.DTI set ft=dosini
20 " Delphi .BPG = Makefile
21 au BufNewFile,BufRead *.bpg,*.BPG set ft=make|setlocal makeprg=make\ -f\ %

Color Schemes
Delphi color scheme

Turbo color scheme

Borland color scheme

2009-05-16

Vim and Visual Studio

There is a VIM script, visual_studio.vim which can be found at http://code.google.com/p/vim-visual-studio/. It uses the Python Extensions for Windows to integrate VIM and Visual Studio. It can get the files, solutions and its projects from Visual Studio. You can directly compile the solution from within VIM and you can obviously use the "quickfix". It is not an emulation mode for Visual Studio unlike ViEmu, you will be using VIM again.

The page on vim.org says that you need to have Python 2.4. On my Windows box, I have Visual Studio 2008 and GVIM 7.2, which has been compiled with Python 2.4 support. But, the Python interpreter I am using is Python 2.5, which I keep compatible with the Python interpreter on a production machine. As a result, I had no chance to uninstall Python 2.5 for Python 2.4 and no intention to uninstall GVIM 7.2 for GVIM 7.0.

So, I have found Vim binaries compiled for Python 2.5 and Python 2.6. I have downloaded the zip file and overwritten the executables in my Vim directory. If I type

:version

in Vim, I get the following screens:




Which shows that I have finally a Python 2.5 compatible Vim.

By the way, do not forget to install Python Extensions for Windows if you did not installed yet.

If we make a summary
- We have Visual Studio 2008
- We have Python 2.5
- We have Python Extensions for Windows
- We have GVIM 7.2
- We have Python 2.5 binaries for GVIM
- We have the visual_studio.vim

And finally, I have been able to see and use the following menu: