Lecture 5: Review + Basic Commands Part I Recurring Themes Part II Core Commands
Announcements • Homework 2 is due now! • Midterm next week! • Format is similar to hws, focus on writing clear descriptions that do exactly what you want to do. • Describe don't explain. • Covers everything in previous lectures, and parts of hws that do not have a '*'.
Case Study: Simple Class declaration to definition in C++ • This is a very simplistic example! • C++ is well known for being notoriously hard to parse. • More complicated examples involve a lot of case handling (macro termination). • We will assume that the class declaration is consistent in style, with no templates, virtuals, inlines, etc. (you do not have to know what that means, you can do it easily with a few tweaks though, we won't explicitly state it in the interest of time) • We will assume that the class declaration follows a specific format, including comments. • We won't worry about indenting and extra lines for now.
Class declaration
Class declaration
Class definition
Walkthrough • Things to remove: • #includes • usings • class ... • member variables • We will try to do it to match a general format.
Walkthrough • Descriptions: • Locate '#include' • Delete Line. • Repeat (...) • Locate 'using' • Delete Line. • ...
Walkthrough • Descriptions: • Locate 'public:' • Delete Line • ... • Locate 'private:' • Delete Line • ...
Walkthrough • Descriptions • Locate 'm_' • Delete Line • ... • Locate 'variables' • Delete Line
Walkthrough • Descriptions • Locate 'class' • Delete Line • Locate '};' • Delete Line • Goto top of document. • insert '#include "extclass.h"' • So now we've done the most trivial part.
Walkthrough • Declaration -> definitions • Complication: there are comments • First thing: is it a comment? • For now, reasonably assume that the comment probably does not contain '(' • Hence, we will exploit the macro termination behavior (shown in hw).
Walkthrough • Description: • goto the ';' within the line • goto the beginning of line
Walkthrough • Description: • goto the ';' within the line • goto the beginning of line • If it is a comment, it will terminate, since we assume that comments will not contain ';'. • Macro termination • (you can also come up with more complicated checks, such as '(', ')' and ';')
Walkthrough • Description: • goto the ';' within the line • goto the beginning of line • Functions in C++ have this format: • <type> <name>(<params>) { <body> }
Walkthrough • Functions in C++ have this format: • <type> <name>(<params>) { <body> } • However, we are using a definition file, so we will have to add a class scope (this is syntatic).
Walkthrough • Description: • goto the ';' within the line • goto the beginning of line • Functions in C++ have this format: • <type> <name>(<params>) { <body> }
Walkthrough
Walkthrough • Description: • goto the ';' within the line • goto the beginning of line • Functions in C++ have this format: • <WORD> <WORD>(<> object>) { <} object> }
Walkthrough • Description: • goto the ';' within the line • goto the beginning of line • goto next word • insert 'FindCat::' • goto the ';' within the line • change the word ';' to '<CR>{<CR>}' • Functions in C++ have this format: • <WORD> <WORD>(<> object>) { <} object> }
Walkthrough • Description: • goto the ';' within the line • goto the beginning of line • goto next word Record macro to • insert 'FindCat::' register 'a' • goto the ';' within the line • change the word ';' to '<CR>{<CR>}'
Walkthrough • Description: • goto the ';' within the line • goto the beginning of line • goto next word Record macro to • insert 'FindCat::' register 'a' • goto the ';' within the line • change the word ';' to '<CR>{<CR>}' • Next line. Run macro on register 'a'. • ...
Walkthrough • Questions?
Walkthrough • Questions? • Good news: this will be the first question in the midterm
Walkthrough • Questions? • Good news: this will be the first question in the midterm • Good news 2: we've already covered everything you need to know for the midterm! (you do NOT need to know commands for the midterm!)
Quick Review • We have talked about these topics: • ergonomics • descriptions • relative numbers are bad • fuzzy descriptions • cheating/relative/distinctive • cursor/screen policy • dot command • macros and termination
• Bare bones commands • Setting non boolean options • Skimming commands
• Bare bones commands • Setting non boolean options • Skimming commands
Bare bones commands • Buffers are... – not windows
Bare bones commands • Buffers are... – not windows – vim's way of keeping track an opened file or scratch file – do not guarantee one to one mappings to windows
Bare bones commands • Buffers are... – not windows – vim's way of keeping track an opened file or scratch file – do not guarantee one to one mappings to windows – Oftentimes hidden, cannot be 'closed', may hide instead – Bottom line: buffers can be hidden, loaded and deleted. Windows can be opened and closed. Buffers are still there when you close a window. – demo ( :ls<CR> )
Bare bones commands • As per unix standard, starting up vim: vim <flags/options> <filenames> • on the command line.
Bare bones commands • As per unix standard, starting up vim: vim <flags/options> <filenames> • on the command line. • Running 'vim' with no flags and filenames just loads up vim with 1 window, 1 empty buffer, 0 args.
Bare bones commands • As per unix standard, starting up vim: vim <flags/options> <filenames> • Ex. vim hello.txt goodbye.txt • Loads both hello.txt and goodbye.txt in two buffers, but 1 window.
Bare bones commands • As per unix standard, starting up vim: vim <flags/options> <filenames> • Ex. vim hello.txt goodbye.txt • Loads both hello.txt and goodbye.txt in two buffers, but 1 window. We'll talk about windows/buffer in great detail in the future.
Bare bones commands • As per unix standard, starting up vim: vim <flags/options> <filenames> • Ex. vim -O hello.txt goodbye.txt • Loads both hello.txt and goodbye.txt in two buffers, with 2 corresponding vertical windows.
Bare bones commands • As per unix standard, starting up vim: vim <flags/options> <filenames> • Important flags: • -o -- opens <filenames> in seperate horizontal windows • -O -- vertical windows • -d -- diff mode • - -- reads from pipe • More in :h vim-arguments
Bare bones commands • Within vim: • the ex command :e <filenames><CR> • opens files in different buffers, but does not change the number of windows. • Buffers and windows are NOT the same thing... We will only deal with single files (and single buffers) for now.
Bare bones commands • Writing to a file • the ex command :w <filename><CR> • writes to <filename>. If no params are given, writes to current file in current buffer. :wa<CR> • writes to all files in all current buffers.
Bare bones commands • Quiting Vim • the ex command :qa<CR> • Quits Vim. • Quit behavior: • If there are edited yet unsaved buffers , it will prompt an error instead of quiting! • Safety feature.
Bare bones commands • Quiting Vim without writing (Force quiting) • the ex command :qa!<CR> • Quits Vim. • If there are edited yet unsaved buffers , it will quit but not save!
Bare bones commands • Quit Vim and writes all files in all buffers. • the ex command :xa<CR> • Quits Vim and ... 1. If a buffer is edited yet unsaved, it is written/saved. 2. If a buffer is unedited, it is left as-is, and untouched. This is probably what you want most of the time (demo hello.cpp).
Next Time • Midterm! • Remember: everything covered in previous lectures and hws except marked with '*'. • Then it's break, yay! :-)
Recommend
More recommend