Difference between revisions of "Vi editor"
From Teknologisk videncenter
m (→Inserting control characters in documents) |
m (→Forcing UTF8 in vim) |
||
Line 40: | Line 40: | ||
==Forcing UTF8 in vim== | ==Forcing UTF8 in vim== | ||
Add the following lines to your $HOME/.vimrc | Add the following lines to your $HOME/.vimrc | ||
+ | ;Note:Remember to set your terminal to UTF-8 | ||
<source lang=text> | <source lang=text> | ||
set encoding=utf-8 | set encoding=utf-8 | ||
Line 45: | Line 46: | ||
set fileencodings=utf-8 | set fileencodings=utf-8 | ||
</source> | </source> | ||
+ | |||
{{Source cli}} | {{Source cli}} | ||
[[Category:Operating Systems]][[Category:UNIX]][[Category:Linux]][[Category:Linux Command]] | [[Category:Operating Systems]][[Category:UNIX]][[Category:Linux]][[Category:Linux Command]] |
Revision as of 05:13, 18 June 2012
Contents
Search and replace
Replace all oldtext to newtext starting at line 1 to last line ($). s means search and g globally - not just once.
:1,$s/oldtext/newtext/g
FAQ
Syntax highlighting
To use syntax highlighting temporarily use the command :syntax on. To switch it off again use :syntax off.
To use syntax highlighting permanently use
[root@mars ~]# <input>echo "syntax on" >> $HOME/.vimrc</input>
Line numbers in vi
To use line numbers temporarily use the command :set number. To switch it off again use :set nonumber.
To use line number permanently use
[root@mars ~]# <input>echo "set number" >> $HOME/.vimrc</input>
Which editor mode are I'm in
Use showmode option. Shown below
[root@mars ~]# <input>echo "set showmode" >> $HOME/.vimrc</input>
Now you can see which mode you are in by looking at the bottom line
- In insert mode it will write -- INSERT --
- In replace mode it will write -- REPLACE --
- In line command mode it will write a colon (:) in the lower left cornor of the screen.
- In command mode - empty or everything else
VIM and FreeBSD malfunctioning arrow keys in insert mode
Set vim to work in nocompatible mode. Not as old vi.
[root@mars ~]# <input>echo "set nocompatible" >> $HOME/.vimrc</input>
Inserting control characters in documents
Using the <CTRL>-v and A inserts SOH (001) See ASC-II. <CTRL>-v and <ESC> inserts <ESC>. Remember capital letters.
Forcing UTF8 in vim
Add the following lines to your $HOME/.vimrc
- Note
- Remember to set your terminal to UTF-8
set encoding=utf-8
set fileencoding=utf-8
set fileencodings=utf-8