bits and pieces |
this is the part where i explain things i've picked up about vimthis is where i point to the other things i have writtenI wrote about command line here. most of the things i anticipate appearing on this page are going to be me learning more about this. I wrote about the basics of vim here. i don't know how one would edit things in the tilde-verse without using vim, nano, or emacs... practice, practice, practiceLike many people at work, I have a standing desk. Unlike many people at work, I do not have a chair for that standing desk. I assume that if I am given a chair, I will sit on it, instead of standing, which is the whole point of having a standing desk in the first place. Similarly, I've heard there are ways to edit text that ends up in tilde.town without having to use vim, but I am not going to seek them out. Editing lots of text (you've seen the rambling), makes it easier by the minute. For double bonus points, there is a Chrome plug in called Vimium, which allows you to practice vim while browsing the internet. :) I assume it's a lot like yoga? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
back to top |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
back to top |
Today I Learned: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
back to top |
The internet revealed the `-p` flag to me today (I can type `vim -p file1.html file2.html` to open both files and move between them with `:n` and `:N`, only the flag will put the names of the files at the top, like tabs!), so I decided today was a good day to figure out how to customize vim and make the layout work for me. SPLITTING - What if I want to have more than one file open to edit--but I want to be able to see the files? I'll open up a file like I noramlly do with `vim file1.html`, and then I will type `:sp file2.html` -- this will cause file2 to appear on the bottom half of my screen! Awesome! Similarly, if I typed `:vsp file2.html`, it would cause file 2 to appear on the right side of the screen instead of the bottom. You can combine `:sp` and `:vsp` however you like! To move around between these panes (i think the commands mean "split pane & vertical split pane") you hold control + w then one of the following:
I realized recently that if I'm editing in tilde.town, when I open vim, each line is numbered (super handy!), but when I open vim locally, there aren't numbers :( To number your lines in the session you are in, you type `:set number`. Ig you ahve more than one pane open, it will only number the active pane. But what if you want to always have numbered lines? Glad you asked! We get to explore the magical world of VIMRC If you go to your home directory, whether it's local, or ssh (`cd`), there is a hidden file called .vimrc (reveal hidden files with `ls -a`). That's where all the defaults are hidden! The tilde.town file was already pretty well pre-populated, but I knew I wanted to wrap some text, since I've got so many medium-to-long-ish paragraphs. I scanned the file until I saw 'set nowrap " don't warp display' (double quote mark is used to 'comment out' words that mean something to humans, but not to vim). To make sure this did what I wanted, I did a bit of Googling and also used vim's `:help` command, which I always forget to give mad props to. I changed the line to `set wrap linebreak`, which made all of my long paragraphs wrap at the end of the window. It sounded like linebreak was going to make those breaks happen between words, rather than in the middle of words, but that didn't happen. I'll have to figure that out... OK, now color schemes! What color should the background/standard text/highlighted text/syntex highlight style 1 through infinity be? I started off in vim. in command mode, I typed `:colorscheme ` and then hit tab. This will show you all of the loaded colorschemes. Choose one! Better option: go through all of them! I chose one that I think paralysed my eyeballs for a few minutes at first. A lot of the differences were almost imperceptible (though I am editing HTML-- maybe they would be drastically different in another language). Adventure for next time: tweaking the colorscheme I chose to be just right by editing ~/.vim/colors! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
back to top |
11/15 - TIL - COPYING FROM OTHER FILES ~dhgwilliam showed me this *super duper awesome thing!* At some point, I learned I could type `:r filename.html` if I wanted to copy filename.html into my current file. The problem is, I normally just want to use the <head> section, not a whole file. `:r !head filename.html -n 50` will pull the top 50 lines from filename.html. take a minute to just think of all the possibilities Breaking down the command:
~~~~~~~~~~~~~~~~~~~~~~~~~~~ So any time I want to write about what I've learned in command line/bash/terminal and show the result of a new command, I can type `:r !(command)` ---for example, I'm going to type `:r !ls -l | grep duke` (and add html formatting around it for you afterwards). -rw-r--r-- 1 shanx shanx 123096 Nov 10 01:18 black_duke.jpg -rwxr--r-- 1 shanx shanx 684113 Oct 28 05:45 the_duke.jpg seriously, I'm about to start mad scientist laughing! W00! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
back to top |
11/15 - THINGS I THNK I FORGOT TO WRITE DOWN The longer your file is, the more you don't want to be stuck using arrows and j/k's to move up and down. I like using
I know it's in the reference table (which I should really update), but find and replace is one of my favorite things. I just love doing stuff with words. If you find that you habitually type 'anythign', you can use this to fix ALL THE THIGNS! `:%s/thign/thing/g` ~~~ `%` means 'check the whole file', `s` means 'substitute', and `g` means 'global' (or at least 'do this for everything you find'). Now let's say you wanted to leave some mispellings in place (like in the line ablve), or only wanted to change the name of a thing in part of your file. `:1,40s/thign/thing/gc` ~~~ we've replaced `%` with `1,40`, which means 'only check between rows 1 and 40- I don't care about the rest of the file'. You'll also notice that we added a `c` at the end. This means 'check before making the change'. When you use this, vim will highlight each instance of the word you are searching and ask "replace with thing (y/n/a/q/l/^E/^Y)?" If you type:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
back to top |
11/11 - TIL: DUAL WEILDING So there you are, learning all sorts of wild and crazy things about unix and vim and irc and *, and you keep `:wq` and opening up a file to edit it, then `:wq` and opening up another file to edit it. what if it didn't have to be like that? While editing in one file, you can type `:e file_name.html` and it will open up the other file for you to edit. Whoah. You can open tons of files- then see which ones you've got by typing `:buffers`-- this will show a list of open files with numbers before them. You can switch to a file by typing `:buffer #`, where # is the preceding number. Yeah, that's cool and all, but it doesn't seem like it's saving that many keystrokes :( `:q`uit whatever you're doing. Now, rather than getting into vim with `vim file_name.html` do it with `vim file_name.html other_file_name.html`. It opened both of them. And nowwwwwwww... `:n` will take you to other_file_name.html! And from there, you can return with `:N`! Lovely! UPDATE: the `-p` flag will add tabs! So if I type `vim -p vim.html cli.html other.html` in command line, vim will open up and have tabs at the top of the screen with the names of each file that is open. You navigte the same way with `:n` and `:N` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
back to top |
11/9 - TIL: FILL IN THE BLANKS Have you ever been cruising through your file and you need to replace an element of some sort? Maybe you usedd the wrong tag. Maybe you need to replace a broken URL. Maybe you need to rewrite a function. Meet your new vim BFFs: `ci` and `vi`. If you place your cursor somewhere inside single quotes and from command mode run `ci'`, it will Clear the content between the `'`s and go into Insert mode, so you can replace it. Similarly, if you use `vi<` when your cursor is between brackets, it will go into insert mode and highlight everything between, so you can `y`ank, `p`aste, or do whatever you want. UPDATE: What if you don't want to replace the tag names- you want to replace the content BETWEEN the tags? `cit` seems to do the trick :) example: `ci=^..^=` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
back to top |
11/8 - TIL: NEW WAYS TO "INSERT"! So I've been cruising along in vim, and I will frequently forget to enter Insert mode before entering text. I noticed that I would start typing and it wouldn't be until a word or two in that text would get entered (or I would do something terrible like delete the line). Now at the begining, I assumed that the text would start when I came to the first "i" in the sentence. Then I noticed that wasn't always the case, but I was so engrossed in whatever I was doing that I didn't check it out. Tangetially, when editing files (especially HTML with all its tags) I would go to the end of a line with `$` and hit `i` and then have to move the cursor over with space to get past the closing > and hit enter to make a new line. Wow, writing it all out makes it sound arduous. But like many new things, when you are learning, you don't really notice the little things. Well today the internet dropped a knowledge bomb on me: THERE ARE DIFFERENT WAYS TO GET INTO INSERT MODE.
I think I'm going to be using `A`, `o`, and `O` a whole lot now :) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
back to top |
11/8 part deux - TIL: `~` `~` will change the case of the letter the cursor is under (in command mode). Some may have noticed that I generally ignore the shift key when typing and refer to myself as "i" and other things that make the sticklers cringe. Whelp, now it is a bajillion times easier for me to edit those :) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
back to top |
11/6 - TIL: `P` `P` (capitalized) pastes *in front* of your curser (super helpful if you need to add a bunch of tags to the beginings of lines) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
back to top |