diff --git a/lorem-ipsum.md b/lorem-ipsum.md new file mode 100644 index 0000000..6a8f07f --- /dev/null +++ b/lorem-ipsum.md @@ -0,0 +1,44 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque accumsan +maximus nibh, commodo pellentesque sapien congue sed. Cras suscipit urna sed +nisl maximus, vitae dignissim lectus interdum. In non consectetur libero. +Maecenas at quam sed est luctus varius. Aenean rutrum, nibh eget malesuada +imperdiet, mauris felis gravida orci, vitae tincidunt dolor nunc sit amet +tortor. Vestibulum eget rhoncus arcu, ut interdum nulla. Phasellus quis lacus eu +purus scelerisque faucibus. In hac habitasse platea dictumst. Nullam efficitur +ex a tortor semper sagittis. Suspendisse potenti. Suspendisse vel auctor enim. +Sed sed pretium augue, ac commodo nunc. Sed malesuada enim est, non congue velit +gravida id. + +Duis suscipit consequat leo, et hendrerit arcu consectetur vel. Maecenas congue +porta finibus. Etiam in maximus enim. Curabitur ac dapibus felis, commodo +facilisis lorem. Aliquam urna ante, imperdiet non ipsum non, feugiat ornare +magna. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere +cubilia Curae; Sed vestibulum dolor erat, in posuere ipsum ultricies non. +Suspendisse potenti. Maecenas laoreet tincidunt elementum. + +Mauris eros ligula, volutpat non mollis non, mattis ornare quam. Donec et semper +mauris. Suspendisse dictum tortor ut massa tristique, ut sagittis elit +fermentum. Mauris pellentesque at diam at accumsan. Duis hendrerit tempor +sapien, quis faucibus libero sagittis ut. Sed vitae arcu nisi. Nulla ac nibh +diam. Suspendisse eget massa euismod, congue lorem a, fringilla nibh. Orci +varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus +mus. Nullam at quam non diam viverra ultrices ut ac nisi. Sed vel dapibus enim. +Mauris rutrum et libero sit amet fermentum. Pellentesque at nulla bibendum, +vulputate quam ac, laoreet turpis. Maecenas varius facilisis diam. + +Nam laoreet eros ac orci consequat condimentum. Maecenas dictum felis eget massa +imperdiet tempus. Proin viverra id erat in sagittis. Suspendisse id luctus +neque. Pellentesque posuere massa vel ex ultricies fermentum. Donec semper +sapien sed nunc porta congue. Aliquam elementum tortor non elit interdum, at +sagittis mi feugiat. Nunc ultricies nisl velit, eget mollis nulla pulvinar ac. +Nam consectetur magna in odio tempus porta. Class aptent taciti sociosqu ad +litora torquent per conubia nostra, per inceptos himenaeos. + +Integer ut dapibus ante, eget suscipit enim. Proin bibendum ligula quis +malesuada malesuada. Aliquam hendrerit imperdiet lorem, in condimentum tellus +varius nec. Donec mattis leo pharetra, vehicula orci vel, tristique ligula. +Donec lacinia tincidunt viverra. Etiam imperdiet eu odio laoreet facilisis. +Suspendisse non consectetur lacus, vel aliquam mi. Sed eu condimentum eros. +Pellentesque dolor nunc, tempor eget gravida nec, mollis vitae mi. Curabitur non +eleifend sem. Mauris vestibulum libero a nulla hendrerit gravida. Ut at sem +ullamcorper, fringilla erat et, fermentum ante. Fusce a scelerisque velit. diff --git a/lorem-ipsum.php b/lorem-ipsum.php new file mode 100644 index 0000000..ea5311d --- /dev/null +++ b/lorem-ipsum.php @@ -0,0 +1,53 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/** + * Some comment explaining this class. + */ +class LoremIpsum extends AnotherClass +{ + /** + * @var string + */ + protected $arg1 = ''; + + /** + * @var array + */ + protected $arg2 = []; + + public function __construct(string $arg1, array $arg2 = []) + { + $this->arg1 = $arg1; + $this->arg2 = $arg2; + } + + public function getSum(): int + { + if ($this->arg1 === '+') { + return 1 + 2; + } + + return 1 - 2; + } +} diff --git a/lorem-ipsum2.php b/lorem-ipsum2.php new file mode 100644 index 0000000..d6e4906 --- /dev/null +++ b/lorem-ipsum2.php @@ -0,0 +1,43 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/** + * Some comment explaining this class. + */ +class LoremIpsum2 extends AnotherClass +{ + /** + * @var LoremIpsum + */ + protected $loremIpsum; + + public function __construct(LoremIpsum $loremIpsum) + { + $this->loremIpsum = $loremIpsum; + } + + public function getSum(): int + { + return $this->loremIpsum->getSum(); + } +} diff --git a/readme.rst b/readme.rst new file mode 100644 index 0000000..540bf54 --- /dev/null +++ b/readme.rst @@ -0,0 +1,208 @@ +Vim introduction workshop +========================= + +Welcome +------- + +First things first, how to start and *quit* Vim. + +To start Vim, just type `vim` into the terminal. + +To exit Vim, try `CTRL+C` like for nearly all CLIs. Vim will display a help message +in the bottom left with instructions how to quit Vim: + + Type :qa! and press to abandon all changes and exit Vim + +So lets type in `:qa!` to quit Vim again. + +Settings +-------- + +By default Vim comes with no useful settings. Most developers like line numbers which +can be turned on by typing `:set number`. + +Run `vim lorem-ipsum.md` and type `:set number` to activate line numbers. + +If you quit Vim and re open the file, line numbers are gun. Settings adjusted within +a session are not persisted. We get back to that later. + +The concepts +------------ + +We now have the basics, let's learn some basic concepts. + +Vim is a mode editor. Most editors are mode less. + +What is a mode? + +NORMAL +^^^^^^ + +This is the default mode when you start Vim. If you open a file, e.g. `vim lorem-ipsum.md` +keys are used to navigate in this file. E.g. use `h`, `j`, `k` and `l` to move the +cursor around. + +TASK: Navigate a bit within `lorem-ipsum.md`. + +Press `ESC` from any mode to come back to the `NORMAL` mode. + +VISUAL +^^^^^^ + +Sometimes you want to highlight something, e.g. for a presentation or to interact +with the highlighted parts. + +You can enter different Visual Modes, e.g. + +`v` + Will start `VISUAL` mode where you can highlight stuff using the same keys as in + `NORMAL` Mode. + + TASK: Highlight line 19. + +`V` + `VISUAL LINE` to highlight lines, useful for presentations. + + TASK: Highlight line 19. + +`CTRL+v` + `VISUAL BLOCK` to highlight blocks, useful for tables. + + TASK: Highlight column 2. + +INSERT +^^^^^^ + +Insert some text, keys will be passed through as insertions. + +Enter the `INSERT` mode by one of the following keys: + +`a` + Append behind the cursor + +`i` + Insert at the cursor + +`A` + Append at the end if line + +`I` + Insert at beginning of the line + +TASK: Insert todays date at the end of the file. + +REPLACE +^^^^^^^ + +Replace some text, keys will be passed through as replacements. + +`r` + Replaces a single character. + +`R` + Switches to `REPLACE` mode. + +TASK: Replace last line with todays date. + +COMMAND +^^^^^^^ + +Executes commands within Vim, e.g. adjust settings or quit. + +`:` + Inserts the command mode. The cursor will be set to the command line. + The command mode has auto completion, just press `TAB`. + + TASK: Activate line numbers, quit Vim. + +And there are more Modes. + +Better movement +--------------- + +So far we now that we can move around in `NORMAL` mode with `h`, `j`, `k` and `l`. +There are more keys to move around. E.g.: + +`G` + Go to end of file. + +`gg` + Go to beginning of file. + +Most movements can be prefixed with a count, that's called Vim Grammar. So to move to +Line x type `xG`. + +TASK: Highlight Line 19 by jumping to Line 19. + +Most of the time we are not working with text documents but source code. So how to +move efficiently within source code? We will explain the help, to allow you to figure +out yourself. + +Help +---- + +Vim has a huuuuge documentation on board. This can be accessed via `:help`. + +The help consists of a guide, reference, topics and plugins. + +Code navigation Part 1 +---------------------- + +Let's check out `:help object-motions` to get further movements. + +TASK: `vim lorem-ipsum.php` and navigate to the 2nd method via `]]` + +Code navigation Part 2 Plugins +------------------------------ + +There are a bunch of plugins and even some plugin manager to choose from. + +To navigate within Code I use CTRLP and Tagbar in combination with Universal Ctags. + +* TASK: Check out the benefits, run `nvim lorem-ipsum.php` and type in `,r`. + +* TASK: Check out the benefits, run `nvim lorem-ipsum.php` and type in `,b`. + +Code navigation Part 3 Go to definition +--------------------------------------- + +Vim provides support for tags out of the box. Using `CTRL+]` we can jump to the +definition of something. + +TASK: Run `vim lorem-ipsum2.php` to to the constructor and run `CTRL+]` on +`LoremUpsum` type hint. + +Efficient editing +----------------- + +We now know some basics to move within source code. What about editing? + +Let's change the content of an PHP if condition to just false. + +TASK: Change content of if condition within `lorem-ipsum.php` within the `getSum` +method. + +Vim provides operators within the `NORMAL` mode. These can be copy, delete, change, +uppercase. In our case we want to change the condition = `c`. Following Vim Grammar, +this can be combined with either a count as prefix, or a motion as suffix. + +In our case we want to change text within `()` as this is the condition in PHP. We +can achieve this by typing `ci(` within the braces. + +What's next? +------------ + +That were some basics. What is most important to you? What would you miss when using +Vim? Let's provide some guidance to make you more productive within Vim in your daily +work. + +References +---------- + +* https://daniel-siepmann.de/Posts/Migrated/2015-10-10-vim-linklist.html + +* https://vimawesome.com/plugin/ctrlp-vim-red + +* https://vimawesome.com/plugin/tagbar + +* https://ctags.io/