Is there a way to show the current row and column position in vi? In vim, I know there is the set ruler
command, but what are my options when using vi?
A vi equivalent of vim’s ‘set ruler’ command
vivim
Related Solutions
When Vim reads an existing file, it tries to detect the file encoding. When writing out the file, Vim uses the file encoding that it detected (except when you tell it differently). So a file detected as UTF-8 is written as UTF-8, a file detected as Latin-1 is written as Latin-1, and so on.
By default, the detection process is crude. Every file that you open with Vim will be assumed to be Latin-1, unless it detects a Unicode byte-order mark at the top. A UTF-8 file without a byte-order mark will be hard to edit because any multibyte characters will be shown in the buffer as character sequences instead of single characters.
Worse, Vim, by default, uses Latin-1 to represent the text in the buffer. So a UTF-8 file with a byte-order mark will be corrupted by down-conversion to Latin-1.
The solution is to configure Vim to use UTF-8 internally. This is, in fact, recommended in the Vim documentation, and the only reason it is not configured that way out of the box is to avoid creating enormous confusion among users who expect Vim to operate basically as a Latin-1 editor.
In your .vimrc
, add set encoding=utf-8
and restart Vim.
Or instead, set the
LANG
environment variable to indicate that UTF-8 is your preferred character encoding. This will affect not just Vim but any software which relies onLANG
to determine how it should represent text. For example, to indicate that text should appear in English (en
), as spoken in the United States (US
), encoded as UTF-8 (utf-8
), setLANG=en_US.utf-8
.
Now Vim will use UTF-8 to represent the text in the buffer. Plus, it will also make a more determined effort to detect the UTF-8 encoding in a file. Besides looking for a byte-order mark, it will also check for UTF-8 without a byte-order mark before falling back to Latin-1. So it will no longer corrupt a file coded in UTF-8, and it should properly display the UTF-8 characters during the editing session.
For more information on how Vim detects the file encoding, see the
fileencodings
option in the Vim
documentation.
For more information on setting the encoding that Vim uses
internally, see the encoding
option.
If you need to override the encoding used when writing a file back
to disk, see the fileencoding
option.
That's a bit like asking what the difference is between a beaten up Datsun 120Y & a Porsche!
Vim has a multitude of features not offered by plain old vi:-
- Multiple windows - horizontal, vertical & tabs.
- Visual highlighting.
- Online help via the :help command.
- Record macros into a register that you can then execute.
- Undo (and redo) multiple times, rather than old vi's insane undo toggle.
- Command line history, search history.
- An entire language embedded along with a host of available functions, eg getcwd()
- Vastly expanded pattern matching.
- Word completion via ctrl-P & ctrl-N.
- A built in file navigator (a little clunky, but can be useful).
- The ESC key actually quits commands you were trying to, well, escape from instead of (insanely) running them as vi does.
- Ability to run commands on all buffers, args or windows via bufdo, argdo & windo.
I could rave on for much longer than this, vim has so many more features than plain old vi that there's really no comparison.
PS - To actually use plain old vi, you'd have to be working on a legacy Unix system, e.g. Solaris (sorry guys, it's going that way). You may well be using vim when you think you're using vi, as most Linux distros simply map vi to vim. If :help works, or multiple undos work, or :version works, you're using vim, not vi!
Best Answer
You can do
set number
to show the line number at the beginning of each line. However, in original vi, there doesn't seem to be an option to show the current column.There is a way to at least position the cursor at a specific column. Do
25|
to position the cursor at column 25 of the current line.