Usr_09 - Neovim docs (2022)

Nvim :help pages, generated from source using the tree-sitter-vimdoc parser.

VIM USER MANUAL - by Bram Moolenaar

Using the GUI

Vim works in an ordinary terminal, while gVim has a Graphical User Interface(GUI). It can do the same things and a few more. The GUI offers menus, atoolbar, scrollbars and other items. This chapter is about these extra thingsthat the GUI offers.

09.1 Parts of the GUI09.2 Using the mouse09.3 The clipboard09.4 Select mode

Next chapter: usr_10.txt Making big changes Previous chapter: usr_08.txt Splitting windowsTable of contents: usr_toc.txt

Parts of the GUI

You might have an icon on your desktop that starts gvim. Otherwise, one ofthese commands should do it:

gvim file.txtvim -g file.txt

If this doesn't work you don't have a version of Vim with GUI support. Youwill have to install one first. Vim will open a window and display "file.txt" in it. What the window lookslike depends on the version of Vim. It should resemble the following picture(for as far as this can be shown in ASCII!).

+----------------------------------------------------+| file.txt + (~/dir) - VIM X |<- window title+----------------------------------------------------+| FileEdit Tools Syntax Buffers Window Help |<- menubar+----------------------------------------------------+| aaa bbb ccc ddd eee fffggg hhh iii jjj |<- toolbar| aaa bbb ccc ddd eee fffggg hhh iii jjj |+----------------------------------------------------+| file text | ^ || ~ | # || ~ | # |<- scrollbar| ~ | # || ~ | # || ~ | # || | V |+----------------------------------------------------+

The largest space is occupied by the file text. This shows the file in thesame way as in a terminal. With some different colors and another fontperhaps.


At the very top is the window title. This is drawn by your window system.Vim will set the title to show the name of the current file. First comes thename of the file. Then some special characters and the directory of the filein parens. These special characters can be present:

-The file cannot be modified (e.g., a help file)+The file contains changes=The file is read-only=+The file is read-only, contains changes anyway

If nothing is shown you have an ordinary, unchanged file.


You know how menus work, right? Vim has the usual items, plus a few more.Browse them to get an idea of what you can use them for. A relevant submenuis Edit/Global Settings. You will find these entries:

Toggle Toolbarmake the toolbar appear/disappearToggle Bottom Scrollbarmake a scrollbar appear/disappear at the bottomToggle Left Scrollbarmake a scrollbar appear/disappear at the leftToggle Right Scrollbarmake a scrollbar appear/disappear at the right


