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.
"start maximised au GUIEnter * simalt ~x
Your _vimrc will be in the root folder of your Vim install, mine’s located in: C:\Program Files\Vim\
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
:%s/^M/\r/g
I encountered a problem typing control characters in Windows.
In a UNIX environment you type a control character using Ctrl–V. In Windows Ctrl–V is used to ‘Paste’ so you must use Ctrl–Q instead.
To type ^M in gVim you type (Ctrl–Q) <– keep your finger on Ctrl then press M.
:help CTRL-V-alternative *CTRL-V-alternative* *CTRL-Q* Since CTRL-V is used to paste, you can't use it to start a blockwise Visual selection. You can use CTRL-Q instead. You can also use CTRL-Q in Insert mode and Command-line mode to get the old meaning of CTRL-V. But CTRL-Q doesn't work for terminals when it's used for control flow.
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.
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
set nobackup set nowritebackup set noswapfile
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
"set where to store backups set backupdir=C:\vimbackups "set where to store swap files set dir=C:\vimbackups