## Tabs & Windows
Open files in multiple tabs.
`vim -o file1.txt file2.txt file3.txt`
o-vertical, O-horizontal
Switch tabs:
`gt ->`
`gT <-`
Switch windows:
`<C+w>w ->`
`<C+w>W <-`
Add permanent hotkey (Tab-key) to switch windows
```
cat ~/.vimrc
:noremap <Tab> <C-W>w
```
## Substitution
`:%s/\<foo\>/bar/gc` Change only whole words exactly matching 'foo' to 'bar'; ask for confirmation.
`:s/foo/bar/g` Change each 'foo' to 'bar' in the current line.
`:%s/foo/bar/g` Change each 'foo' to 'bar' in all the lines.
`:5,12s/foo/bar/g` Change each 'foo' to 'bar' for all lines from line 5 to line 12 (inclusive).
`:'a,'bs/foo/bar/g` Change each 'foo' to 'bar' for all lines from mark a to mark b inclusive (see Note below).
`:'<,'>s/foo/bar/g` When compiled with +visual, change each 'foo' to 'bar' for all lines within a visual selection. Vim automatically appends the visual selection range ('<,'>) for any ex command when you select an area and enter :. Also, see Note below.
`:.,$s/foo/bar/g` Change each 'foo' to 'bar' for all lines from the current line (.) to the last line ($) inclusive.
`:.,+2s/foo/bar/g` Change each 'foo' to 'bar' for the current line (.) and the two next lines (+2).
`:g/^baz/s/foo/bar/g` Change each 'foo' to 'bar' in each line starting with 'baz'.
## Fileformat
```
:set fileformat=unix
fileformat=dos
```
Display CRLF as ^M:
```
:e ++ff=unix
```
Substitute CRLF for LF:
```
:setlocal ff=unix
:w
:e
```
```
:set fileencoding=utf8
:w myfilename
:set bomb
```
## Other
In editor u can write in command mode:
`:sh`
to get in into the shell. To move back press `<C-D>`.
`:help` is very helpfull :)
## My .vimrc
```
:noremap <Tab> <C-W>w
set wildmenu
set wcm=<Tab>
menu Encoding.koi8-r :e ++enc=koi8-r<CR>
menu Encoding.cp1251 :e ++enc=cp1251<CR>
menu Encoding.cp866 :e ++enc=cp866<CR>
menu Encoding.ucs-2le :e ++enc=ucs-2le<CR>
menu Encoding.utf-8 :e ++enc=utf-8<CR>
map <F12> :emenu Encoding.<Tab>
```