I am writing my first vimrc. I already read help pages for hidden
and nostartofline
options, as well as some articles and other FAQs.
However, I still can't understand what the purpose of these two options are.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityI am writing my first vimrc. I already read help pages for hidden
and nostartofline
options, as well as some articles and other FAQs.
However, I still can't understand what the purpose of these two options are.
Perhaps examples will help you understand the features:
Start a new instance of Vim in the terminal with the command vim -Nu NONE
. This will start Vim with default configuration, and thus 'hidden'
will be unset (and 'startofline'
will be set).
Enter insert mode by pressing i, type in some text, and then press Esc to return to normal mode,
Enter the command :e anotherfile.txt
to start editing a new file,
Vim will display an error because you haven't written the file yet,
Enter the command :set hidden
to switch on the 'hidden'
option
Try the command again: :e anotherfile.txt
.
What happens?
In the same instance of Vim, enter the command :b#
to return to your original buffer.
Press gg to jump to the beginning of the buffer and then $
to jump to the end of the line. (If the first line is blank, first enter some text.)
Press gg again. The cursor will move to the start of the line.
Press $ to move back to the end of the line,
Enter the command :set nostartofline
.
Press gg a third time.
What happens?
Here are two additional examples for nostartofline
.
First, open a new buffer, paste/type the following code, type :nostartofline
, and then switch to Normal mode.
if (x == y) {
dosomething1
}
dosomething2
Then:
Example 1
Place the cursor on x
.
Press VG to select the whole text.
Notice your cursor is now on m
and not d
in dosomething2
.
Example 2
Place the cursor on d
in dosomething1
Press >> to indent this line.
Notice your cursor was not moved.