Skip to content

Neovim sessions not automatically restored upon prefix + Ctrl-r #470

Open
@eisukeesaki

Description

@eisukeesaki

When I execute the tmux-resurrect's restore command, the tmux windows and panes are restored as expected, however neovim sessions are not automatically restored despite having set -g @resurrect-strategy-nvim 'session' in .tmux.conf and Session.vims in the current directories. I would have to restore neovim sessions by manually executing nvim -S.

environment

relevant configuration files

neovim plugins

plug.vim

if has("nvim")
  let g:plug_home = stdpath('data') . '/plugged'
endif

call plug#begin()

if has("nvim")
  Plug 'tpope/vim-fugitive'
  Plug 'tpope/vim-rhubarb'
  Plug 'hoob3rt/lualine.nvim'
  Plug 'nvim-lua/plenary.nvim'
  Plug 'onsails/lspkind.nvim'
  Plug 'hrsh7th/cmp-buffer'
  Plug 'hrsh7th/cmp-nvim-lsp'
  Plug 'hrsh7th/nvim-cmp'
  Plug 'neovim/nvim-lspconfig'
  Plug 'jose-elias-alvarez/null-ls.nvim'
  Plug 'MunifTanjim/prettier.nvim'
  Plug 'williamboman/mason.nvim'
  Plug 'williamboman/mason-lspconfig.nvim'
  Plug 'glepnir/lspsaga.nvim'
  Plug 'L3MON4D3/LuaSnip'
  Plug 'nvim-treesitter/nvim-treesitter', { 'do': ':TSUpdate' }
  Plug 'kyazdani42/nvim-web-devicons'
  Plug 'nvim-telescope/telescope.nvim'
  " 'nvim-telescope/telescope-file-browser.nvim'
  Plug 'windwp/nvim-autopairs'
  Plug 'windwp/nvim-ts-autotag'
  Plug 'norcalli/nvim-colorizer.lua'
  " 'folke/zen-mode.nvim'
  " "iamcco/markdown-preview.nvim",
  " 'akinsho/nvim-bufferline.lua'
  " 'lewis6991/gitsigns.nvim'
  " 'dinhhuy258/git.nvim' -- For git blame & browse

  " Plug 'williamboman/nvim-lsp-installer'
  Plug 'kristijanhusak/defx-git'
  Plug 'kristijanhusak/defx-icons'
  Plug 'Shougo/defx.nvim', { 'do': ':UpdateRemotePlugins' }
  " Plug 'folke/lsp-colors.nvim'
  " Plug 'nvim-lua/popup.nvim'
  Plug 'tpope/vim-commentary'
  Plug 'jeetsukumaran/vim-indentwise'
  " Plug 'vimwiki/vimwiki'
  Plug 'tpope/vim-obsession'
  " Plug 'tpope/vim-sleuth'
  " Plug 'posva/vim-vue'
  " Plug 'jparise/vim-graphql'
  " Plug 'christoomey/vim-tmux-navigator'
  " Plug 'anuvyklack/pretty-fold.nvim'
  Plug 'pseewald/vim-anyfold'
endif

Plug 'groenewege/vim-less', { 'for': 'less' }

call plug#end()

init.vim

