Thursday, November 17, 2011

Useful GVIM Tips

The things that I didn't know about GVIM editor.

How to prepare _vimrc file (i.e. the file with the default settings)

Windows:
1. Copy "C:\Program Files (x86)\Vim\_vimrc" to $HOME/_vimrc.
If you don't have $HOME variable, you may see it in Gvim with the help
:e $HOME/_vimrc

2. Edit $HOME/_vimrc, add commands there.

Linux:
vim $HOME/.vimrc
add commands there.

For instance, my favorite tab stop options:
:set tabstop=2
:set shiftwidth=2
:set expandtab
:set backspace=indent,eol,start

How to make the 'Backsapce' key work properly in Edit mode:
:set backspace=indent,eol,start
(more info here: http://vim.wikia.com/wiki/Backspace_and_delete_problems)


How to start Gvim maximized under Windows:
(taken from http://vim.wikia.com/wiki/Maximize_or_set_initial_window_size)
Add the following line to _vimrc:
au GUIEnter * simalt ~x "x on an English Windows version. n on a French one

It is possible to have only one Gvim running:

Edit "file.txt" in server "FILES" if it exists, become server "FILES"
otherwise:
    gvim --servername FILES --remote-silent file.txt

This means that you'll have only one Gvim running. New files will be opened in already running Gvim.

More information here:
http://vimdoc.sourceforge.net/htmldoc/remote.html

Hidden characters in GVIM

Display hidden characters: :set invlist
(taken from http://dinomite.net/2007/vim-tip-show-hidden-characters) 

Learn the code of symbol under the cursor: ga

Find the symbol with code (for instance, Tab symbol with hex code 09):
/\%x09
Replace: the same, for instance :s/\%x09/  /gc
(taken from http://durgaprasad.wordpress.com/2007/09/25/find-replace-non-printable-characters-in-vim/)

How to show line numbers:
To turn line numbers on  :set nu
To turn line numbers off :set nu!  

How to convert the file from Windows to Unix format using GVIM
(i.e. replace \r\n to just \n)
1. Open file in GVIM.
2. :set ff=unix
3. Save the file and exit


How to remove empty lines in GVIM

:,$s/^\s*\n/
(more tips here: http://www.rayninfo.co.uk/vimtips.html, great source of GVIM info) 

How to make arrow keys work properly in edit mode in Vi on Linux term

Problem: It seems that when I am using VI through putty when I am in insert mode I get escape characters, instead of the cursor moving when I use the arrow keys.

Solution: 1. use vim.
2. Create a .vimrc file in your home directory:
echo syntax enable > ~/.vimrc

Read here: http://www.bluehostforum.com/archive/index.php/t-6700.html


To be continued...

No comments:

Post a Comment