Useful Tools for 2030 Practical - nus-cs2030/2324-s2 GitHub Wiki
Summary of commands that we find useful for Practical
CLI commands
1. cd
Navigate to a specific folder - cd "[folder_name]" -> in this case, if your folder name has a space, enclose your folder name in a string so that the space is bypassed. e.g. cd "Folder A"
Navigate out of a folder - cd ..
2. javac *.java
javac *.java is a fast an easy way to compile all your java files in the folder, so that you can check for any compilation errors with ease!
In this case, javac compiles the java files while *.java is a way of telling your compiler "all files in this folder that has java extension".
3. upwards and downwards arrow keys
helps u to navigate through your command history
usage of the upwards and downwards arrow keys also work in jshell to navigate through your command history!
4. jshell [list of files in bottom up dependency]
e.g. jshell ShareARide.java TakeACab.java JustRide.java Request.java
In the example above, the command in CLI opens ShareARide, TakeACab, JustRide and Request in jshell, so you do not have to /open each of them one by one
When doing level by level in practical, use this with the upwards arrow keys (use upwards arrow keys to go to your last used jshell command in CLI and then add the new files you have created accordingly before pressing enter to run)
5. vim [java files] -p
e.g. vim X.java Y.java Z.java -p
this will open up X.java, Y.java and Z.java concurrently.
Switch tabs using gt in vim's normal mode
6. right click on the mouse
right click on the mouse can be used to copy and paste commands in the CLI, which would help when you want to test your code.
VIM commands
Below are some of the useful commands in Vim, but is by no means an exhaustive list. To learn more, you may refer to this [cheatsheet](https://vim.rtorr.com/) or try this guided [tutorial](https://openvim.com/). All the best in your Vim learning journey!
Useful Modes
esc -> normal mode (where u write commands to save your file etc)
I (from normal mode) -> insert mode (edit file mode)
v (from normal mode) -> visual mode (this is useful for copy pasting.)
Useful VIM tools
Copy pasting within vim
Press v to enter visual mode
Use arrow keys to highlight the parts you want to copy
Press y to yank
Press esc to enter normal mode
Go to the place u want to paste the text
Press p to paste
Undo
In normal mode, enter :u
Redo
Press Control + r
Save and exit
In normal mode, enter :wq
Exit without saving
In normal mode, enter :q or :q!
Moving forward fast (word by word)
In normal mode, enter e {x} times to move forward by x number of words
Moving backwards fast (word by word)
In normal mode, enter b {x} times to move backwards by x number of words
Window Management and Productivity Commands
Tabs in vim
:tabnew `filename` - open `filename` in new tab if it exists, otherwise creates a buffer for that file (only saved after :w)
gt or :tabn[ext] - move to the next tab
gT or :tabp[revious] - move to the previous tab
:tabc[lose] - close the current tab and all its windows
:tabo[nly] - close all tabs except for the current one
:tabdo command - run the command on all tabs (e.g. :tabdo q - closes all opened tabs)
Split Windows
:sp[lit] file - open a file in a new buffer and split window
:vs[plit] file - open a file in a new buffer and vertically split window
:vert[ical] ba[ll] - edit all buffers as vertical windows