diff --git a/README.md b/README.md index 43c9702..8b2495e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1623 TILs and counting..._ +_1624 TILs and counting..._ See some of the other learning resources I work on: - [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators) @@ -1732,6 +1732,7 @@ If you've learned something here, support my efforts writing daily TILs by - [Generate and Edit Rails Migration](vim/generate-and-edit-rails-migration.md) - [Get The pid Of The Session](vim/get-the-pid-of-the-session.md) - [Go Back To The Previous Window](vim/go-back-to-the-previous-window.md) +- [Go To Beginning And End Of Line](vim/go-to-beginning-and-end-of-line.md) - [Go To File With Line Number](vim/go-to-file-with-line-number.md) - [Grepping Through The Vim Help Files](vim/grepping-through-the-vim-help-files.md) - [Head of File Name](vim/head-of-file-name.md) diff --git a/vim/go-to-beginning-and-end-of-line.md b/vim/go-to-beginning-and-end-of-line.md new file mode 100644 index 0000000..99bef33 --- /dev/null +++ b/vim/go-to-beginning-and-end-of-line.md @@ -0,0 +1,33 @@ +# Go To Beginning And End Of Line + +There are two movements that I often find useful in Vim when trying to position +my cursor relative to the current line. + +- `0` - go to the first character of the line +- `$` - go to the end of the line + +For instance, I may use `0` to jump to beginning of a line so that I can then +make a block-visual selection of several lines to insert some text in front of +each line. + +Or perhaps I'm already in visual mode and I want to move the cursor (and visual +selection) to the end of the line. I hit `$` to do that. Then I might `y` +(yank) or `c` (delete into insert mode). + +It's also worth noting that with code indentation, `0` moves the cursor to the +very first position of the line whereas `^` moves the cursor to the first +non-whitespace character. The former essentially accounts for code indentation. +For example, imagine you're in the middle of line 3 in the following example. +Depending on what you're trying to do, you may want to jump to one or the other +position. + +```ruby +class Greeting + def hello(name) + puts "Hello, #{name || 'world'}!" # say hi + end +end +``` + +See `:h 0` for Vim help files on these motions. They are all located near each +other.