" Fundamentals "{{{
" ---------------------------------------------------------------------

" init autocmd
autocmd!
" set script encoding
scriptencoding utf-8
" stop loading config if it's on tiny or small
if !1 | finish | endif

set nocompatible
set number
syntax enable
set fileencodings=utf-8,sjis,euc-jp,latin
set encoding=utf-8
set title
" set autoindent
set background=dark
set nobackup
set hlsearch
set showcmd
set cmdheight=1
set laststatus=2
set scrolloff=10
set expandtab
"let loaded_matchparen = 1
set shell=fish
set backupskip=/tmp/*,/private/tmp/*

" incremental substitution (neovim)
if has('nvim')
  set inccommand=split
endif

" Suppress appending <PasteStart> and <PasteEnd> when pasting
set t_BE=

set nosc noru nosm
" Don't redraw while executing macros (good performance config)
set lazyredraw
"set showmatch
" How many tenths of a second to blink when matching brackets
"set mat=2
" Ignore case when searching
set ignorecase
" Be smart when using tabs ;)
set smarttab
" indents
filetype plugin indent on
set shiftwidth=4
set tabstop=4
set ai "Auto indent
set si "Smart indent
set nowrap "No Wrap lines
set backspace=start,eol,indent
" Finding files - Search down into subfolders
set path+=**
set wildignore+=*/node_modules/*

set number

augroup numbertoggle
  autocmd!
  autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu && mode() != "i" | set rnu   | endif
  autocmd BufLeave,FocusLost,InsertEnter,WinLeave   * if &nu                  | set nornu | endif
augroup END

" Turn off paste mode when leaving insert
autocmd InsertLeave * set nopaste

set shortmess=I

"}}}

" Highlights "{{{
" ---------------------------------------------------------------------
" set nohlsearch
set cursorline
"set cursorcolumn

" Set cursor line color on visual mode
highlight Visual cterm=NONE ctermbg=236 ctermfg=NONE guibg=Grey40

highlight LineNr cterm=none ctermfg=240 guifg=#2b506e guibg=#000000

augroup BgHighlight
  autocmd!
  autocmd WinEnter * set cul
  autocmd WinLeave * set nocul
augroup END

if &term =~ "screen"
  autocmd BufEnter * if bufname("") !~ "^?[A-Za-z0-9?]*://" | silent! exe '!echo -n "\ek[`hostname`:`basename $PWD`/`basename %`]\e\\"' | endif
  autocmd VimLeave * silent!  exe '!echo -n "\ek[`hostname`:`basename $PWD`]\e\\"'
endif

"}}}

" File types "{{{
" ---------------------------------------------------------------------
" autocmd BufNewFile,BufRead * if expand('%:t') !~ '\.' | setlocal shiftwidth=4 | endif
" autocmd BufNewFile,BufRead * if expand('%:t') !~ '\.' | set syntax=markdown | endif
au BufNewFile,BufRead * if !expand('%:t') | setlocal shiftwidth=4 | endif
au BufNewFile,BufRead * if &syntax == '' | setlocal shiftwidth=4 | endif
au BufNewFile,BufRead * if &buftype == '' | setlocal shiftwidth=4 | endif

" JavaScript
au BufNewFile,BufRead *.es6 setf javascript
" TypeScript
au BufNewFile,BufRead *.tsx setf typescriptreact
" Markdown
au BufNewFile,BufRead *.md set filetype=markdown
au BufNewFile,BufRead *.mdx set filetype=markdown
" Flow
au BufNewFile,BufRead *.flow set filetype=javascript
" Fish
au BufNewFile,BufRead *.fish set filetype=fish

set suffixesadd=.js,.es,.jsx,.json,.css,.less,.sass,.styl,.php,.py,.md

autocmd FileType json setlocal shiftwidth=2 tabstop=2
autocmd FileType javascript setlocal shiftwidth=2 tabstop=2
autocmd FileType typescriptreact setlocal shiftwidth=2 tabstop=2
autocmd FileType typescript setlocal shiftwidth=2 tabstop=2
autocmd FileType markdown setlocal shiftwidth=4 tabstop=4
autocmd FileType sql setlocal shiftwidth=4 tabstop=4
autocmd FileType vue setlocal shiftwidth=2 tabstop=2
autocmd FileType html setlocal shiftwidth=2 tabstop=2
autocmd FileType css setlocal shiftwidth=2 tabstop=2

"}}}

" Imports "{{{
" ---------------------------------------------------------------------
runtime ./plug.vim
if has("unix")
  let s:uname = system("uname -s")
  " Do Mac stuff
  if s:uname == "Darwin\n"
    runtime ./macos.vim
  endif
endif
if has('win32')
  runtime ./windows.vim
endif

runtime ./maps.vim
runtime ./commands.vim
"}}}

" Syntax theme "{{{
" ---------------------------------------------------------------------

" true color
if exists("&termguicolors") && exists("&winblend")
  syntax enable
  set termguicolors
  set winblend=0
  set wildoptions=pum
  set pumblend=5
  set background=dark
  " Use NeoSolarized
  let g:neosolarized_termtrans=1
  runtime ./colors/NeoSolarized.vim
  colorscheme NeoSolarized
endif

"}}}

" LSP Diagnostic "{{{
" ---------------------------------------------------------------------
autocmd BufEnter * lua vim.diagnostic.disable()

" Extras "{{{
" ---------------------------------------------------------------------
set exrc
set signcolumn=yes
"}}}
"
" vim: set foldmethod=marker foldlevel=0:

" Add asterisks in block comments
" set formatoptions-=cro

autocmd Filetype * setlocal formatoptions-=cro

" let g:vimwiki_key_mappings = { 'all_maps': 0, }

let g:vimwiki_key_mappings =
  \ {
  \   'all_maps': 1,
  \   'global': 1,
  \   'headers': 1,
  \   'text_objs': 1,
  \   'table_format': 1,
  \   'table_mappings': 0,
  \   'lists': 1,
  \   'links': 1,
  \   'html': 1,
  \   'mouse': 0,
  \ }

.tmux.conf

set -g default-terminal "xterm-256color"
#set -ga terminal-overrides ",*256col*:Tc"
set -ga terminal-overrides ",xterm-256color:Tc"
# action key
unbind C-b
unbind C-z
set-option -g prefix C-t
set-option -g repeat-time 0

#### Key bindings
set-window-option -g mode-keys vi
set-window-option -g xterm-keys on
# set -g terminal-overrides "screen*:kLFT5=\eOD:kRIT5=\eOC:kUP5=\eOA:kDN5=\eOB:smkx@:rmkx@"

#bind t send-key C-t
# Reload settings
bind r source-file ~/.tmux.conf \; display "Reloaded!"
# Open current directory
bind o run-shell "open #{pane_current_path}"
bind -r e kill-pane -a

# vim-like pane switching
# bind -r k select-pane -U 
# bind -r j select-pane -D 
# bind -r h select-pane -L 
# bind -r l select-pane -R 

# move pane focus
bind-key -n C-Left select-pane -L
bind-key -n C-Right select-pane -R
bind-key -n C-Down select-pane -D
bind-key -n C-Up select-pane -U

# vim-tmux-navigator
# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
# is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
#     | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
# bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h'  'select-pane -L'
# bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j'  'select-pane -D'
# bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k'  'select-pane -U'
# bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l'  'select-pane -R'
# tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
# if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
#     "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\'  'select-pane -l'"
# if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
#     "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\'  'select-pane -l'"
# bind-key -T copy-mode-vi 'C-Left' select-pane -L
# bind-key -T copy-mode-vi 'C-Down' select-pane -D
# bind-key -T copy-mode-vi 'C-Up' select-pane -U
# bind-key -T copy-mode-vi 'C-Right' select-pane -R
# bind-key -T copy-mode-vi 'C-\' select-pane -l

# find and select window by index name
# bind-key C-S-, command-prompt -W -p index "select-window -t ':%%'"
# bind-key -n C-S-i command-prompt -W -p index "select-window -t ':%%'"

# creaate new window
# bind-key -n C-S-n new-window

# Moving window
bind-key -n C-S-Down swap-window -t -1 \; previous-window
bind-key -n C-S-Up swap-window -t +1 \; next-window

# next/previous-window
bind-key -n C-S-Left previous-window
bind-key -n C-S-Right next-window

# Resizing pane
# bind -r C-k resize-pane -U 5
# bind -r C-j resize-pane -D 5
# bind -r C-h resize-pane -L 5
# bind -r C-l resize-pane -R 5

# switch to window by index name
# bind-key C-S-w command-prompt "select-window %%"


#### basic settings

set-option -g status-justify "left"
#set-option utf8-default on
#set-option -g mouse-select-pane
set-window-option -g mode-keys vi
#set-window-option -g utf8 on
# look'n feel
set-option -g status-fg cyan
set-option -g status-bg black
set -g pane-active-border-style fg=colour166,bg=default
set -g window-style fg=colour10,bg=default
set -g window-active-style fg=colour12,bg=default
set-option -g history-limit 64096

set -sg escape-time 10

#### COLOUR

# default statusbar colors
set-option -g status-style bg=colour235,fg=colour136,default

# default window title colors
set-window-option -g window-status-style fg=colour244,bg=colour234,dim

# active window title colors
set-window-option -g window-status-current-style fg=colour166,bg=default,bright

# pane border
set-option -g pane-border-style fg=colour235 #base02
set-option -g pane-active-border-style fg=colour136,bg=colour235

# message text
set-option -g message-style bg=colour235,fg=colour166

# pane number display
set-option -g display-panes-active-colour colour33 #blue
set-option -g display-panes-colour colour166 #orange

# clock
set-window-option -g clock-mode-colour colour64 #green

# allow the title bar to adapt to whatever host you connect to
set -g set-titles on
set -g set-titles-string "#T"

# import
if-shell "uname -s | grep -q Darwin" "source ~/.tmux.conf.osx"

# Powerline
source ~/.tmux.powerline.conf

# plugins
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @plugin 'tmux-plugins/tmux-yank'

## plugin options
set -g @resurrect-strategy-nvim 'session'
set -g @resurrect-processes 'nvim'
# set -g @continuum-restore 'on'
# set -g @resurrect-capture-pane-contents 'on' # this causes tmux server to crash upon tmux-resurrect.restore
# set -g default-command "reattach-to-user-namespace -l $SHELL" # this does not work

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

fish config

set fish_greeting ""

set -gx TERM xterm-256color

# theme
# set -g CLICOLOR 1
set -g theme_color_scheme terminal-dark
set -g fish_prompt_pwd_dir_length 1
set -g theme_display_user yes
set -g theme_hide_hostname no
set -g theme_hostname always

# aliases
## ls 
alias l "ls -p -G"
alias la "ls -A"
alias ll "ls -l"
alias llsm "ll --sort=modified"
alias lla "ll -A"
alias llasm "lla --sort=modified"
## others
alias c "cd"
alias ex "exit"
alias gr "grep"
alias f "find"
alias c "clear"
alias tm "tmux"
alias v "nvim"
alias g "git"
alias ide $HOME/.config/.ide
alias ide2 $HOME/.config/.ide2
alias sph $HOME/.config/.tmux.split-window-horizontal
alias sv $HOME/.config/.tmux.split-window-vertical
alias sv75 $HOME/.config/.tmux.split-window-vertical-75
alias sv3 $HOME/.config/.tmux.3-equal-v-splits
alias sp6 $HOME/.config/tmux.6-panes
alias n "node"
alias vsc "/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code"
alias t "tsc"
alias tn "ts-node"
alias ash "aws-shell"

set -gx HOMEBREW_LOG_FILE /usr/local/var/log/homebrew.log

set -gx EDITOIR nvim
#set -gx PAGER nvim

set -gx PATH bin $PATH
set -gx PATH ~/bin $PATH
set -gx PATH ~/.local/bin $PATH

set -gx PATH node_modules/.bin $PATH

# pyenv
# I'll configure this next time I use pyenv
pyenv init - | source

# Node.js
set -gx PATH $HOME/.nvm/versions/node/v16.13.1/bin $PATH

# Kaleidoscope
set -gx KALEIDOSCOPE_DIR $HOME/atreus/Kaleidoscope

# TODO: config to prevent closing terminal when ^d is pressed

set -gx PATH /usr/local/Cellar/v8/10.6.194.18/bin $PATH

switch (uname)
  case Darwin
    source (dirname (status --current-filename))/config-osx.fish
  case Linux
    source (dirname (status --current-filename))/config-linux.fish
end

set LOCAL_CONFIG (dirname (status --current-filename))/config-local.fish
if test -f $LOCAL_CONFIG
  source $LOCAL_CONFIG
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions