*usr_21.txt* For MNV version 10.0. Last change: 2026 Feb 14 MNV USER MANUAL by Bram Moolenaar Go away and come back This chapter goes into mixing the use of other programs with MNV. Either by executing program from inside MNV or by leaving MNV and coming back later. Furthermore, this is about the ways to remember the state of MNV and restore it later. |21.1| Suspend and resume |21.2| Executing shell commands |21.3| Remembering information; mnvinfo |21.4| Sessions |21.5| Views |21.6| Modelines Next chapter: |usr_22.txt| Finding the file to edit Previous chapter: |usr_20.txt| Typing command-line commands quickly Table of contents: |usr_toc.txt| ============================================================================== *21.1* Suspend and resume Like most Unix programs MNV can be suspended by pressing CTRL-Z. This stops MNV and takes you back to the shell it was started in. You can then do any other commands until you are bored with them. Then bring back MNV with the "fg" command. > CTRL-Z {any sequence of shell commands} fg You are right back where you left MNV, nothing has changed. In case pressing CTRL-Z doesn't work, you can also use ":suspend". Don't forget to bring MNV back to the foreground, you would lose any changes that you made! Only Unix has support for this. On other systems MNV will start a shell for you. This also has the functionality of being able to execute shell commands. But it's a new shell, not the one that you started MNV from. When you are running the GUI you can't go back to the shell where MNV was started. CTRL-Z will minimize the MNV window instead. ============================================================================== *21.2* Executing shell commands To execute a single shell command from MNV use ":!{command}". For example, to see a directory listing: > :!ls :!dir The first one is for Unix, the second one for MS-Windows. MNV will execute the program. When it ends you will get a prompt to hit . This allows you to have a look at the output from the command before returning to the text you were editing. The "!" is also used in other places where a program is run. Let's take a look at an overview: :!{program} execute {program} :r !{program} execute {program} and read its output :w !{program} execute {program} and send text to its input :[range]!{program} filter text through {program} Notice that the presence of a range before "!{program}" makes a big difference. Without it executes the program normally, with the range a number of text lines is filtered through the program. Executing a whole row of programs this way is possible. But a shell is much better at it. You can start a new shell this way: > :shell This is similar to using CTRL-Z to suspend MNV. The difference is that a new shell is started. When using the GUI the shell will be using the MNV window for its input and output. Since MNV is not a terminal emulator, this will not work perfectly. If you have trouble, try toggling the 'guipty' option. If this still doesn't work well enough, start a new terminal to run the shell in. For example with: > :!xterm& ============================================================================== *21.3* Remembering information; mnvinfo After editing for a while you will have text in registers, marks in various files, a command line history filled with carefully crafted commands. When you exit MNV all of this is lost. But you can get it back! The mnvinfo file is designed to store status information: Command-line and Search pattern history Text in registers Marks for various files The buffer list Global variables Each time you exit MNV it will store this information in a file, the mnvinfo file. When MNV starts again, the mnvinfo file is read and the information restored. The 'mnvinfo' option is set by default to restore a limited number of items. You might want to set it to remember more information. This is done through the following command: > :set mnvinfo=string The string specifies what to save. The syntax of this string is an option character followed by an argument. The option/argument pairs are separated by commas. Take a look at how you can build up your own mnvinfo string. First, the ' option is used to specify how many files for which you save marks (a-z). Pick a nice even number for this option (1000, for instance). Your command now looks like this: > :set mnvinfo='1000 The f option controls whether global marks (A-Z and 0-9) are stored. If this option is 0, none are stored. If it is 1 or you do not specify an f option, the marks are stored. You want this feature, so now you have this: > :set mnvinfo='1000,f1 The < option controls how many lines are saved for each of the registers. By default, all the lines are saved. If 0, nothing is saved. To avoid adding thousands of lines to your mnvinfo file (which might never get used and makes starting MNV slower) you use a maximum of 500 lines: > :set mnvinfo='1000,f1,<500 < Other options you might want to use: : number of lines to save from the command line history @ number of lines to save from the input line history / number of lines to save from the search history r removable media, for which no marks will be stored (can be used several times) ! global variables that start with an uppercase letter and don't contain lowercase letters h disable 'hlsearch' highlighting when starting % the buffer list (only restored when starting MNV without file arguments) c convert the text using 'encoding' n name used for the mnvinfo file (must be the last option) See the 'mnvinfo' option and |mnvinfo-file| for more information. When you run MNV multiple times, the last one exiting will store its information. This may cause information that previously exiting MNVs stored to be lost. Each item can be remembered only once. GETTING BACK TO WHERE YOU STOPPED MNV You are halfway editing a file and it's time to leave for holidays. You exit MNV and go enjoy yourselves, forgetting all about your work. After a couple of weeks you start MNV, and type: > '0 And you are right back where you left MNV. So you can get on with your work. MNV creates a mark each time you exit MNV. The last one is '0. The position that '0 pointed to is made '1. And '1 is made to '2, and so forth. Mark '9 is lost. The |:marks| command is useful to find out where '0 to '9 will take you. GETTING BACK TO SOME FILE If you want to go back to a file that you edited recently, but not when exiting MNV, there is a slightly more complicated way. You can see a list of files by typing the command: > :oldfiles < 1: ~/.mnvinfo ~ 2: ~/text/resume.txt ~ 3: /tmp/draft ~ Now you would like to edit the second file, which is in the list preceded by "2:". You type: > :e #<2 Instead of ":e" you can use any command that has a file name argument, the "#<2" item works in the same place as "%" (current file name) and "#" (alternate file name). So you can also split the window to edit the third file: > :split #<3 That #<123 thing is a bit complicated when you just want to edit a file. Fortunately there is a simpler way: > :browse oldfiles < 1: ~/.mnvinfo ~ 2: ~/text/resume.txt ~ 3: /tmp/draft ~ -- More -- You get the same list of files as with |:oldfiles|. If you want to edit "resume.txt" first press "q" to stop the listing. You will get a prompt: Type number and (empty cancels): ~ Type "2" and press to edit the second file. If you know that the filename contains a pattern, you can also |:filter| the list of files: > :filter /resume/ :browse oldfiles < Since there is only one single matching filename, MNV will directly edit that file without prompting. If the filter matches several files, you'll get prompted for the list of matching files instead: > :filter! /resume/ browse oldfiles < 1: ~/.mnvinfo ~ 3: /tmp/draft ~ Type number and (q or empty cancels): ~ Note: this time we filtered out all files NOT matching resume. More info at |:oldfiles|, |v:oldfiles| and |c_#<|. MOVE INFO FROM ONE MNV TO ANOTHER You can use the ":wmnvinfo" and ":rmnvinfo" commands to save and restore the information while still running MNV. This is useful for exchanging register contents between two instances of MNV, for example. In the first MNV do: > :wmnvinfo! ~/tmp/mnvinfo And in the second MNV do: > :rmnvinfo! ~/tmp/mnvinfo Obviously, the "w" stands for "write" and the "r" for "read". The ! character is used by ":wmnvinfo" to forcefully overwrite an existing file. When it is omitted, and the file exists, the information is merged into the file. The ! character used for ":rmnvinfo" means that all the information is used, this may overwrite existing information. Without the ! only information that wasn't set is used. These commands can also be used to store info and use it again later. You could make a directory full of mnvinfo files, each containing info for a different purpose. ============================================================================== *21.4* Sessions Suppose you are editing along, and it is the end of the day. You want to quit work and pick up where you left off the next day. You can do this by saving your editing session and restoring it the next day. A MNV session contains all the information about what you are editing. This includes things such as the file list, window layout, global variables, options and other information. (Exactly what is remembered is controlled by the 'sessionoptions' option, described below.) The following command creates a session file: > :mksession mnvbook.mnv Later if you want to restore this session, you can use this command: > :source mnvbook.mnv If you want to start MNV and restore a specific session, you can use the following command: > mnv -S mnvbook.mnv This tells MNV to read a specific file on startup. The 'S' stands for session (actually, you can source any MNV script with -S, thus it might as well stand for "source"). The windows that were open are restored, with the same position and size as before. Mappings and option values are like before. What exactly is restored depends on the 'sessionoptions' option. The default value is: "blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal". blank keep empty windows buffers all buffers, not only the ones in a window curdir the current directory folds folds, also manually created ones help the help window options all options and mappings tabpages all tab pages winsize window sizes terminal include terminal windows Change this to your liking. To also restore the size of the MNV window, for example, use: > :set sessionoptions+=resize SESSION HERE, SESSION THERE The obvious way to use sessions is when working on different projects. Suppose you store your session files in the directory "~/.mnv". You are currently working on the "secret" project and have to switch to the "boring" project: > :wall :mksession! ~/.mnv/secret.mnv :source ~/.mnv/boring.mnv This first uses ":wall" to write all modified files. Then the current session is saved, using ":mksession!". This overwrites the previous session. The next time you load the secret session you can continue where you were at this point. And finally you load the new "boring" session. If you open help windows, split and close various windows, and generally mess up the window layout, you can go back to the last saved session: > :source ~/.mnv/boring.mnv Thus you have complete control over whether you want to continue next time where you are now, by saving the current setup in a session, or keep the session file as a starting point. Another way of using sessions is to create a window layout that you like to use, and save this in a session. Then you can go back to this layout whenever you want. For example, this is a nice layout to use: +----------------------------------------+ | MNV - main help file | | | |Move around: Use the cursor keys, or "h| |help.txt================================| |explorer | | |dir |~ | |dir |~ | |file |~ | |file |~ | |file |~ | |file |~ | |~/=========|[No File]===================| | | +----------------------------------------+ This has a help window at the top, so that you can read this text. The narrow vertical window on the left contains a file explorer. This is a MNV plugin that lists the contents of a directory. You can select files to edit there. More about this in the next chapter. Create this from a just started MNV with: > :help CTRL-W w :vertical split ~/ You can resize the windows a bit to your liking. Then save the session with: > :mksession ~/.mnv/mine.mnv Now you can start MNV with this layout: > mnv -S ~/.mnv/mine.mnv Hint: To open a file you see listed in the explorer window in the empty window, move the cursor to the filename and press "O". Double clicking with the mouse will also do this. UNIX AND MS-WINDOWS Some people have to do work on MS-Windows systems one day and on Unix another day. If you are one of them, consider adding "slash" and "unix" to 'sessionoptions'. The session files will then be written in a format that can be used on both systems. This is the command to put in your mnvrc file: > :set sessionoptions+=unix,slash MNV will use the Unix format then, because the MS-Windows MNV can read and write Unix files, but Unix MNV can't read MS-Windows format session files. Similarly, MS-Windows MNV understands file names with / to separate names, but Unix MNV doesn't understand \. SESSIONS AND MNVINFO Sessions store many things, but not the position of marks, contents of registers and the command line history. You need to use the mnvinfo feature for these things. In most situations you will want to use sessions separately from mnvinfo. This can be used to switch to another session, but keep the command line history. And yank text into registers in one session, and paste it back in another session. You might prefer to keep the info with the session. You will have to do this yourself then. Example: > :mksession! ~/.mnv/secret.mnv :wmnvinfo! ~/.mnv/secret.mnvinfo And to restore this again: > :source ~/.mnv/secret.mnv :rmnvinfo! ~/.mnv/secret.mnvinfo ============================================================================== *21.5* Views A session stores the looks of the whole of MNV. When you want to store the properties for one window only, use a view. The use of a view is for when you want to edit a file in a specific way. For example, you have line numbers enabled with the 'number' option and defined a few folds. Just like with sessions, you can remember this view on the file and restore it later. Actually, when you store a session, it stores the view of each window. There are two basic ways to use views. The first is to let MNV pick a name for the view file. You can restore the view when you later edit the same file. To store the view for the current window: > :mkview MNV will decide where to store the view. When you later edit the same file you get the view back with this command: > :loadview That's easy, isn't it? Now you want to view the file without the 'number' option on, or with all folds open, you can set the options to make the window look that way. Then store this view with: > :mkview 1 Obviously, you can get this back with: > :loadview 1 Now you can switch between the two views on the file by using ":loadview" with and without the "1" argument. You can store up to ten views for the same file this way, one unnumbered and nine numbered 1 to 9. A VIEW WITH A NAME The second basic way to use views is by storing the view in a file with a name you choose. This view can be loaded while editing another file. MNV will then switch to editing the file specified in the view. Thus you can use this to quickly switch to editing another file, with all its options set as you saved them. For example, to save the view of the current file: > :mkview ~/.mnv/main.mnv You can restore it with: > :source ~/.mnv/main.mnv ============================================================================== *21.6* Modelines When editing a specific file, you might set options specifically for that file. Typing these commands each time is boring. Using a session or view for editing a file doesn't work when sharing the file between several people. The solution for this situation is adding a modeline to the file. This is a line of text that tells MNV the values of options, to be used in this file only. A typical example is a C program where you make indents by a multiple of 4 spaces. This requires setting the 'shiftwidth' option to 4. This modeline will do that: /* mnv:set shiftwidth=4: */ ~ Put this line as one of the first or last five lines in the file. When editing the file, you will notice that 'shiftwidth' will have been set to four. When editing another file, it's set back to the default value of eight. For some files the modeline fits well in the header, thus it can be put at the top of the file. For text files and other files where the modeline gets in the way of the normal contents, put it at the end of the file. The 'modelines' option specifies how many lines at the start and end of the file are inspected for containing a modeline. To inspect ten lines: > :set modelines=10 The 'modeline' option can be used to switch this off. Do this when you are working as root on Unix or Administrator on MS-Windows, or when you don't trust the files you are editing: > :set nomodeline Use this format for the modeline: any-text mnv:set {option}={value} ... : any-text ~ The "any-text" indicates that you can put any text before and after the part that MNV will use. This allows making it look like a comment, like what was done above with /* and */. The " mnv:" part is what makes MNV recognize this line. There must be white space before "mnv", or "mnv" must be at the start of the line. Thus using something like "gmnv:" will not work. The part between the colons is a ":set" command. It works the same way as typing the ":set" command, except that you need to insert a backslash before a colon (otherwise it would be seen as the end of the modeline). Another example: // mnv:set textwidth=72 dir=c\:\tmp: use c:\tmp here ~ There is an extra backslash before the first colon, so that it's included in the ":set" command. The text after the second colon is ignored, thus a remark can be placed there. For more details see |modeline|. ============================================================================== Next chapter: |usr_22.txt| Finding the file to edit Copyright: see |manual-copyright| mnv:tw=78:ts=8:noet:ft=help:norl: