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 newWordy: replace currenta: replace all instances
:tabf FileName.java: opens FileName in another tabgt: 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 wtwice to go to other screen
:! javac FileName.java: compile your file without closing vim
No :
ndd: deletes n linesnyy: yank (copy) n linesp: paste copied text (after cursor)u: undo0: move cursor to start of the line$: move cursor to end of the linegg=G: auto-indent/functionName: brings you to first instance offunctionName(or whatever u search for)nto go to next instance- is case sensitive
Dealing with .swp file

- click
rto recover :wqto save and exit- in terminal,
rm .fileName.java.swp
Terminal
For details on navigating between directories, please visit the official notes
javac FileName.java: compiles FileNamejava FileName: run the program (remember do not dojava FileName.java)rm FileName.java: deletes the filels: list the files in the directorycp FileName.java NewName.java: Creates a copy ofFileName.javaand saves asNewName.javacp FileName.java dir/: Creates a copy ofFileName.javalocated in directorydir
mv FileName.java NewName.java: RenamesFileName.javaasNewName.java- Note that original
FileName.javawill no longer exist
- Note that original