GNU/Linux >> Tutoriales Linux >  >> Linux

¿Guardar el estado actual de la sesión de Vim y restaurarlo más tarde (por ejemplo, búferes, divisiones, etc.)?

Como antiguo usuario de VIM, atraído por él en primer lugar, especialmente por sus sencillas sustituciones de expresiones regulares que permiten trabajar muy rápido, realmente no espero que VIM tenga esa característica. Pero, qué diablos, tal vez se me pasó por alto algo o alguna novedad.

¿Conocerías una forma de vim , al reabrir una enorme lista de archivos (todos los archivos de origen cpp/h de un proyecto a saber) en modo dividido en n columnas adaptado al tamaño de la pantalla (consulte el comando bash/alias a continuación), para tener búferes anteriores abiertos/seleccionados/activos volver en lugar de restablecer los n primeros archivos en los búferes visibles? Un poco como lo haría un IDE, guardando el estado de los archivos abiertos.

# 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 )) \{} \+'

Respuesta aceptada:

Puedes usar sesiones vim para eso. Solo ejecuta:

:mksession mysession.vim

y se creará un archivo en el directorio actual (llamado 'mysession.vim'). La próxima vez que abra vim, puede hacer:

 :source mysession.vim

(o como lo hayas llamado) y volverás al estado en el que estabas cuando creaste el archivo de sesión (todas las divisiones estarán allí, etc.).

De la ayuda:

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. ¿Cómo enumerar los descriptores de archivos abiertos (y los archivos a los que se refieren) en la sesión actual de Bash?

  2. Obtener la hora actual en horas y minutos

  3. Linux ext4 restaurar archivos y derechos de acceso al directorio después de una mala copia de seguridad/restauración

  4. ¿Cuál es la conexión entre los directorios /etc/init.d y /etc/rcX.d en Linux?

  5. ¿Cómo funcionan juntos `/etc/hosts` y DNS para resolver nombres de host en direcciones IP?

Cómo guardar un archivo en Vim/Vi y salir del editor

Cómo deshacer y rehacer en Vim / Vi

La forma correcta de editar archivos /etc/passwd y /etc/group en Linux

Cómo guardar un archivo en Vi / Vim y salir del editor

Vim vs Vi:¿similitudes y diferencias entre VIM y VI?

Guardar y restaurar terminal al reiniciar