Editing Files Flashcards

1
Q

How do I load a file in Vim for editing?

A

:e
1. The simplest is to use the “:e” (:edit) command:
:e

  1. :n or :args also work.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do I save the current file in another name (save as) and edit a new file?

A

:saveas

To save the current file in another name:

:saveas 

Alternatively, you can also use the following commands:

:w 
:edit #

You can also use the “:file” command, followed by “:w” command:

:file 
:w
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do I change the current directory to the directory of the current file?

A

:cd %:p:h

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

To automatically change the current directory to the directory of the
current file, simply set the option

A

:set autochdir

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do I edit a file whose name is under the cursor?

A

gf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Open a new tab page that contains the

file name under the cursor.

A

CTRL-W gf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do I reload/re-edit the current file?

A

:edit
You can use the “:edit” command, without specifying a file name, to reload
the current file. If you have made modifications to the file, you can use
“:edit!” to force the reload of the current file (you will lose your
modifications, but depending on your ‘undoreload’ settings, those
changes might be saved into the undo history).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do I open a file in read-only mode?

A

:view filename

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do I open multiple files at once from within Vim?

A

:next f1.txt f2.txt
:next *.c

After loading the files, you can use the “:next” and “:prev” command to switch between the files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Difference between args, buffers, tabs and windows

A

Make a difference between args, buffers, tabs and windows. They are all
different things in VIM.

args is a list of arguments. Buffers are place to edit text, almost
always attached to a file but not necessarily. Window is a place for a
buffer and tab is set of windows, better name would be ‘layout’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Open several files in Vim, with each file in a separate

window/tab.

A

$ vim -o3 f1.txt f2.txt f3.txt

Will open the files f1.txt, f2.txt and f3.txt in three separate horizontally split Vim windows.

$ vim -p f1.txt f2.txt f3.txt

Will open the files f1.txt, f2.txt and f3.txt in three separate tab windows.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do I browse/explore directories from within Vim?

A

Start the file explorer using one of the following commands:

:Explore

From the file explorer, you can browse through directories, rename, delete and edit files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do I configure Vim to auto-save a modified buffer when switching to another buffer?

A

:set autowrite

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Ways other than :Explore for browsing/exploring directories from within Vim

A
\:e 
    :Explore
    :Sexplore
    :Vexplore
    :Texplore

From the file explorer, you can browse through directories, rename, delete
and edit files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

8.3. How do I replace the buffer in the current window with a blank buffer?

A

:enew

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

8.5. How do I open all the current buffers in separate windows?

A

:tab :sball

You can use the “:ball” or “:sball” commands to open all the buffers
in the buffer list:

:ball

If you want all buffers to be opened in new tabs, simply prefix the :tab command:

:tab :sball
17
Q

How do I close (delete) a buffer without exiting Vim?

A

:bdelete file1

You can use any of “:bdelete”, “:bwipeout” or “:bunload” commands to delete a buffer without exiting Vim. For example:

18
Q

Open the next buffer

A

:bn

Short for :bnext (next buffer)

19
Q

9.1. What is the difference between a Vim window and a buffer? *** IMPORTANT

A

A Vim buffer is a file loaded into memory for editing. The original file remains unchanged until you write the buffer to the file.
A Vim window is a viewport onto a buffer. You can use multiple windows on one buffer or several windows on different buffers.

20
Q

Close all the windows except the current

window

A

:on

Short for: “:only”