Movatterモバイル変換


[0]ホーム

URL:


Quick links:help overview ·quick reference ·user manual toc ·reference manual toc·faq
Go to keyword (shortcut:k)
Site search (shortcut:s)
usr_31.txt  ForVim version 9.2.  Last change: 2026 Feb 14     VIM USER MANUALbyBramMoolenaar      Exploiting theGUIVim works well ina terminal, but theGUI hasa few extra items.A filebrowser can be used for commands that usea file.Adialog to makea choicebetween alternatives.  Use keyboard shortcuts to access menu items quickly.31.1  The file browser31.2  Confirmation31.3  Menu shortcuts31.4  Vimwindow position and size31.5  Various     Next chapter:usr_32.txt  Theundo tree Previous chapter:usr_30.txt  Editing programsTable of contents:usr_toc.txt==============================================================================31.1  The file browserWhen using the File/Open... menu you geta file browser.  This makesit easierto find the file you want to edit.  But what if you want to splitawindow toedit another file?  Thereis no menu entry for this.  You could first useWindow/Split and then File/Open..., but that's more work.   Since you are typing most commands in Vim, opening the file browser withatyped commandis possibleas well.  To make the split command use the filebrowser, prepend "browse"::browse splitSelecta file and then the ":split" command will be executed with it.  If youcancel the filedialog nothing happens, thewindow isn't split.   You can also specifya file name argument.  Thisis used to tell the filebrowser where to start.  Example::browse split /etcThe file browser will pop up,starting in the directory "/etc".The ":browse" command can be prepended to just about any command that opensafile.   If no directoryis specified, Vim will decide where to start the filebrowser.  By defaultit uses the same directoryas the last time.  Thus whenyou used ":browse split" and selecteda file in "/usr/local/share", the nexttime you usea ":browse"it will start in "/usr/local/share" again.   This can be changed with the'browsedir' option.  It can have one of threevalues:lastUse the last directory browsed (default)bufferUse the same directoryas the current buffercurrentuse the current directoryFor example, when you are in the directory "/usr", editing the file"/usr/local/share/readme", then the command::set browsedir=buffer:browse editWill start the browser in "/usr/local/share".  Alternatively::set browsedir=current:browse editWill start the browser in "/usr".Note:To avoid using the mouse, most file browsers offer using key pressesto navigate.  Since thisis different for every system,itis notexplained here.  Vim usesa standard browser when possible, yoursystem documentation should contain an explanation on the keyboardshortcuts somewhere.When you are not using theGUI version, you could use the file explorerwindowto select files like ina file browser.  However, this doesn't work for the":browse" command.  Seenetrw-browse.==============================================================================31.2  ConfirmationVim protects you from accidentally overwritinga file and other ways to losechanges.  If youdo something that might bea bad thing to do, Vim produces anerror message and suggests appending! if you really want todo it.   To avoid retyping the command with the !, you can make Vim give youadialog.  You can then press "OK" or "Cancel" to tell Vim what you want.   For example, you are editinga file and made changes to it.  You startediting another file with::confirm edit foo.txtVim will pop upadialog that looks something like this:+-----------------------------------+|    ||?Save changes to "bar.txt"?  ||    ||   YES   NO CANCEL     |+-----------------------------------+Now make your choice.  If youdo want to save the changes, select "YES".  Ifyou want to lose the changes for ever: "NO".  If you forgot what you weredoing and want to check what really changed use "CANCEL".  You will be back inthe same file, with the changes still there.Just like ":browse", the ":confirm" command can be prepended to most commandsthat edit another file.  They can also be combined::confirm browse editThis will produceadialog when the current buffer was changed.  Thenit willpop upa file browser to select the file to edit.Note:In thedialog you can use the keyboard to select the choice.Typically the<Tab> key and the cursor keys change the choice.Pressing<Enter> selects the choice.  This depends on the systemthough.When you are not using the GUI, the ":confirm" command worksas well.  Insteadof popping upa dialog, Vim will print the messageat the bottom of the Vimwindow and ask you to pressa key to makea choice.:confirm edit main.cSave changes to "Untitled"?[Y]es, (N)o, (C)ancel:You can now press the single key for the choice.  You don't have to press<Enter>, unlike other typing on the command line.==============================================================================31.3  Menu shortcutsThe keyboardis used for all Vim commands.  Themenus providea simple way toselect commands, without knowing what they are called.  But you have to moveyour hand from the keyboard and grab the mouse.   Menus can often be selected with keysas well.  This depends on yoursystem, but most oftenit works this way.  Use the<Alt> key in combinationwith the underlinedletter ofa menu.  For example,<A-w> (<Alt> and w) popsup the Window menu.   In the Window menu, the "split" item has thep underlined.  To select it,letgo of the<Alt> key and press p.After the first selection ofa menu with the<Alt> key, you can use the cursorkeys to move through the menus.<Right> selectsa submenu and<left> closesit.<Esc> also closesa menu.<Enter> selectsa menu item.Thereisa conflict between using the<Alt> key to select menu items, andusing<Alt> key combinations for mappings.  The'winaltkeys' option tells Vimwhatit shoulddo with the<Alt> key.   The default value "menu"is the smart choice: If the key combinationisamenu shortcutit can't be mapped.  All other keys are available for mapping.   The value "no" doesn't use any<Alt> keys for the menus.  Thus youmust usethe mouse for the menus, and all<Alt> keys can be mapped.   The value "yes" means that Vim will use any<Alt> keys for the menus.  Some<Alt> key combinations may alsodo other things than selectinga menu.==============================================================================31.4  Vimwindow position and sizeTo see the current Vimwindow position on the screen use::winposThis will only work in the GUI.  The output may look like this:Window position: X 272, Y 103The positionis given in screen pixels.  Now you can use the numbers to moveVim somewhere else.  For example, to moveit to the lefta hundred pixels::winpos 172 103Note:There may bea small offset between the reported position and wherethewindow moves.  Thisis because of the border around the window.Thisis added by thewindow manager.You can use this command in yourstartupscript to position thewindowataspecific position.The size of the Vimwindowis computed in characters.  Thus this depends onthe size of the font being used.  You can see the current size with thiscommand::set lines columnsTo change the size set the'lines' and/or'columns'options toa new value::set lines=50:set columns=80Obtaining the size works inaterminal just like in the GUI.  Setting the sizeis not possible in most terminals.You can start the X-Windows version ofgvim with an argument to specify thesize and position of the window:gvim -geometry {width}x{height}+{x-offset}+{y-offset}{width} and{height} are in characters,{x-offset} and{y-offset} are inpixels.  Example:gvim -geometry 80x25+100+300==============================================================================31.5  VariousYou can usegvim to edit an e-mail message.  In your e-mail program youmustselectgvim to be the editor for messages.  When you try that, you willsee thatit doesn't work: The mail program thinks that editingis finished,whilegvimis still running!   What happensis thatgvim disconnects from the shellit was started in.Thatis fine when you startgvim ina terminal, so that you cando other workin that terminal.  But when you really want to wait forgvim to finish, youmust preventit from disconnecting.  The "-f" argument does this:gvim -f file.txtThe "-f" stands for foreground.  Now Vim will block the shellit was startedin until you finish editing and exit.DELAYED START OF THE GUIOnUnix it's possible to first start Vim ina terminal.  That's useful if youdovarious tasks in the same shell.  If you are editinga file and decide youwant to use theGUI after all, you can startit with::guiVim will open theGUIwindow and no longer use the terminal.  You can continueusing theterminal for something else.  The "-f" argumentis used here to runtheGUI in the foreground.  You can also use ":gui-f".THE GVIM STARTUP FILEWhengvim starts,it reads thegvimrc file.  That's similar to thevimrc fileused whenstarting Vim.  Thegvimrc file can be used for settings and commandsthat are only to be used when theGUIis going to be started.  For example,you can set the'lines' option to seta differentwindow size::set lines=55You don't want todo this ina terminal, since its sizeis fixed (except foran xterm that supports resizing).   Thegvimrc fileis searched for in the same locationsas thevimrc file.Normally its nameis "~/.gvimrc" forUnix and "$VIM/_gvimrc" for MS-Windows.The$MYGVIMRC environment variableis set to it, thus you can use this commandto edit the file, if you have one::edit $MYGVIMRC   If for some reason you don't want to use the normalgvimrc file, you canspecify another one with the "-U" argument:gvim -U thisrc ...That allowsstartinggvim for different kinds of editing.  You could setanother font size, for example.   To completely skip readingagvimrc file:gvim -U NONE ...==============================================================================Next chapter:usr_32.txt  Theundo treeCopyright: seemanual-copyright  vim:tw=78:ts=8:noet:ft=help:norl:

Quick links:help overview ·quick reference ·user manual toc ·reference manual toc·faq


[8]ページ先頭

©2009-2026 Movatter.jp