Praktische Aspekte der Informatik Moritz Mhlhausen Prof. Marcus - - PowerPoint PPT Presentation

praktische aspekte
SMART_READER_LITE
LIVE PREVIEW

Praktische Aspekte der Informatik Moritz Mhlhausen Prof. Marcus - - PowerPoint PPT Presentation

Praktische Aspekte der Informatik Moritz Mhlhausen Prof. Marcus Magnor https://graphics.tu-bs.de/teaching/ss19/padi/ Vim Exit command, basic vim commands, handling several files https://graphics.tu-bs.de/teaching/ss19/padi/ Further Reading


slide-1
SLIDE 1

Praktische Aspekte der Informatik

Moritz Mühlhausen

  • Prof. Marcus Magnor

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-2
SLIDE 2

Vim

Exit command, basic vim commands, handling several files

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-3
SLIDE 3

Further Reading

Warning!

The following slides are meant to give you a very superficial introduction. If you want to learn more, have a look at:

https://vim.sourceforge.io/docs.php

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-4
SLIDE 4

Outline

  • What is Vim?
  • How to exit Vim?
  • Basic Vim commands
  • Handling several files
  • Configure your Vim
  • Try out VimGolf!

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-5
SLIDE 5

What is Vim?

  • Highly configurable text editor
  • Macros, Colortheme, indent configurable
  • Very fast editing of files
  • Only needs a terminal, works even when emacs stops

working

  • Vi Improved
  • Vim is free! It is open source with a charityware

license.

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-6
SLIDE 6

What is Vim? – Why?

*temp var1 0 *temp var2 "hi" *temp var3 -1 *temp var4 42 *temp var5 "asdf" *temp var6 0 Simple things we do all the time should be able to be done with very few keystrokes, but sometimes I find something I need to do makes me go, "There MUST be a better way." This challenge is just a simple movement and entering text at a certain place. *temp var1 0 *temp var2 "hi" *temp var3 -1 *temp var4 42 *temp var5 "asdf" *temp var6 0 *temp var7 11 Simple things we do all the time should be able to be done with very few keystrokes, but sometimes I find something I need to do makes me go, "There MUST be a better way." New text. This challenge is just a simple movement and entering text at a certain place.

22 Keystrokes only

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-7
SLIDE 7

How to exit Vim?

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-8
SLIDE 8

How to exit Vim?

  • Vim usually starts in normal mode
  • Use the command :q<Enter> to exit
  • :q!<Enter> to exit with losing all edits
  • :wq<Enter> for saving and exit
  • If you are not in normal mode, hit <ESC>
  • Lower left indicates which mode is active

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-9
SLIDE 9

How to exit Vim? – Vim Modi

  • Vim has several modi
  • Normal mode
  • Command mode
  • Insert mode
  • Visual mode

Normal End Start Visual Command Insert

ZZ : z.B. i z.B. v <ESC> <ESC> <ESC> z.B. wq<ENTER>

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-10
SLIDE 10

Basic Vim Commands – Emergency Kit

  • Inserting Text
  • Type i, the lower left of the screen should show --INSERT--
  • Now you can work like in a usual editor
  • Exit --INSERT-- mode with <ESC> when done
  • Moving around
  • h (left), j (down), k (up), l (right)
  • Easier moving without moving your hand
  • Deleting characters
  • Move the cursor over the character to delete and type x
  • Stay in normal mode, deleting only a single character

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-11
SLIDE 11

Basic Vim Commands – Emergency Kit

  • Undo and Redo
  • Accidentally some vim-magic happened?
  • First go back to normal mode by <ESC>
  • Type u to undo the last edit
  • Type <CTRL-r> to redo last undo
  • Saving and getting out
  • Type :w<ENTER> to save (write) the current state of the file
  • Type :q<ENTER> to exit after saving
  • Combine it to :wq<ENTER> to save and exit
  • ZZ will do the same with less strokes

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-12
SLIDE 12

Basic Vim Commands – Editing Faster

  • Using a count
  • Executes a command several times
  • 3j goes down 3 lines
  • 3iabc<ESC> inserts “abcabcabc”
  • Saving Macros
  • q<Macrokey><Command>q saves the <Command> on

<Macrokey>

  • @<Macrokey> executes the saved command
  • Executing last text edit again
  • . executes the last edit again
  • Pure movements are ignored

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-13
SLIDE 13

Basic Vim Commands – More Commands

  • Uppercase keys have similar commands
  • Makes them quite intuitive
  • Go to insert mode
  • I/i go to insert mode in front of line/cursor
  • A/a go to insert mode at end of line/cursor
  • O/o insert news line above/below line and go to insert mode
  • Moving in file
  • G/gg move to end/start of file
  • <Number>G move to line <Number>
  • w/b move to start of next/prior word
  • e/ge move to end of next/prior word

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-14
SLIDE 14

Handling several Files

  • Tabs
  • :tabe <File> will open the <File> in a new tab, after the

current one

  • gt / gT switches to the next / previous tab
  • <Count>gt switches to the <Count>th tab
  • Split window
  • :sp / :vsp splits the window horizontally / vertically
  • <CTRL-w>h/j/k/l move the cursor to the

left/bottom/top/right split

  • Splits can vary between Tabs
  • <CTRL-w>T turn the current split into a tab

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-15
SLIDE 15

Configure your Vim

  • Create/edit .vimrc / _vimrc file in your home folder
  • Contains optional runtime configuration settings to

initialize Vim

  • set numbers show the line numbers
  • set cindent automatic C-like indenting
  • “ for comments
  • ab for abbreviations
  • It is a good start to look up some standard .vimrc

and keep updating to your desire

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-16
SLIDE 16

A good start: vimtutor

  • vimtutor comes along with vim
  • (interactive) vim tutorial in a terminal
  • In vim!!
  • Learn basic commands
  • Moving
  • Exiting
  • Editing
  • Just type „vimtutor“ in a terminal to start

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-17
SLIDE 17

More advanced techniques: Try VimGolf!

  • https://vimgolf.com/
  • Real Vim ninjas count every keystroke - do you?
  • Edit a specified file with as few keystrokes as possible
  • See solutions of others within a certain range of your entry
  • Learn new commands or combinations
  • To make it fair, VimGolf uses a predefined .vimrc
  • No copy/paste from solution file allowed
  • No external scripts allowed

https://graphics.tu-bs.de/teaching/ss19/padi/

slide-18
SLIDE 18

Church of Vim

Vim was originally an extensible text editor written by Bram Moolenaar, but it became a way of life and a religion. To join the Church of Vim, you need only pronounce the Confession of the Faith: http://www.avelino.xxx/2015/03/church-vim

There is no system but GNU, and Linux is one of its kernels.

https://graphics.tu-bs.de/teaching/ss19/padi/