Home Explore Blog CI



neovim

1st chunk of `runtime/doc/usr_31.txt`
50d45c77fb103421b16c62f6dd681544979d7ac2504c69980000000100000fa2
*usr_31.txt*	Nvim

		     VIM USER MANUAL - by Bram Moolenaar

			      Exploiting the GUI


Vim works well in a terminal, but the GUI has a few extra items.  A file
browser can be used for commands that use a file.  A dialog to make a choice
between alternatives.  Use keyboard shortcuts to access menu items quickly.

|31.1|	The file browser
|31.2|	Confirmation
|31.3|	Menu shortcuts
|31.4|	Vim window position and size
|31.5|	Various

     Next chapter: |usr_32.txt|  The undo tree
 Previous chapter: |usr_30.txt|  Editing programs
Table of contents: |usr_toc.txt|

==============================================================================
*31.1*	The file browser

When using the File/Open... menu you get a file browser.  This makes it easier
to find the file you want to edit.  But what if you want to split a window to
edit another file?  There is no menu entry for this.  You could first use
Window/Split and then File/Open..., but that's more work.
   Since you are typing most commands in Vim, opening the file browser with a
typed command is possible as well.  To make the split command use the file
browser, prepend "browse": >

	:browse split

Select a file and then the ":split" command will be executed with it.  If you
cancel the file dialog nothing happens, the window isn't split.
   You can also specify a file name argument.  This is used to tell the file
browser where to start.  Example: >

	:browse split /etc

The file browser will pop up, starting in the directory "/etc".

The ":browse" command can be prepended to just about any command that opens a
file.
   If no directory is specified, Vim will decide where to start the file
browser.  By default it uses the same directory as the last time.  Thus when
you used ":browse split" and selected a file in "/usr/local/share", the next
time you use a ":browse" it will start in "/usr/local/share" again.
   This can be changed with the 'browsedir' option.  It can have one of three
values:

	last		Use the last directory browsed (default)
	buffer		Use the same directory as the current buffer
	current		use the current directory

For example, when you are in the directory "/usr", editing the file
"/usr/local/share/readme", then the command: >

	:set browsedir=buffer
	:browse edit

Will start the browser in "/usr/local/share".  Alternatively: >

	:set browsedir=current
	:browse edit

Will start the browser in "/usr".

	Note:
	To avoid using the mouse, most file browsers offer using key presses
	to navigate.  Since this is different for every system, it is not
	explained here.  Vim uses a standard browser when possible, your
	system documentation should contain an explanation on the keyboard
	shortcuts somewhere.

When you are not using the GUI version, you could use the file explorer window
to select files like in a file browser.  However, this doesn't work for the
":browse" command.  See |netrw-browse|.

==============================================================================
*31.2*	Confirmation

Vim protects you from accidentally overwriting a file and other ways to lose
changes.  If you do something that might be a bad thing to do, Vim produces an
error message and suggests appending ! if you really want to do it.
   To avoid retyping the command with the !, you can make Vim give you a
dialog.  You can then press "OK" or "Cancel" to tell Vim what you want.
   For example, you are editing a file and made changes to it.  You start
editing another file with: >

	:confirm edit foo.txt

Vim will pop up a dialog that looks something like this:

	+-----------------------------------+
	|				    |
	|   ?	Save changes to "bar.txt"?  |
	|				    |
	|   YES   NO		 CANCEL     |
	+-----------------------------------+

Now make your choice.  If you do want to save the changes, select "YES".  If
you want to lose the changes for ever: "NO".  If you forgot what you were
doing and want to check what really changed use "CANCEL".  You will be back in
the same file, with the changes still there.

Just

Title: Vim GUI Exploitation: File Browser and Confirmation Dialogs
Summary
This section of the Vim user manual discusses features that enhance the GUI experience. It covers using the file browser for opening files, including specifying a starting directory and configuring the 'browsedir' option. It also explains how to use confirmation dialogs to prevent accidental overwriting of files by using the `:confirm` command, offering options to save, discard, or cancel the operation.