GNU/Linux >> LINUX-Kenntnisse >  >> Linux

Aktuellen Vim-Sitzungsstatus speichern und später wiederherstellen (z. B. Puffer, Splits usw.)?

Als alter VIM-Benutzer, der sich in erster Linie für seine unkomplizierten Regex-Ersetzungen interessiert hat, die ein sehr schnelles Arbeiten ermöglichen, erwarte ich nicht wirklich, dass VIM eine solche Funktion hat. Aber was soll's, vielleicht habe ich etwas oder eine Neuheit übersehen.

Kennen Sie zufällig einen Weg für vim , beim erneuten Öffnen einer riesigen Liste von Dateien (nämlich alle cpp/h-Quelldateien eines Projekts) im n-Spalten-Split-Modus, angepasst an die Bildschirmgröße (siehe Bash-Befehl/Alias ​​unten), um zuvor geöffnete/ausgewählte/aktive Puffer zu haben zurückkommen, anstatt auf die n ersten Dateien über sichtbare Puffer zurückzusetzen? Ein bisschen wie eine IDE es tun würde, indem sie den Zustand der geöffneten Dateien speichert.

# check the window size after each command and, if necessary,                   
# update the values of LINES and COLUMNS.                                       
shopt -s checkwinsize                                                           
alias vimcpp='find . \( -name '\''*.cpp'\'' -o -name '\''*.cc'\'' -o -name '\''*.cxx'\'' -o -name '\''*.c'\'' -o -name '\''*.hpp'\'' -o -name '\''*.hh'\'' -o -name '\''*.hxx'\'' -o -name '\''*.h'\'' \) -exec vim -O$(( ( ( $COLUMNS - 1 ) / 80 > 0 ) ? ( ( $COLUMNS - 1 ) / 80 ) : 1 )) \{} \+'

Akzeptierte Antwort:

Sie können dafür vim-Sitzungen verwenden. Führen Sie einfach Folgendes aus:

:mksession mysession.vim

und eine Datei wird im aktuellen Verzeichnis erstellt (mit dem Namen „mysession.vim“). Wenn Sie vim das nächste Mal öffnen, können Sie Folgendes tun:

 :source mysession.vim

(oder wie auch immer Sie es genannt haben) und Sie finden sich wieder in dem Zustand wieder, in dem Sie sich befanden, als Sie die Sitzungsdatei erstellt haben (alle Teilungen sind dort usw.).

Aus der Hilfe:

This is introduced in sections 21.4 and 21.5 of the user manual.

:mks[ession][!] [file]  Write a Vim script that restores the current editing
            session.
            When [!] is included an existing file is overwritten.
            When [file] is omitted "Session.vim" is used.


The resulting file, when executed with a ":source" command:

1. Restores global mappings and options, if 'sessionoptions' contains
   "options".  Script-local mappings will not be written.
2. Restores global variables that start with an uppercase letter and contain
   at least one lowercase letter, if 'sessionoptions' contains "globals".
3. Closes all windows in the current tab page, except the current one; closes
   all tab pages except the current one (this results in currently loaded
   buffers to be unloaded, some may become hidden if 'hidden' is set or
   otherwise specified); wipes out the current buffer, if it is empty
   and unnamed.
4. Restores the current directory if 'sessionoptions' contains "curdir", or
   sets the current directory to where the Session file is if 'sessionoptions'
   contains "sesdir".
5. Restores GUI Vim window position, if 'sessionoptions' contains "winpos".
6. Restores screen size, if 'sessionoptions' contains "resize".
7. Reloads the buffer list, with the last cursor positions.  If
   'sessionoptions' contains "buffers" then all buffers are restored,
   including hidden and unloaded buffers.  Otherwise only buffers in windows
   are restored.
8. Restores all windows with the same layout.  If 'sessionoptions' contains
   "help", help windows are restored.  If 'sessionoptions' contains "blank",
   windows editing a buffer without a name will be restored.
   If 'sessionoptions' contains "winsize" and no (help/blank) windows were
   left out, the window sizes are restored (relative to the screen size).
   Otherwise, the windows are just given sensible sizes.
9. Restores the Views for all the windows, as with |:mkview|.  But
   'sessionoptions' is used instead of 'viewoptions'.
10. If a file exists with the same name as the Session file, but ending in
   "x.vim" (for eXtra), executes that as well.  You can use *x.vim files to
   specify additional settings and actions associated with a given Session,
   such as creating menu items in the GUI version.

Linux
  1. So bearbeiten Sie mehrere Dateien und wechseln zwischen diesen in VIM mithilfe von Puffern

  2. Linux – So speichern Sie eine X-Sitzung – Archlinux+openbox?

  3. Wie listet man die offenen Dateideskriptoren (und die Dateien, auf die sie sich beziehen) in der aktuellen Bash-Sitzung auf?

  4. Speichern und Wiederherstellen Ihrer Terminal-Tabs?

  5. So sichern und wiederherstellen Sie eine Datenbank in PostgreSQL

So speichern Sie eine Datei in Vim / Vi und beenden den Editor

So machen Sie Rückgängig und Wiederherstellen in Vim / Vi

Der richtige Weg zum Bearbeiten von /etc/passwd- und /etc/group-Dateien unter Linux

So speichern Sie eine Datei in Vi / Vim und beenden den Editor

Vim vs. Vi – Ähnlichkeiten und Unterschiede zwischen VIM und VI?

Wie arbeiten `/etc/hosts` und DNS zusammen, um Hostnamen in IP-Adressen aufzulösen?