15:32:41 #startmeeting VIM Classroom repeat for APAC time zone 15:32:41 Meeting started Wed Jan 18 15:32:41 2012 UTC. The chair is FranciscoD. Information about MeetBot at http://wiki.debian.org/MeetBot. 15:32:41 Useful Commands: #action #agreed #halp #info #idea #link #topic. 15:33:00 To start with how many folks here for the class room? 15:33:22 * FranciscoD waits for a response 15:33:33 +1 15:33:44 FranciscoD, +1 15:33:44 ah, at least one ;) 15:33:47 okay 15:33:58 to start with, please install the required pacakges: 15:34:13 ready. 15:34:35 +1... sort of. Have $dayjob to attend to. 15:34:36 yum install vim vim-X11 vim-vimoutliner 15:34:55 please install the related packages if you're not on fedora 15:35:02 * bckurera is started learning 15:35:19 I'll wait for you folks to install them 15:35:27 let me know when you're done :) 15:35:55 I m already equipped with vim 15:36:00 while waiting....may I start questions? 15:36:21 luceliofreitas: yes, sure, 15:36:25 you can ask one question ;) 15:36:37 (to avoid using too much time) 15:37:07 okay, assuming everyones installed the packages, 15:37:12 #topic invocation 15:37:35 why vim? I'm used to kate. 15:37:39 Done with install. 15:37:42 please download this file to a directory 15:37:47 luceliofreitas: that question is out of scope, sorry 15:38:09 the class is not intended to market vim 15:38:25 it is for those who wish to learn how to use it properly, by choice 15:38:49 ok. is my case. 15:38:54 please download this my file: http://ankursinha.fedorapeople.org/fedora-classroom.txt 15:39:00 FranciscoD, +1 15:39:01 to some directory, 15:39:09 we'll make use of this for excercises 15:39:36 once you're done, 15:39:40 please open a terminal 15:39:50 go to the directory (cd 15:39:53 ) 15:39:55 ls should show the file 15:40:07 you can use wget http://ankursinha.fedorapeople.org/fedora-classroom.txt straight away too ;) 15:40:15 simplest invocation: 15:40:19 vim 15:40:32 that should open the file for you in vim 15:40:40 * FranciscoD waits for folks to complete this step 15:40:52 Done. 15:40:57 FranciscoD, done 15:41:02 done 15:41:21 okay, great 15:41:29 lets get out of vim 15:41:32 press "ZQ" 15:41:40 that is capital Z followed by capital Q 15:41:48 ZQ = quit without saving 15:42:04 you should be back on the terminal 15:42:27 any issues here? 15:42:30 * FranciscoD waits 15:42:41 no 15:42:50 great 15:42:52 next 15:42:55 reopen the file 15:42:59 no 15:43:38 hit ctrl G 15:43:42 that will give you info on the file 15:44:11 lets quit again, and get back to the terminal 15:44:30 c cp fedora-classroom.txt another-classroom.txt 15:44:40 cp fedora-classroom.txt another-classroom.txt 15:44:45 make a copy 15:45:21 vim -p fedora-classroom.txt another-classroom.txt 15:45:30 you should see *2* tabs 15:45:39 one with each copy of the file 15:45:58 to switch b/w tabs: 15:46:04 gT and gt 15:46:07 try it 15:46:11 * FranciscoD waits 15:46:24 gt: next tab 15:46:28 gT: previous tab 15:46:40 stop me if you run into any issues please 15:46:50 works for me 15:46:59 yes it's working 15:47:02 yes 15:47:13 great, lets get back to the terminal 15:47:23 #topic modes 15:47:46 open one of the two files 15:47:57 by default, the file is opened in COMMAND mode 15:48:13 which is why ZQ didn't insert ZQ into the document like in Notepad 15:48:27 also why gT and gt didnt insert text 15:48:38 in command mode, the various mappings have various functions 15:48:44 Kool, tabs! 15:48:59 lets see another mode: INSERT mode 15:49:05 in insert mode, vim is notepad 15:49:24 to enter insert mode, hit "i" 15:49:27 small i 15:49:50 now, you can insert text, delete text, use the arrow keys to navigate 15:49:55 etc etc 15:50:00 just like notepad 15:50:23 run around a little, edit stuff if you want 15:50:56 to get out of insert mode, and back into command mode, hit esc 15:51:01 try thsi out 15:51:10 switch between them a few times 15:51:21 next, a third mode: ex mode 15:51:36 in command mode, hit ":" 15:51:38 (colon) 15:51:53 a colon should pop up in the lower right hand corner 15:52:22 write "wq" and hit enter 15:52:31 total-> :wq in command mode 15:52:38 wq -> save and quite 15:52:41 er.. quit 15:52:50 so you can use whatever method you are comfortable with 15:53:09 to quit without saving, hit ":wq!" 15:53:32 any issues 15:53:37 ? 15:53:37 * FranciscoD waits 15:53:41 no 15:53:46 done 15:53:54 no 15:54:13 now, we are going to learn how to use vim correctly, efficiently 15:54:13 Done. 15:54:24 Wait, shouldn't "wq!" be "q!" 15:54:33 to quit without saving 15:54:50 JorisL_42: ugh, correct 15:55:06 thanks 15:55:23 okay, open the file, *stay* in command mode 15:55:46 h,j,k,l 15:55:57 hit these, see what happens 15:56:08 j - down 15:56:10 k - up 15:56:12 h - left 15:56:15 l - right 15:56:28 the idea is to stay in command mode, and only go into insert mode when necessary 15:56:41 now, this moves column by column or line by line 15:56:47 what if i want to move quicker? 15:56:51 try: 15:57:06 w, b 15:57:08 e 15:57:14 you should move wordwise 15:57:19 with subtle differences 15:57:27 also try: W, B, E 15:58:04 the capital versions ignore punctuations 15:58:12 all okay till here? 15:58:18 yes 15:58:24 yes 15:58:33 yes 15:58:40 yes 15:58:48 try: "G" 15:58:56 and then "gg" 15:59:03 thats two small gs in quick succession 15:59:26 try: 45G 15:59:38 goes to line 45 15:59:58 try 13| (13 followed by pipe) -> goes to column 13 16:00:17 try: "$" 16:00:19 and "0" 16:00:24 end of line, beginning of line 16:00:54 what you need to see is, that you can move around the file using minute key strokes 16:00:55 me i use http://fpaste.org/wLX6/ into vimrc for use my mouse 16:01:16 * bioinfornatics hide 16:01:22 bioinfornatics: yeah, some of us dont like to leave the home row on the keyboard to use the mouse 16:01:33 ;) 16:01:36 wastes time 16:02:01 move *sentence* wise: 16:02:23 ( and ) 16:02:28 for forward and backward 16:03:06 or, move *paragraph* wise: { and } 16:03:19 all okay? 16:03:36 FranciscoD, is it just me, or ^ should (not) act as 0, too 16:03:58 meka: 0 goes to column 0, while ^ goes to the first non spaced letter of the line 16:04:11 FranciscoD, ok, thanx 16:04:22 so if you have something that begins with a tab, 0 will still go to column 0, but ^ will go to 4 16:04:33 (depending on the tabwidth) 16:04:48 ok, I got it 16:05:07 now, most of these commands can be prefixed my a number 16:05:18 which tells vim how many times to repeat the command 16:05:32 so "4j" will take you down *4* lines 16:05:43 try it out with the other commands: hjkl web 16:05:50 see if it works as expected 16:06:12 and stop me if anyone gets stuck 16:06:20 remember, we are still in command mode 16:06:38 okay 16:06:47 if you want to move about even quicker: 16:06:51 ctrl f -> forward 16:06:55 ctrl b -> backward 16:06:59 ctrl u -> up 16:07:03 ctrl d -> down 16:07:43 will someone tell me the difference in ctrl f and ctrl d? 16:08:08 f moves by the screen full iirc 16:08:23 while d mimics page down 16:08:43 should we look at ex mode then? 16:08:47 * FranciscoD waits for responses and queries 16:08:58 what does iirc means? 16:09:09 "if i recall correctly" 16:09:11 ;) 16:09:25 anything else? 16:09:34 okay 16:09:51 now you already know how to invoke ex mode (use ":") 16:10:05 ex mode works on lines 16:10:09 try 16:10:12 ":40" 16:10:21 should take you to line 40 16:10:40 most of the vim config commands are given in this mode too 16:10:44 for instance, 16:10:45 try: 16:10:48 ":set nu" 16:10:54 that should give you line numbers 16:11:19 to remove line numbers: 16:11:19 ":set nonu" 16:11:19 works for everyone? 16:11:27 yes 16:11:29 yep 16:11:36 #chair FranciscoD_ 16:11:36 Current chairs: FranciscoD FranciscoD_ 16:11:36 yes 16:11:38 yes 16:11:43 great 16:11:58 lets see some more complex stuff: 16:12:01 try: 16:12:41 ":%s/Fedora/The Fedora/" 16:12:55 what does that do? 16:13:00 replace? 16:13:07 let me break it up 16:13:11 meka: search and replace, yes 16:13:18 in ex mode, 16:13:22 % -> on every line 16:13:34 s -> search and replace (like sed if anyones used it) 16:13:45 s/search string/replacement string/ 16:14:03 thos only replaces the first occurence of "Fedora" on each line 16:14:10 to replace *all* of them 16:14:15 ":%s/Fedora/The Fedora/g" 16:14:21 notice the "g" at the end 16:14:32 oh, and hit "u" to undo ;) 16:14:37 and "ctrl r" to redo 16:14:40 * FranciscoD waits 16:14:51 you will notice that vim highlights the string you are searching for 16:14:59 so "Fedora" should be highlighted 16:15:14 to only search, not replace: 16:15:25 "/search string" in command mode 16:15:28 wait 16:15:31 (no : needed" 16:15:36 cc__: yep? 16:16:02 difference between ":%s/Fedora/The Fedora/" and.... 16:16:14 ":%s/Fedora/The Fedora/g" 16:16:31 the first one only replaces the *first* occurence in each line 16:16:39 the second replaces all occurences 16:17:04 so: 16:17:26 ?searchstring -> backword search 16:17:42 to move to the next matching string, use "n" 16:17:49 to move to the previous match, use "N" 16:17:54 (small and capital) 16:18:02 * FranciscoD waits so you folks can try it out 16:18:05 2 minutes 16:18:09 ok 16:18:19 any queries? 16:18:27 no 16:18:51 cool, it works 16:18:56 grat 16:18:58 great 16:19:01 hit gg0 16:19:09 to go to the first word of our document 16:19:33 "/asdfsadfdsf" -> to search for dummy string and unhighlight fedora 16:19:41 (if it is still highlighted) 16:19:54 on "Fedora", hit * 16:19:59 (star) 16:20:01 what happens? 16:20:27 highlight Fedora 16:20:30 great 16:20:40 to forward search the word under cursor 16:20:54 now, gg0 again 16:21:07 "2fR" 16:21:18 FranciscoD, what's the difference between gg and gg0? 16:21:21 thats a two followed by an "f" followed by capital "R" 16:21:35 meka: iirc, gg doesnt change what column you are on 16:21:42 ah, it does 16:21:46 my bad 16:21:51 ok 16:21:54 gg -> starting of doc, no 0 required 16:22:12 so, try out the "2fR" and tell me where your cursor goes ;) 16:22:46 hm 16:22:50 jumps to Red Hat 16:22:54 graet 16:23:00 did it do that for everyone? 16:23:05 * FranciscoD hopes it dic 16:23:08 *did 16:23:23 yes 16:23:26 i'll break it up -> 16:23:34 2 -> repeat 2 times 16:23:39 f -> find forward 16:23:45 R -> occurence of R 16:23:55 so 2fR goes to the second occurence of capital r forwards 16:24:00 clear? 16:24:04 cool 16:24:11 now, when you're on Red, hit # 16:24:13 (hash) 16:24:18 this is a backward search 16:24:57 now, more on insertions 16:25:03 hit : 16:25:06 I 16:25:09 capital I 16:25:21 write something, hit esc to return to command mode 16:25:25 then, try: 16:25:34 o and O 16:25:36 write something, hit esc to return to command mode 16:25:42 try: 16:25:45 a and A 16:26:01 all of these are easy to remember 16:26:04 i -> insert 16:26:07 a -> append 16:26:13 o -> no clue ;) 16:26:23 but I'm hoping its working for you folks 16:26:39 * FranciscoD waits while folks try it all out 16:26:58 i vs a ? 16:27:08 i inserts at cursor location 16:27:12 a inserts at next location 16:27:22 also try "rP" 16:27:25 r -> replace 16:27:33 k 16:27:39 it will replace the letter under cursor with "P" 16:27:55 okay, 16:28:00 #topic copy paste! 16:28:12 on any line, hit "yy" 16:28:20 thats small y twice, in command mode 16:28:34 then: 16:28:38 ":tabedit temp" 16:28:46 it should open a new tab, called temp 16:28:56 works for everyone? 16:29:06 yes 16:29:07 you can also open an existing file -> :tabedit 16:29:15 tab completion works btw 16:29:26 ok 16:29:27 great, in the new tab, hit "p" 16:29:36 small "p" 16:29:46 y -> yank (copy) 16:29:47 p -> paste 16:29:49 works for all? 16:29:55 p -> paste after cursor 16:30:01 P -> paste before cursor 16:30:21 go back to the previous tab (remember gt?) 16:30:26 lets copy multiple lines 16:30:41 ":29,45y" 16:30:49 that will copy lines 25 through 45 16:30:58 please go to the other tab and paste them 16:31:06 and get back to this tab 16:31:12 * FranciscoD waits 16:31:12 any issues? 16:31:14 any one stuck? 16:31:34 logs will be available, please dont make notes ;) 16:31:36 it works 16:31:52 we have 15 more minutes, so lets hurry it up ;) 16:32:01 now, another way of copying -> 16:32:06 ":34" 16:32:11 to go to line 34 16:32:14 or 34G 16:32:19 whatever you're comfortable with 16:32:27 "ma" 16:32:34 -> mark this spot as "a" 16:32:41 then go down to line 45 16:32:48 and try: 16:33:00 "y'a" 16:33:08 thats y followed by a single quote followed by a 16:33:18 -> yank from marker "a" till here 16:33:34 please go paste these in the new tab and get back 16:34:34 all okay? 16:34:44 any issues anyone? 16:35:05 no 16:35:57 now, like you have y for yank, 16:36:05 you have d for "delete" 16:36:19 the catch is, it isnt really delete, as much it is "cut" 16:36:56 try cutting a few lines 16:37:06 to cut *one* letter, use "x" 16:37:16 x -> looks like a cross ;) 16:37:40 now, more fun! 16:37:44 to change stuff, you have "c" 16:37:47 go to any word, 16:37:50 hit "cw" 16:38:00 the word goes, and you are in insert mode 16:38:08 so you can easily change stuff 16:38:17 2cw will change *two* words 16:38:20 etc 16:38:29 2cb 16:38:31 5ce 16:38:33 tc 16:38:36 *etc 16:38:44 (various combinations as required) 16:38:58 all okay? 16:39:10 2 minutes for questions, clarifications 16:39:15 * FranciscoD waits 16:40:17 anyone? 16:40:21 k 16:40:24 continue then? 16:40:31 ok 16:40:40 #topic macros! 16:41:02 so, open yet another dummy tab 16:41:13 ":tabedit anotherdummy" 16:41:29 write -> 1 16:41:31 thats ONE 16:41:36 and return to command mode 16:41:40 * FranciscoD waits again 16:41:48 for folks to catch up 16:41:53 this is important stuff 16:41:59 comes in handy 16:42:16 keeping the cursor at 1, try: 16:42:24 hit -> "qa" 16:42:37 it should say "recording" in the bottom left corner 16:43:02 yy 16:43:03 ok 16:43:07 to yank the "1" 16:43:09 p 16:43:13 to paste it in the next line 16:43:35 hit "ctrl a" 16:43:52 the freshly pasted "1" should increase to 2 16:43:54 q 16:44:01 the "recording" should vanish 16:44:09 what we've done is create a macro 16:44:24 we copied 1 to a new line, incremented it by one useing "ctrl a" 16:44:50 on the second line, hit "@a" 16:44:55 thats AT 16:45:05 followed by the macro name we used, which was "a" 16:45:15 it should give you "3" in the next line 16:45:23 * FranciscoD waits for response/confirmation 16:45:41 ok 16:46:35 grat 16:46:42 s/grat/great! 16:46:49 now, you know how to use macros 16:46:57 what if we want to write 1-30? 16:47:05 on the 3, hit "27@a" 16:47:19 basically calling the macro *27* times 16:47:30 #chair FranciscoD_ 16:47:30 Current chairs: FranciscoD FranciscoD_ 16:47:41 did that work? 16:49:00 yes 16:49:03 * FranciscoD waits for le response 16:49:07 meka: great 16:49:09 yes 16:49:09 othes? 16:49:27 okay, I'm going to end here 16:49:37 what you must remember -> 16:49:47 do not use Insert mode unless necessar 16:49:57 vim is way more powerful, and efficient in the other modes 16:50:18 if you learn how to use vim correctly, you can edit docs, source etc with just a few key strokes 16:50:26 ten minutes for questions 16:50:38 #topic questions -> 10 minutes 16:50:52 go ahead :) shoot 16:50:58 FranciscoD, does "qa" means "macro named a"? 16:51:05 yes 16:51:12 I mean, we could name it anything else? 16:51:16 sure 16:51:24 and is it limited to one char? 16:51:30 any of the 26 alphas I guess 16:51:35 other than q probably 16:51:46 you not talk about template ( ~/.vim/templates ) 16:51:47 meka: to my knowledge yes, 16:51:55 me i use one for my d programm 16:51:58 http://fpaste.org/yFAn/ 16:52:01 bioinfornatics: thats advanced stuff 16:52:04 ok 16:52:13 i didnt talk about vimrc, or even programming with vim 16:52:22 true 16:52:27 the class is intended to teach folks how to use vim correctly 16:52:38 *not* like NOTEPAD 16:52:43 whre we can getthe log ? 16:53:05 bioinfornatics: I'll give you the link once class finishes and zodbot spews them out 16:53:10 btw, 16:53:20 ZQ -> quit without save 16:53:24 ZZ -> save and quit 16:53:25 if i use only :tabedit, it creates a tab with No Name. can we change its name later? 16:53:29 * FranciscoD forgot to mention it 16:53:37 sayan: yes 16:53:57 ":w filename" 16:53:57 will save the current tab (buffer) to "filename" 16:54:26 ok 16:54:27 you should all run "vimtutor" in the terminal and take the tutorial 16:54:41 its very simple, gives you some practice in navigation etc 16:55:06 and the vim help docs themselves 16:55:17 another source of knowledge is google of course 16:55:19 for help on any command 16:55:23 :h command 16:55:25 for instance 16:55:27 try: 16:55:38 :h y 16:55:53 it will open the help for yank in a split window 16:56:00 like a text document 16:56:26 theres also a great book -> "vim and vi" that you can refer to 16:56:36 * FranciscoD is going to close the class now 16:56:45 thanks all for coming, hope you learnt something new! 16:56:49 #endmeeting