How to Create and Edit Text Files
Create and Edit Text Files
vi/vim
: Full screen editors;vi
is always available since it is a POSIX requirement,vim
may need to beinstalled)vi filename
: Multiple modes:Command mode
allows for navigation and the entering of commands using combinations of one or more letters; these can be prefixed with numeric values for repetitionEx mode
allow file manipulation; to enter this mode, type a colon (:
) followed by the command desiredInsert mode
to edit text; enter this post by pressingi
-
The ESC key always returns to command mode
-
vi
command examples: h
: Move one character leftj
Move down linek
Move up linel
Move one character rightH
Move to top of screenL
Move to bottom of screenG
Move to end of file0
Move to beginning of line$
Move to end of linei
Insert at current positionI
Insert at beginning of linex
Delete characterdd
Delete lineo
Create a blank line after current lineO
Create a blank line before current line-
Additional commands can be found in the vi/vim man pages
-
Text files can be created by various methods outside of
vi, vim
or other editors: touch testfile.txt
: Creates a blank file called testfile.txt owned by the current user in the current directoryecho "Some value" > testfile.txt
: Creates a file calledtestfile.txt
, owned by the current user in the current directory, containing the text following the echo command (in this instance, “Some value”)- Redirection of almost any command will take the output and place it into a file