mirror of
https://github.com/jbranchaud/til
synced 2026-01-02 22:58:01 +00:00
Add Go To Beginning And End Of Line as a Vim TIL
This commit is contained in:
@@ -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)
|
||||
|
||||
33
vim/go-to-beginning-and-end-of-line.md
Normal file
33
vim/go-to-beginning-and-end-of-line.md
Normal file
@@ -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.
|
||||
Reference in New Issue
Block a user