machakann / vim-sandwich

Set of operators and textobjects to search/select/edit sandwiched texts.
1.42k stars 38 forks source link

LaTeX command replacement c stops working #55

Open languitar opened 6 years ago

languitar commented 6 years ago

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?

lervag commented 6 years ago

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.

lervag commented 6 years ago

Blahrg, sorry: I just noticed this issue is with vim-sandwich, not vimtex. I'm sorry for the confusion.

machakann commented 6 years ago

hmm... It sounds strange. Could you check the following outputs when you reproduce the situation?

  1. :echom &filetype
  2. :echom exists('b:did_sandwich_initex_ftplugin')
languitar commented 6 years ago

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.

machakann commented 6 years ago

Ok. Feel free to reopen if you saw it again.

albertfgu commented 6 years ago

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:

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.

albertfgu commented 6 years ago

I just noticed the post above and tried the following queries:

  1. :echom &filetype consistently returns tex
  2. :echom exists('b:did_sandwich_initex_ftplugin') is giving 1 until I try a reverse-search, and then it gives 0
machakann commented 6 years ago

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?

lervag commented 6 years ago

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?

albertfgu commented 6 years ago

@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"

albertfgu commented 6 years ago

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.

lervag commented 6 years ago

I think you should be able to reproduce from the terminal with

nvr --remote-silent +":100 | silent foldo!" "<filename>"

I.e.:

  1. Open a tex file in neovim
  2. Check &filetype and b:did_sandwhich_initex_ftplugin
  3. Do nvr --remote-silent +":100 | silent foldo!" "<filename>" from the terminal
  4. 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>.

albertfgu commented 6 years ago

I followed the above steps generally; I couldn't understand some of the steps so this is what I did:

  1. Open a tex file with a few lines called temp.tex
  2. :echom &filetype prints tex and :echom exists('b:did_sandwich_initex_ftplugin') prints 1
  3. 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.
  4. Repeating step 2, the filetype is still correct and :echom exists('b:did_sandwich_initex_ftplugin') now prints 0

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()
machakann commented 6 years ago

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.

  1. Put the ~/.config/nvim/init.vim.
filetype plugin indent on
syntax enable
  1. 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
  1. Launch neovim with opening a .tex file
touch ~/temp.tex
nvim ~/temp.tex

At this moment:

  1. Execute :terminal command and exit the terminal buffer immediately
:terminal
exit

Now:


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.

languitar commented 6 years ago

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.

languitar commented 6 years ago

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?

machakann commented 6 years ago

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!

albertfgu commented 6 years ago

Seems to work for me now!

languitar commented 6 years ago

Just looking at your commit: could this happen also with other languages? Seems you have only moved stuff for tex.

machakann commented 6 years ago

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