Commands Part I Recurring Themes Part II Core Commands - - PowerPoint PPT Presentation

commands
SMART_READER_LITE
LIVE PREVIEW

Commands Part I Recurring Themes Part II Core Commands - - PowerPoint PPT Presentation

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


slide-1
SLIDE 1

Lecture 5: Review + Basic Commands

Part I Recurring Themes Part II Core Commands

slide-2
SLIDE 2

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 '*'.

slide-3
SLIDE 3

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.

slide-4
SLIDE 4

Class declaration

slide-5
SLIDE 5

Class declaration

slide-6
SLIDE 6

Class definition

slide-7
SLIDE 7

Walkthrough

  • Things to remove:
  • #includes
  • usings
  • class ...
  • member variables
  • We will try to do it to match a general

format.

slide-8
SLIDE 8

Walkthrough

  • Descriptions:
  • Locate '#include'
  • Delete Line.
  • Repeat (...)
  • Locate 'using'
  • Delete Line.
  • ...
slide-9
SLIDE 9

Walkthrough

  • Descriptions:
  • Locate 'public:'
  • Delete Line
  • ...
  • Locate 'private:'
  • Delete Line
  • ...
slide-10
SLIDE 10

Walkthrough

  • Descriptions
  • Locate 'm_'
  • Delete Line
  • ...
  • Locate 'variables'
  • Delete Line
slide-11
SLIDE 11

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.
slide-12
SLIDE 12

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).

slide-13
SLIDE 13

Walkthrough

  • Description:
  • goto the ';' within the line
  • goto the beginning of line
slide-14
SLIDE 14

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 ';')

slide-15
SLIDE 15

Walkthrough

  • Description:
  • goto the ';' within the line
  • goto the beginning of line
  • Functions in C++ have this format:
  • <type> <name>(<params>) { <body> }
slide-16
SLIDE 16

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).

slide-17
SLIDE 17

Walkthrough

  • Description:
  • goto the ';' within the line
  • goto the beginning of line
  • Functions in C++ have this format:
  • <type> <name>(<params>) { <body> }
slide-18
SLIDE 18

Walkthrough

slide-19
SLIDE 19

Walkthrough

  • Description:
  • goto the ';' within the line
  • goto the beginning of line
  • Functions in C++ have this format:
  • <WORD> <WORD>(<> object>) { <} object>

}

slide-20
SLIDE 20

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> }
slide-21
SLIDE 21

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>}'

Record macro to register 'a'

slide-22
SLIDE 22

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>}'
  • Next line. Run macro on register 'a'.
  • ...

Record macro to register 'a'

slide-23
SLIDE 23

Walkthrough

  • Questions?
slide-24
SLIDE 24

Walkthrough

  • Questions?
  • Good news: this will be the first

question in the midterm

slide-25
SLIDE 25

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!)

slide-26
SLIDE 26

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
slide-27
SLIDE 27
  • Bare bones commands
  • Setting non boolean options
  • Skimming commands
slide-28
SLIDE 28
  • Bare bones commands
  • Setting non boolean options
  • Skimming commands
slide-29
SLIDE 29

Bare bones commands

  • Buffers are...

– not windows

slide-30
SLIDE 30

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

slide-31
SLIDE 31

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>)

slide-32
SLIDE 32

Bare bones commands

  • As per unix standard, starting up vim:

vim <flags/options> <filenames>

  • on the command line.
slide-33
SLIDE 33

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.

slide-34
SLIDE 34

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.

slide-35
SLIDE 35

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.

slide-36
SLIDE 36

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.

slide-37
SLIDE 37

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
slide-38
SLIDE 38

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.

slide-39
SLIDE 39

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.
slide-40
SLIDE 40

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

  • f quiting!
  • Safety feature.
slide-41
SLIDE 41

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!

slide-42
SLIDE 42

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).

slide-43
SLIDE 43

Next Time

  • Midterm!
  • Remember: everything covered in

previous lectures and hws except marked with '*'.

  • Then it's break, yay! :-)