This contains icons for the most often used actions. Hopefully the icons areself-explanatory. There are tooltips to get an extra hint (move the mousepointer to the icon without clicking and don't move it for a second).

The "Edit/Global Settings/Toggle Toolbar" menu item can be used to make thetoolbar disappear. If you never want a toolbar, use this command in yourvimrc file:

:set guioptions-=T

This removes the 'T' flag from the 'guioptions' option. Other parts of theGUI can also be enabled or disabled with this option. See the help for it.


By default there is one scrollbar on the right. It does the obvious thing.When you split the window, each window will get its own scrollbar. You can make a horizontal scrollbar appear with the menu itemEdit/Global Settings/Toggle Bottom Scrollbar. This is useful in diff mode, orwhen the 'wrap' option has been reset (more about that later).

When there are vertically split windows, only the windows on the right sidewill have a scrollbar. However, when you move the cursor to a window on theleft, it will be this one that the scrollbar controls. This takes a bit oftime to get used to. When you work with vertically split windows, consider adding a scrollbar onthe left. This can be done with a menu item, or with the 'guioptions' option:

:set guioptions+=l

This adds the 'l' flag to 'guioptions'.

09.2 Using the mouse

Standards are wonderful. In Microsoft Windows, you can use the mouse toselect text in a standard manner. The X Window system also has a standardsystem for using the mouse. Unfortunately, these two standards are not thesame. Fortunately, you can customize Vim. You can make the behavior of the mousework like an X Window system mouse or a Microsoft Windows mouse. The followingcommand makes the mouse behave like an X Window mouse:

:behave xterm

The following command makes the mouse work like a Microsoft Windows mouse:

:behave mswin

The default behavior of the mouse on Unix systems is xterm. The defaultbehavior on Windows systems is selected during the installation process. Fordetails about what the two behaviors are, see :behave. Here follows asummary.


Left mouse clickposition the cursorLeft mouse dragselect text in Visual modeMiddle mouse clickpaste text from the clipboardRight mouse clickextend the selected text until the mousepointer

Left mouse clickposition the cursorLeft mouse dragselect text in Select mode (see 09.4)Left mouse click, with Shiftextend the selected text until the mousepointerMiddle mouse clickpaste text from the clipboardRight mouse clickdisplay a pop-up menu

The mouse can be further tuned. Check out these options if you want to changethe way how the mouse works:

'mouse'in which mode the mouse is used by Vim'mousemodel'what effect a mouse click has'mousetime'time between clicks for a double-click'mousehide'hide the mouse while typing'selectmode'whether the mouse starts Visual or Select mode

09.3 The clipboard

In section 04.7 the basic use of the clipboard was explained. There is oneessential thing to explain about X-windows: There are actually two places toexchange text between programs. MS-Windows doesn't have this.

In X-Windows there is the "current selection". This is the text that iscurrently highlighted. In Vim this is the Visual area (this assumes you areusing the default option settings). You can paste this selection in anotherapplication without any further action. For example, in this text select a few words with the mouse. Vim willswitch to Visual mode and highlight the text. Now start another gvim, withouta file name argument, so that it displays an empty window. Click the middlemouse button. The selected text will be inserted.

The "current selection" will only remain valid until some other text isselected. After doing the paste in the other gvim, now select some charactersin that window. You will notice that the words that were previously selectedin the other gvim window are displayed differently. This means that it nolonger is the current selection.

You don't need to select text with the mouse, using the keyboard commands forVisual mode works just as well.


Now for the other place with which text can be exchanged. We call this the"real clipboard", to avoid confusion. Often both the "current selection" andthe "real clipboard" are called clipboard, you'll have to get used to that. To put text on the real clipboard, select a few different words in one ofthe gvims you have running. Then use the Edit/Copy menu entry. Now the texthas been copied to the real clipboard. You can't see this, unless you havesome application that shows the clipboard contents (e.g., KDE's Klipper). Now select the other gvim, position the cursor somewhere and use theEdit/Paste menu. You will see the text from the real clipboard is inserted.


This use of both the "current selection" and the "real clipboard" might sounda bit confusing. But it is very useful. Let's show this with an example.Use one gvim with a text file and perform these actions:

Select two words in Visual mode.

Use the Edit/Copy menu to get these words onto the clipboard.

Select one other word in Visual mode.

Use the Edit/Paste menu item. What will happen is that the single selected word is replaced with the two words from the clipboard.

Move the mouse pointer somewhere else and click the middle button. You will see that the word you just overwrote with the clipboard is inserted here.

If you use the "current selection" and the "real clipboard" with care, you cando a lot of useful editing with them.


If you don't like using the mouse, you can access the current selection andthe real clipboard with two registers. The "* register is for the currentselection. To make text become the current selection, use Visual mode. For example,to select a whole line just press "V". To insert the current selection before the cursor:


Notice the uppercase "P". The lowercase "p" puts the text after the cursor.

The "+ register is used for the real clipboard. For example, to copy the textfrom the cursor position until the end of the line to the clipboard:


Remember, "y" is yank, which is Vim's copy command. To insert the contents of the real clipboard before the cursor:


It's the same as for the current selection, but uses the plus (+) registerinstead of the star () register.

09.4 Select mode

And now something that is used more often on MS-Windows than on X-Windows.But both can do it. You already know about Visual mode. Select mode is likeVisual mode, because it is also used to select text. But there is an obviousdifference: When typing text, the selected text is deleted and the typed textreplaces it.

To start working with Select mode, you must first enable it (for MS-Windowsit is probably already enabled, but you can do this anyway):

:set selectmode+=mouse

Now use the mouse to select some text. It is highlighted like in Visual mode.Now press a letter. The selected text is deleted, and the single letterreplaces it. You are in Insert mode now, thus you can continue typing.

Since typing normal text causes the selected text to be deleted, you can notuse the normal movement commands "hjkl", "w", etc. Instead, use the shiftedfunction keys. <S-Left> (shifted cursor left key) moves the cursor left. Theselected text is changed like in Visual mode. The other shifted cursor keysdo what you expect. <S-End> and <S-Home> also work.

You can tune the way Select mode works with the 'selectmode' option.

Next chapter: usr_10.txt Making big changes

Copyright: see manual-copyright vim:tw=78:ts=8:noet:ft=help:norl:

Top Articles

Latest Posts

Article information

Author: Greg Kuvalis

Last Updated: 01/20/2023

Views: 5942

Rating: 4.4 / 5 (75 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Greg Kuvalis

Birthday: 1996-12-20

Address: 53157 Trantow Inlet, Townemouth, FL 92564-0267

Phone: +68218650356656

Job: IT Representative

Hobby: Knitting, Amateur radio, Skiing, Running, Mountain biking, Slacklining, Electronics

Introduction: My name is Greg Kuvalis, I am a witty, spotless, beautiful, charming, delightful, thankful, beautiful person who loves writing and wants to share my knowledge and understanding with you.