Replacing ^M

Frequently I have to replace ^M in UNIX style files. I usually Google “vim newline replace”. And come to this post on the vim website. It is also now available on wikia. Vim wikia is an example of very good wiki style collaboration.

The command I am using to replace ^M:

:%s/\r//g

Count words

This describes how to get information about number of words from vim. Use

g Ctrl-g

Change encoding in 50 files

Task: change encoding in 50 files from windows to utf. Solution: map

map q :set fileencoding=utf-8:wn

Open all files in one window and press q, until encoding is changed in all the files. In the last file the command ‘n’ will not work – just quit.

End of file

The first line always has number one. How about the last line? The “$” character is used for this. For example, to substitute in the lines from the cursor to the end:

:.,$s/yes/no/

From here.

Editing more than one file

Highlight several files and with right click select “Edit with single Vim”. To go to the next file type

:next

or simply

:n

If quit and there are some files left, vim will generate an error: “More files to edit”. Simply quit one more time.

Set encoding

For the Donetsk map site I use a simple database in txt files so far. Each file has Russian characters. In version 6.2 the encoding for Russian symbols was native Windows. In version 7.0 I have to type

:set fileencoding=cp1251

to have it the same.

Vim and Thunderbird

To use gvim and Thunderbird External editor extension for Thunderbird can be used.

When downloaded in Tunderbird go to Tools>Entensions>Install and browse to the file.

After installation start composing a message and go to View>Toolbars>Customize and pull the External editor to the sidebar.

Then go back to main window Tools>Entensions>Options for the editor and enter the path (do not forget –nofork option)

$Vim/vim70/gvim.exe --nofork

Change $Vim to the main directory for vim

Here is more detailed description.

Russian keymap

A problem: when using Shift+Ctrl to switch the keyboard layout it is neccessary to switch again after Esc for browsing the document.

Solution: use keymap. Vim has various keymap in

$Vim/vim70/keymap

The problem is that phonetic Russian layout is slightly different from what I am using so I have modified it a little. The file rus.vim is attached. To switch to the keymap use

:set keymap=rus

To switch keymaps in input mode use

Ctrl+^

On a note relevant to this post. Here it is explained how to upload files with additional extensions. Simply

vi wp-admin/admin-functions.php

in the blog directory and look for “jpg”. Insert additional extensions there.

Spelling

In LaTeX I had problems with spelling: some words are not recognized as wrong. The solution was to turn of the syntax highlighting

:syntax off

It was found in this article. There also info about tabs, undos, code completion etc.

:zg

Adds a word to dictionary. Found in help.

Here is a blog post describing the spell checker.

Wrapping after 76 characters

Removed the following line from vimrc file.

" Wrap after 76 Chars (could probably be 77, too)
set textwidth=75

It is probably relevant for Phython, but annoying for LaTex.