PLEASE NOTE: the upgrades to this server, secure.csse.uwa.edu.au, have not yet been completed.
Hopefully the changes will be completed on THURSDAY 8th December.
Web-based programs, such as csmarks, cssubmit, and the help fora, will be unavailable at some time on Thursday 8th.
  It's UWAweek 49

help2002

This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

Displaying the 6 articles in this topic
Showing 6 of 919 articles.
Currently 5 other people reading this forum.


 UWA week 31 (2nd semester, week 2) ↓
SVG not supported

Login to reply

👍?
helpful
9:23am Thu 4th Aug, Christopher M.

A number of students are asking about some of the commands or techniques that I use in lectures (usually to compensate for my slow typing), and perhaps watching those recordings too closely -:) . There isn't time in lectures to stop and explain them, and they are certainly not examinable, so let's collect some useful commands and tricks in this 'Software hacks' thread. Either just add to this thread, or choose the 'software hacks' tag for any new articles.


SVG not supported

Login to reply

👍?
helpful
9:40am Thu 4th Aug, Christopher M.

Adding coloured syntax-highlighting in vim. The default installation of vim simply displays its text in monochrome, but by adding commands to (one of) vim's "startup files", it will add colours to code keywords, comments, .... To download and add the necessary commands to vim's startup file: prompt> curl -o xxxxxx http://teaching.csse.uwa.edu.au/units/CITS2002/labsheets/vimrc prompt> cat xxxxxx >> ~/.vimrc prompt> rm -f xxxxxx Now, the next time you edit a, say, C file with vim if should provide coloured syntax-highlighting. If you're brave enough, you can manually change the colour-scheme by editing the ~/.vimrc file itself (using vim). And if you search the web for phrases such as "vim color scheme", you'll find many other pre-built schemes that you can download and install (usually in other vim startup files).


SVG not supported

Login to reply

👍?
helpful
9:45am Thu 4th Aug, James A.

So, we've got the helpful cheat-sheet on using frequent commands: [CITS2002] Your shell (the program that helps you manage and run commands in your terminal) also has a bunch of handy keyboard shortcuts that will make your life a lot easier. The biggest one to know about is using the up- and down-arrow keys to scroll through your command history to run again -- very handy when you're doing the same few steps over and over. There are plenty of good articles out there for reference, like this one: https://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-command-shell-for-ubuntu-debian-suse-redhat-linux-etc/


SVG not supported

Login to reply

👍x1
helpful
3:49pm Thu 4th Aug, Christopher M.

Using foreground/background job control in your shell The traditional (40+ year old) way to run the vim editor is inside the same window that receives your shell commands. I choose to edit files and compile them in the same window (and in most of my work) to simply save screen real-estate. So you can run the vim editor in the single window by simply executing the 'vim file.c' command at the prompt, and then leaving the editor with either :wq!<RETURN> or ZZ when finished editing (or just :q! to quit without saving changes). The second part is more complex, and will be covered later in the unit. Processes may be in one of a number of states - (simplified definition): - running in the foreground, receiving keyboard input - suspended, not running, receiving no input, or - running in the background, receiving no input. When working I first invoke a copy of the vim editor, and it runs in the foreground receiving input from the keyboard. I then type 2 keys at once - Control-Z - which suspends the vim process. The shell notices this, and issues the next prompt, and which I can run the compiler again (or any other commands). When I wish to resume execution of the vim process - shifting it from suspended to foreground - I type 'fg', the shell becomes suspended, vim resumes, detects that it's again running in the foreground, and redraws the screen. For this sequence to be effective, you also need the editor to write its changes to disk before becoming suspended. Either you can do this manually, which gets tiring and you may forget, or you can ask vim to do it automatically by setting an internal vim setting - :set autowrite<RETURN> Then, just before vim is suspended it writes its changes to disk, and the next compilation, etc, will be performed using the updated C file. In much the same way that shell aliases can be saved between visits, vim's settings can also be saved in a file named ~/.vimrc which you can edit with vim itself, appending the line: set autowrite (no leading colon). ____ See also: https://www.thegeekdiary.com/understanding-the-job-control-commands-in-linux-bg-fg-and-ctrlz/


SVG not supported

Login to reply

👍?
helpful
9:11pm Fri 5th Aug, Cody H.

Was wondering how to implement your "vc" command that you use to open a C template in vim. Thanks :)


SVG not supported

Login to reply

👍x1
helpful
7:35am Sat 6th Aug, Christopher M.

"Cody Howe" <22*7*6*[email protected]*u*e*t*u*a*e*u*a*> wrote:
> Was wondering how to implement your "vc" command that you use to open a C template in vim.
Oops, forgot that one. There's multiple ways to create new commands for your shell to execute: - shell aliases - usually single-line commands kept in the shell's memory - shell functions - usually multi-line commands kept in the shell's memory - shellscripts - usually multi-line commands stored in a text file on disk My "vc" command is a function, which is stored in a disk file and read by the shell each time the shell starts. Firstly, determine if you're using bash (probably on Linux), or using zsh (probably on macOS): prompt> echo $SHELL then, based on which shell you're using, append the following text to either ~/.bashrc (for bash) or ~/.zshrc (for zsh) :
vc () {
if [ ! -r try.c ]
then
cat << END_END > try.c
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char *argv[])
{

    return 0;
}
END_END
fi
vim +8 try.c
}
Now, exit the current shell, or start a new shell (or a new terminal window), and the new "vc" command should be found by your shell - creating a new file try.c, if necessary, and placing you in vim.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  1:17AM Sep 14 2022
Privacy policy