vim-sandwich
vim-sandwich copied to clipboard
LaTeX command replacement c stops working
I can't tell when exactly, but usually for LaTeX documents, saiwc
should surround a word with a command that is given via input. This sometimes stops working for me in some buffers. While in one buffers this still produces the desired results, in another buffer this just surrounds a word with the character c
.
Any idea how to debug this?
This is not a feature of vimtex, as far as I can remember. With vimtex, you can change or delete a surrounding command, but not create one. I expect this feature either to be provided by vim-sandwich or vim-surround.
Blahrg, sorry: I just noticed this issue is with vim-sandwich, not vimtex. I'm sorry for the confusion.
hmm... It sounds strange. Could you check the following outputs when you reproduce the situation?
-
:echom &filetype
-
:echom exists('b:did_sandwich_initex_ftplugin')
Strange, somehow this doesn't happen anymore. So maybe it is fixed now. I'll just close this issue as long as it doesn't happen again.
Ok. Feel free to reopen if you saw it again.
I just noticed this issue, and actually I have the same (I think) problem. I've been meaning to file an issue but I haven't had time to do more digging.
For me, here are a few things that I notice:
- The issue is not just with the
c
sandwich but with any LaTeX recipe that vim-sandwich defines (for example, the environmente
or delimiters like them(
recipe corresponding to\left(
\right)
). In all of these cases, it will just surround with the first letter, i.e.e
orm
(it does not wait to see the(
in the latter case). - The issue also happens with any of my user-defined recipes in my .vimrc, I believe.
- The only way I have been able to recreate this is that it consistently happens after I attempt a reverse-search. I am not sure if there are other mechanisms that trigger the problem.
I use Neovim with the vimtex plugin and my PDF viewer is Skim (on a Mac). I have been meaning to experiment with different settings, for example trying Vim8 and/or Zathura, to see how consistent the issue is. I don't know if this is the exact same problem @languitar has and how similar his configuration is to mine.
Unfortunately I don't know much about the internals of vim, but based on the behavior I see, it seems like doing a reverse-search somehow refreshes vim and reloads vim-sandwich with only the default recipes, so none of the LaTeX recipes exist anymore. Perhaps @lervag can also offer some insight.
I just noticed the post above and tried the following queries:
-
:echom &filetype
consistently returnstex
-
:echom exists('b:did_sandwich_initex_ftplugin')
is giving1
until I try a reverse-search, and then it gives0
Thank you for your so detailed report! I will re-open this issue.
Let me just make sure, reverse-search is ?
command? If so, can I ask you to check the output of :verbose nmap ?
in tex
filetype buffer?
Strange. For the Skim viewer, backward search is set in the Skim app, see here. That is, this is not provided directly by vimtex, and so I don't know what you are doing in the backward search call. With Zathura, vimtex does enable backward search directly. It would be interesting to know if the problem persists with Zathura.
@albertfgu Could you also provide the details you've used to enable backward sync?
@machakann Ah sorry, what I meant by reverse search is usually called "backward search" or "inverse search". It is when you click on a line of output.pdf and it jumps to the line of output.tex corresponding to it.
@lervag My vimrc only has the following relevant lines:
let g:vimtex_view_method = 'skim'
let g:vimtex_compiler_progname = 'nvr'
My Skim settings for "PDF-TeX Sync support":
Preset: Custom
Command: nvr
Arguments: --remote-silent +":%line | silent foldo!" "%file"
I am planning on trying Zathura at some point, when I find the time. I've been putting it off because it looks more difficult to configure :) . I'll let you guys know if the problem persists there.
I think you should be able to reproduce from the terminal with
nvr --remote-silent +":100 | silent foldo!" "<filename>"
I.e.:
- Open a tex file in neovim
- Check
&filetype
andb:did_sandwhich_initex_ftplugin
- Do
nvr --remote-silent +":100 | silent foldo!" "<filename>"
from the terminal - Repeat 2
If this does reproduce your issue, then try to do this without vimtex. Does it still reproduce? And more generally, try to reproduce this with a minimal vimrc file that only loads vim-sandwich, something like:
set nocompatible
let &rtp = '~/.vim/bundle/vim-sandwich,' . &rtp
filetype plugin indent on
syntax enable
" Add relevant options here
Now repeat the above steps, but use nvim -u minivimrc <filename.tex>
.
I followed the above steps generally; I couldn't understand some of the steps so this is what I did:
- Open a tex file with a few lines called temp.tex
-
:echom &filetype
printstex
and:echom exists('b:did_sandwich_initex_ftplugin')
prints1
- I ran
:!nvr --remote-silent temp.tex
. (Running it from a separate terminal gave annoying swap file messages.) I'm not sure what this command did because it froze neovim and I had to Ctrl-C to resume. - Repeating step 2, the filetype is still correct and
:echom exists('b:did_sandwich_initex_ftplugin')
now prints0
This happened even with a minimal vimrc (unfortunately I couldn't figure out how to load vim-sandwich without using the plugin manager):
call plug#begin('~/.local/share/nvim/plugged')
Plug 'machakann/vim-sandwich'
call plug#end()
Now I prepared a newly installed Ubuntu 16.04 and installed neovim. I reproduced the same problem probably. What I tried is the following procedure.
- Put the
~/.config/nvim/init.vim
.
filetype plugin indent on
syntax enable
- Install
vim-sandwich
into~/.config/nvim/pack/mypackages/start
.
mkdir -p ~/.config/nvim/pack/mypackages/start
cd ~/.config/nvim/pack/mypackages/start
git clone https://github.com/machakann/vim-sandwich
- Launch neovim with opening a .tex file
touch ~/temp.tex
nvim ~/temp.tex
At this moment:
-
echo &filetype
->plaintex
-
echo exists('b:did_sandwich_initex_ftplugin')
->1
- Execute
:terminal
command and exit the terminal buffer immediately
:terminal
exit
Now:
-
echo &filetype
->plaintex
-
echo exists('b:did_sandwich_initex_ftplugin')
->0
I still don't know why but it looks neovim execute b:undo_ftplugin
(in ~/.config/nvim/pack/mypackages/start/vim-sandwich/after/ftplugin/initex/sandwich.vim
) between step 3 and 4. The filetype-plugin handlings of neovim might be a little different from that of Vim.
I just ended up in the same situation again. I have been using reverse search before on the same file and it worked for some time. The first time I noticed this was after performing a :Neoformat
. Afterwards, the filetype plugin for tex from sandwhich wasn't loaded anymore.
Alright, I can confirm that also Neoformat
triggers this behavior. Is there a chance to reload the mappings manually while this is an issue without having to delete and reopen the buffer?
Thank you! I finally found the problem. after/ftplugin/**/*.vim
files were not sourced in FileType autocmd event, not like ftplugin/**/*.vim
files. Probably the latest commit (dca5b29) fixed the problem. Please test it!
Seems to work for me now!
Just looking at your commit: could this happen also with other languages? Seems you have only moved stuff for tex.
Probably yes, but actually the file re-arrangement is rather trivial. The main fix is to add autocmd, I should have split the commit.
https://github.com/machakann/vim-sandwich/blob/dca5b29e3a55c884396575bff338d8647198e634/after/ftplugin/initex/sandwich.vim#L7-L10 https://github.com/machakann/vim-sandwich/blob/dca5b29e3a55c884396575bff338d8647198e634/after/ftplugin/plaintex/sandwich.vim#L7-L10 https://github.com/machakann/vim-sandwich/blob/dca5b29e3a55c884396575bff338d8647198e634/after/ftplugin/tex/sandwich.vim#L7-L10