vi
  • vi is the default text editor which comes with any Linux/UNIX machine.
  • vi is “old-school”, but absolutely essential to learn, although there are many other GUI type text editors around, which may be more intuitive.
  • The reason one should learn vi, is because all GUI type text editors, rely on very good internet connection to the server you are working on. To use vi, ones does not required very good internet. Additionally, vi is installed by default, whereas GUI editors are not.
  • On most systems, vi and vim (m= improved) are the same thing. Whether you vi a file or vim a file, it’s the same. But you should check using "which vi", then do ls -l of the path, and usually vi is a soft link to vim. If it's not, you may have to install vim yourself
  • vi basics (ECS = escape key):
    • Open a file: “vi file_name”
    • To enter text, you need to be in "insert mode", so press ESC, then i. You can now type text as you would normally.
    • There is also a "delete mode", press ESC, then x. Press x to delete stuff.
    • To exit a mode press ESC
    • Close the file and save changes, press ESC, then :wq
    • Close the file but don’t save changes, press ESC, then :q!
    • Save file while still open, press ESC, then :w
    • Undo latest change, press ESC, then u
    • Delete current line, press ESC, then dd
    • Go to a certain line, say line 50, press ESC, then :50
    • Find occurrences of a string, say “year”, press ESC, then :/year, then press n to find next occurrence of the string “year” in the file
    • Global find and replace, press ESC, then :%s/foo/bar/g. This will replace all instances of foo with bar.
  • There are MANY online tutorials on vi, have a look around.
  • If you have good internet, you may wish to use “gvim”, i.e., a GUI version of vim. All the vim syntax is the same, except now you have a GUI, with scroll bar, and menus etc.
  • vi has automatic color coding for Fortran and BASH. However, this may not work by default on Mac-OSX. There are easy work-around/fixes for this. Just Google it.
  • When you vi a file, a file with .swp extension is automatically created, this is a hidden file, and like a back-up file. In case you suddenly loose connection, the .swp file can be used to recover the file when you log back in.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License