Gvim

Vim ( / vɪm /; a contraction of Vi IMproved) is a clone, with additions, of Bill Joy 's vi text editor program for Unix. Vim's author, Bram Moolenaar, based it on the source code for a port of the Stevie editor to the Amiga and released a version to the public in 1991. Vim is designed for use both from a command-line interface and as a. Gvim is model editor it has two modes of operation for editing files 1) insert mode 2) qcommand mode. There might be other mode for using it but for beginners this two is enough.) Insert mode. Once you have started gvim by default you are in command mode. To enter from command mode to insert mode press character 'i' and you.

A friend introduced me to the excellent Vi editor. His constant talking about how great it is made me curious. I purchased Learning the Vi and Vim Editors – O’Reilly and learnt the basic commands.

My boss prefers Windows: so all our servers are Windows.
I wanted to continue using Vim so started using gVim. gVim is a modified version of the UNIX Vi editor.

Here are some things I’ve needed to configure while using gVim.

Maximising gVim Windows on file open

The default window size when opening a file in gVim is small.
To make gVim maximise windows on file open add the following to you _vimrc file.

Your _vimrc will be in the root folder of your Vim install, mine’s located in: C:Program FilesVim

The _vimrc file contains optional runtime configuration settings to initialize Vim when it starts.
On Unix based systems, the file is named .vimrc, on Windows systems it’s _vimrc.

Removing ^M characters in gVim

^M characters are DOS/Windows line-ending characters.
Previous developers at my work used Notepad++ to edit files. When I’d open these files in gVim they were littered with ^M characters and appear without line breaks or indents. Hard to read and edit.

To remove these use the ex command

I encountered a problem typing control characters in Windows.
In a UNIX environment you type a control character using CtrlV. In Windows CtrlV is used to ‘Paste’ so you must use CtrlQ instead.
To type ^M in gVim you type (CtrlQ) <– keep your finger on Ctrl then press M.

Gvim color schemes

Good explanation of ^M characters copied from here

There is a difference between how a Windows-based based OS and a Unix based OS store end-of-line markers.
Windows based operating systems – thanks to their DOS heritage – store an end-of-line as a pair of characters – 0x0A0D. Unix based operating systems just use 0x0A. ^M is a visual representation of 0x0D.

Gvim

Changing the location of gVim swap and backup files

When editing a file in gVim a backup file is created after saving changes to a newly opened file.
It is a copy of the file before changing the file. It is named the same as the file with a ~ at the end.
This creates a lot of clutter in your directories.
Thankfully you can change the default behaviour by disabling swap and backup files or moving the location of these.

To disable swap and backup files add this to your _vimrc file

Gviml

I like to keep these files as it saves the line location that I was last editing.

To change the swap and backup file location add this to your _vimrc file

vimdiff allows you to diff and merge two files in vim. Start it with either of the following commands:

You can also use gvim, in which case substitute 'vim' for 'gvim' in the above commands.

If you are already in vim (editing [file1]), use the following command to do a vertical diff between the current file and another.

If you want to use the --remote-tab or --remote-tab-silent switch to open the diff in a new tab in the existing window, you need to start the diff via a command rather than via a switch:

Note that you will need to escape any spaces in [file2].

Scrolling

To get both files scrolling at the same time I had to set the scrollbind option in my .vimrc file (or set it in /etc/vim/vimrc as a global setting):

Redoing the diff

If you loose the diff for whatever reason (e.g. I lost the diff when opening a new tab with :tabnew), turn the diff option on again.

Vim Font Size

You'll also need to redo the diff if you make a non-trivial change to a line, in which case run the following:

Moving around

Switch viewport:

Jump to next diff:

Gvim On Macos 10.13

Jump to previous diff:

Merging

Whole diff

To replace a diff in the current viewport with that from the other viewport, use the :diffget command. This can be shortened to the following:

To replace a diff in the other viewport with that from the current viewport, use the :diffput command. This can be shortened to the following:

Gvim Vs Vim

If you want to get contents from the other viewport when the current viewport has 'filler' - i.e. a series of dashes - then do so from the line below.

Part of the diff

To replace just a single line or multiple lines in a diff in the current viewport (rather than getting the entire diff), use a range. You have to use the full command for this - you can't use the shortened command shown above. For example, if you want to get line 63 from the other viewport, do the following:

The diffget command can be shortened slightly to diffg.

It's similar for diffput.

References

  • Vim documentation: diff