TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
The Joy of Vim
1. The Joy of Vim
Johan Jansson / Oy Raisoft Ltd
devTalk Kokkola 3.12.2019
2. Raisoft intro
• Founded year 2000 in Kokkola
• 50+ employees – offices in Kokkola and Jyväskylä + remote contractors
• Revenue in the 7 figures range
Products
• RAIsoft.net (web based SaaS & On Premise solution)
A comprehensive software solution for measuring functional performance
and health status, as well as quality and effectiveness of care.
– Market: Finland, Switzerland, Spain, Singapore, Australia, …
• Smart Break: 3 minute workplace wellness solution
3. Personal background
Early editing
• First editor experience: edlin (late -80s)
Advanced editing
• Emacs (late -90s)
• “Vi is standardized in POSIX, so it’s available on almost all platforms”
• Easy to achieve hero status at the university
• Vi < Vim
Today
• CTO at Raisoft & part-time researcher
• Use Vim daily for code, config files, commit messages, log viewing, documents, email, data munging,
etc.
5. The Joy of Vi
Bill Joy, the creator of the Vi editor
Vi was released in 1976
Joy was influential in other projects as well
• BSD UNIX
• NFS
• Java
6. The Joy of Vim
Bram Moolenaar, the creator of Vim
Released Vim in 1991
Fun fact:
Initially a vi-clone based on
another vi-clone ported to the Amiga.
8. Vim intro
• Highly configurable text editor
• Available as GUI and in the console
• Rock stable, actively maintained
• Extensive plugin system
• Support for hundreds of programming languages and file formats
• Powerful macros, and search/replace
• Integrates well with many tools
• It’s a modal editor.
• It has a very powerful command system.
• There are other editors. I’m happy for you if you’ve found a good one.
10. We choose to learn Vim.
Not because it’s easy, but because it’s hard.
https://lucasfcosta.com/2016/09/25/How-I-Learned-to-Stop-Worrying-and-Love-vIM.html
11. We choose to learn Vim.
Not because it’s easy, but because it’s hard efficient.
https://lucasfcosta.com/2016/09/25/How-I-Learned-to-Stop-Worrying-and-Love-vIM.html
14. Composing edit commands
Vim command: ACTION x TEXT OBJECT
ACTIONs:
• cut, delete, copy, paste
• autoformat/indent
• change case: upper/lower/invert
• search/replace
• increment/decrement
• select (=> visual mode)
• etc.
TEXT OBJECTs:
• text: char, word, line, sentence, paragraph
• blocks: ”...”, (...), [...], {...}, <...>
• code: xml/html tags
• range of lines
• cursor motion from current position:
– to start/end of text objects
– to next/previous search match
– to next/previous occurrence of character
15. Composing edit commands - examples
Vim command: ACTION x TEXT OBJECT
diw delete inside word
yi) copy inside ( ) parens
=a} auto-indent around { } braces
CHALLENGE:
Learn 10 actions, and 10 text objects:
you’ll be able to compose 100 commands.
16. Composing macros
Vim macro: recorded keyboard input.
=> Compose macros of multiple commands.
1. Start recording: q{name}
– qa records macro a
2. Edit, using re-usable commands (avoid using mouse input, use motion commands to move)
3. End macro: q
4. Replay macro:@a
You can record many different macros: registers a-z
17. DEMO: macros
DEMO 1:
convert for (var property in object) {…}
into object.forEach((property) => {…});
wwwwwdwNPa.<ESC>elsEach<ESC>wwdwi(<ESC>elct{) => <ESC>l%A);<ESC>
• 22 commands in total.
• Composed of a set of 7 actions x 6 text objects:
– Actions: d, P, a, s, i, c, A
– Text objects/motions: w, N, e, l, t, %
18. Macros & The Multiplication Principle of Combinatorics
So, you learnt 10 actions & 10 text objects.
you are able to compose 100 distinct commands.
How many 22-command macros can you create?
10022 = 100 000 000 000 000 000 000 000 000 000 000 000 000 000 000
(100 tredecillions)
Your imagination is the limit.
19. Other useful features
• Screen layout – split screen windows & tabs
• Spell check
• Auto-completion (text from files, dictionary, code
identifiers, file names, etc.)
• Edit files over scp
• Regex (search/replace)
• Vimdiff
• Auto-commands
• Shell integration
• Vimscript
• Registers
• Extensive plugin system
• Customizable key mappings
• Auto-formatting/highlighting
• Filters (process text with external program)
• Dot command . repeats last command in normal
mode
• Built-in-grep
• Compiler integration
• Comprehensive help system
• Built-in terminal
• File browser
20. DEMO composing features:
edit your file system with shell integration and vimdiff
DEMO 2: Clean up build server
• 3-way diff of directories on Jenkins build server
• Shell integration :r !<command> will read command output into vim buffer
• Split screen into multiple windows
• Diff windows with :windo diffthis
DEMO 3: Remove extra artifact directories
• Macros may execute shell commands
• Shell integration :!<command> will execute a shell command
21. CONCLUSION
• Composition is a powerful concept.
• Learn your editor well.
• Practice makes perfect.
• Learning curve = compound interest efficiency!
• My vim config: https://github.com/jupj/vimconfig
• Take the challenge!
• Start with 5 x 5.