Skip to content

Vim and Terminal

Vim and Terminal

Here are some useful vim/terminal commands I used a lot during my PE/using terminal in general (if it matters, I use windows)

Note

These are merely the common ones I use, for a proper list of commands please visit the official notes

Vim

Note the use of : and when u shouldn't

  • :wq : write (save) the file and exit
  • :w FileName.java : make a copy of the current file and save it as FileName.java
  • :%s/oldWord/newWord/gc : replaces instances of oldWord with newWord
    • y : replace current
    • a : replace all instances
  • :tabf FileName.java : opens FileName in another tab
    • gt : move to that tab
  • :tabe FileName.java : creates a new file called FileName in another tab
  • :vsp FileName.java : opens FileName in split screen (vertically)
    • ctrl w twice to go to other screen
  • :! javac FileName.java : compile your file without closing vim

No :

  • ndd: deletes n lines
  • nyy : yank (copy) n lines
  • p : paste copied text (after cursor)
  • u : undo
  • 0 : move cursor to start of the line
  • $ : move cursor to end of the line
  • gg=G : auto-indent
  • /functionName : brings you to first instance of functionName (or whatever u search for)
    • n to go to next instance
    • is case sensitive

Dealing with .swp file

swp

  1. click r to recover
  2. :wq to save and exit
  3. in terminal, rm .fileName.java.swp

Terminal

For details on navigating between directories, please visit the official notes

  • javac FileName.java : compiles FileName
  • java FileName : run the program (remember do not do java FileName.java)
  • rm FileName.java : deletes the file
  • ls : list the files in the directory
  • cp FileName.java NewName.java : Creates a copy of FileName.java and saves as NewName.java
    • cp FileName.java dir/ : Creates a copy of FileName.java located in directory dir
  • mv FileName.java NewName.java : Renames FileName.java as NewName.java
    • Note that original FileName.java will no longer exist