Vi Unix Editor – How to use Vi Editor and Common Problems – CLI Putty Errors and Terminal Type

The Vi Unix Editor

The Vi Unix Editor is the standard UNIX command line editor and if you’re planning on doing some configuring of a Unix Server you will definitely need to use the VI editor especially when you’re running a Command Line only operating system.

This hub will go through the basics of using the Vi unix editor, opening, creating, saving and writing to a file as well as the different modes for the Vi Editor. I will also go through common problems people have with the Vi editor especially the annoying problem when logging into your server using a SSH client such as Putty, where you find that the backspace key doesn’t work or the arrow keys simply return letters.

I’ll also cover basic terminal modes and types and how to make sure the server’s terminal type and the putty terminal type match so that you have no problems accessing and editing files remotely on your server.

Try these navigational keys if the usual arrows and backspace do not work for you, otherwise keep reading to get normal keyboard function back
Try these navigational keys if the usual arrows and backspace do not work for you, otherwise keep reading to get normal keyboard function back

Unix Vi Editor Modes

- Command mode – This is the basic mode of the Vi editor and can be accessed by opening a file using “vi file.conf”. Letters and combination of letters will be interpreted as commands.

- Insert Mode – The Insert mode as it sounds allows you to edit text and insert your own text into configuration files. Depending on how your Unix system is setup you can either navigate using the arrow keys and regular windows keyboard or use the following. Press the INSERT key on your keyboard to enter this mode.

- INSEERT IMAGE, ordinarily you can use the regular keyboard functions otherwise use these ones. Paste bigger list onto a copy code thingo

- Line Mode – The line mode can be entered by pressing ESC and then type colon (J

From here you can either save the file, save and quit , or quit without saving changes.

:wq write the file to disk and quit

:q! quit without saving any changes

:w! newfile write all lines from the entire current file into the file 'newfile', overwriting any existing newfile

:n,m w! newfile write the lines from n to m, inclusive, into the file newfile, overwriting any existing newfile

the Vim editor will solve all your problems :)
the Vim editor will solve all your problems :)

Common Problems when using Vi Editor

- Backspace function not working

- Arrow keys return A, B, C , alpha functions

- Keys generally acting strange and muddled

- Errors when using Putty or SSH client to remotely access server

Solution – Vim Editor **

There is an incredibly easy solution to this problem, instead of using the light weight Vi editor, instead use vim to edit your files. Simply type Vim “filename” to edit the files and you will notice all the regular functions are restored. You can backspace as usual and the arrows also work fine.

You can also choose to change the alias for vi to point to the vim editor in your bashrc profile. Follow the steps below

- Open up your terminal window , Command Line

- Type “vim ~/.bashrc” , create the file if it doesn’t already exist, or copy the file from your existing login directory

- At the end of the file type “alias vi=’vim’”

- Save and Quit

- Done

Checking terminal-type string in Putty SSH client
Checking terminal-type string in Putty SSH client
Keyboard settings for putty , Check settings for how putty will interpret a backspace function
Keyboard settings for putty , Check settings for how putty will interpret a backspace function
Remember to save your settings before testing them
Remember to save your settings before testing them

Other Problems - Cant Backspace, Weird arrow Keys etc

SSH client Putty Problem – Weird key functions, backspace not working

Solution – Make sure the Terminal mode on your server matches the Terminal mode used on the putty or ssh client. If they don’t match putty and the server won’t be able to agree on how to interpret keys and you may find it hard to carry out basic tasks.

Check what Terminal Mode you are running

Echo $SHELL or Echo $TERM

You can set the terminal type by typing “set term/device=vt100” replace vt100 with your chosen terminal mode. Vt100 is the most commonly used.

Check Terminal Mode on your SSH client (putty)

- Check terminal-type string and make sure they match

- Save your SSH client configuration

Note: If your problem is only to do with the backspace check the setting under keyboard and try using Backspace key , Control-H.

Setting the Backspace Key on Linux

stty erase ^v<press backspace key right after typing ^v>

(just incase you incorrectly assign the backspace key)

More by this Author


Comments 10 comments

Portamenteff profile image

Portamenteff 6 years ago from Western Colorado, USA

Actually in most modern Linux systems, the command "vi" is an alias to vim. It is a necessary tool for the server admin or tech.

Great hub!


expectus profile image

expectus 6 years ago from Land Downunder Author

yea that's true, I wrote this hub because I had so many problems using the vi editor it was driving me crazy:P


pj 6 years ago

greate imfo


htodd profile image

htodd 5 years ago from United States

Thanks for the great post..Nice


Dave 5 years ago

Here is a vim plugin script that I use that caused me some pain when I switched over to using Putty to remotely access development machines. Basically, you can just provide mappings for the character codes that Putty uses to represent the arrow keys.

$ cat ~/.vim/plugin/window_resize.vim

" Window resizing mappings /*{{{*/

" Putty shift-arrow key mappings

nnoremap [A :normal =Resize('+')

nnoremap [B :normal =Resize('-')

nnoremap [C :normal =Resize('')

" Local shift-arrow key mappings

nnoremap :normal =Resize('+')

nnoremap :normal =Resize('-')

nnoremap :normal =Resize('')

function! Resize(dir)

echo "Resize called!!!!"

let this = winnr()

if '+' == a:dir || '-' == a:dir

execute "normal k"

let up = winnr()

if up != this

execute "normal j"

let x = 'bottom'

else

let x = 'top'

endif

elseif '>' == a:dir || '' == a:dir && 'left' == x) || ('


KMattox profile image

KMattox 5 years ago from USA

expectus

Good article on vim. I appreciate you taking the time to write it. It is easy to become confused in the command line environment. I don't use vim much anymore since the gui's have improved so much over the last few years. Vim is one of those programs it is good to fall back on. KUDOS. I voted up and useful.

KMattox


abani 5 years ago

I had installed ubuntu 11.04 in compaq presario v3239 tu.In terminal after creating a .c file when I try to do program by pressing insert key or i,but it doesn't show any insert mode.

please help

Thank you


captain 5 years ago

its helpful a lot. I am puzzled by my vi editor in ubuntu.


expectus profile image

expectus 4 years ago from Land Downunder Author

abani, you will need to type vi filename.c to bring up the vi editor


e-learning.academy@outlook.com 24 months ago

Hi for all your people who are facing a tough time learning vi, Here is a very comprehensive tuitoial to help you out. All the commands will be practiaclly illustrated.

https://www.udemy.com/vi-editor-increase-your-prod...

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working