vi / vim editor – how to edit, cut, copy and paste!

When working with the shell in linux you’ll often have to edit or change a text file / config file or two.

The easiest way to do this is to use vi or vim straight from the shell. Simply type vi followed by the name of the file that you wish to open and edit or create. You must provide the full path for the file you want to open or create.

If you type vi and then a filename that doesn’t already exist, vi will create that file for you.

vi name_of_file.txt

Once opened you won’t be able to edit or change the file without using these keys

Press i to insert, this allows you to start editing / deleting existing text, press ESC once finished.

Press v to start to highlight text or multiple rows of text, use the arrow keys to make your selection.

once highlighted with v you can:
Press delete to delete!
Press y to copy the selection.
Press d to cut the selection.

Press p to paste

How to save and quit
Press Escape to cancel any key mode you might be in such as highlight, insert etc

Type w: and press return to write the changes ie. save the file
Type q: to quit the editor and return to shell

When working remotely using pussy for example, you can interact with vi by copying the contents of your clipboard to vi by using the right mouse button

Print Friendly, PDF & Email

More Like This


Categories


Linux

Tags


  • Post a comment