Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the latex text objects in markdown #1937

Closed
physicophilic opened this issue Jan 31, 2021 · 22 comments
Closed

How to use the latex text objects in markdown #1937

physicophilic opened this issue Jan 31, 2021 · 22 comments

Comments

@physicophilic
Copy link

Issue
I love your text objects, but I tend to work with markdown more often than LaTeX. I would like to use them in markdown.

One option for me would be to create them myself using something like vim-textobj plugin. But, if there's a convenient way to port them from vimtex that would be great. (I suppose some copy pasting might help?)

@lervag
Copy link
Owner

lervag commented Jan 31, 2021

But, if there's a convenient way to port them from vimtex that would be great.

Unfortunately, there is no straightforward way right now. I can see how that would be useful, though.

This could work, I've not tested: In your after/ftplugin/markdown.vim file (or similar), add:

call vimtex#text_obj#init_buffer()

omap <silent><buffer> id <plug>(vimtex-id)
omap <silent><buffer> ad <plug>(vimtex-ad)
xmap <silent><buffer> id <plug>(vimtex-id)
xmap <silent><buffer> ad <plug>(vimtex-ad)
" ...

Let me know if you test this whether it works or not. If it does, then I might add some convenience functionality for easily activate some "Vimtex layers".

@physicophilic
Copy link
Author

I can't get it to work. Each time it says

Error detected while processing function vimtex#text_obj#init_buffer:

with further errors like

E121: Undefined variable: g:vimtex_text_obj_enabled
E121: Undefined variable: g:vimtex_text_obj_enabled
E121: Undefined variable: g:vimtex_text_obj_enabled

What I did

I added these commands to after/ftplugin/markdown.vim and also to after/ftplugin/pandoc.vim since I use vim-pandoc. I also sourced this file after opening a markdown file.

I am using vim 8.1, and here are my vimrc settings for vimtex:

Plug 'lervag/vimtex'
    let g:tex_flavor='latex'
    let g:vimtex_view_method='general' 
    let g:vimtex_quickfix_mode=0   "For Linux
    let g:vimtex_view_method = 'zathura' 
    let g:vimtex_view_general_options = '--unique file:@pdf\#src:@line@tex'
    let g:vimtex_view_general_options_latexmk = '--unique'
    let g:vimtex_compiler_progname = 'nvr'
    let g:vimtex_fold_enabled=1
    let g:vimtex_fold_manual=1

I feel like I am missing something basic to get it work?

@lervag
Copy link
Owner

lervag commented Jan 31, 2021

I'll look more into it myself later, but in the meantime, try to add call vimtex#options#init(). It might solve your issues.

@physicophilic
Copy link
Author

I gues you meant call vimtex#init_options(); using it the delimiter text objects are working. Thanks a lot!

I see these mappings are documented so I can carry forward from here, but yes, please do add info about what other vimtex layers can be made available!

@physicophilic
Copy link
Author

I am SO HAPPY to see that your text-objects work well with vim-operator-surrond! Today seems like a good day!

@lervag
Copy link
Owner

lervag commented Jan 31, 2021

Yes, sorry about the "typo". I'll keep this issue open for now, as I think it seems sensible to allow loading parts of Vimtex at will!

@lervag
Copy link
Owner

lervag commented Jan 31, 2021

I am SO HAPPY to see that your text-objects work well with vim-operator-surrond! Today seems like a good day!

Thanks, I try to implement things in a standard way so it should work with other plugins. Glad to hear you find it useful!

@physicophilic
Copy link
Author

Hi again.

I recently updated to latest vimtex.. and I am facing an issue.

I use context feature of ultisnips and primarily write in markdown.. Earlier I used the following python functions for checking the context.

Click to expand
import vim
texMathZones = ['texMathZone'+x for x in ['A', 'AS', 'B', 'BS', 'C', 'CS', 'D', 'DS', 'E', 'ES', 'F', 'FS', 'G', 'GS', 'H', 'HS', 'I', 'IS', 'J', 'JS', 'K', 'KS', 'L', 'LS', 'DS', 'V', 'W', 'X', 'Y', 'Z']]

texIgnoreMathZones = ['texMathText']

texMathZoneIds = vim.eval('map('+str(texMathZones)+", 'hlID(v:val)')")
texIgnoreMathZoneIds = vim.eval('map('+str(texIgnoreMathZones)+", 'hlID(v:val)')")

ignore = texIgnoreMathZoneIds[0]

def math():
	synstackids = vim.eval("synstack(line('.'), col('.') - (col('.')>=2 ? 1 : 0))")
	try:
		first = next(i for i in reversed(synstackids) if i in texIgnoreMathZoneIds or i in texMathZoneIds)
		return first != ignore
	except StopIteration:
		return False


def notmath():
	synstackids = vim.eval("synstack(line('.'), col('.') - (col('.')>=2 ? 1 : 0))")
	try:
		first = next(i for i in reversed(synstackids) if i in texIgnoreMathZoneIds or i in texMathZoneIds)
		return first == ignore
	except StopIteration:
		return True

After getting the latest version, I see that

def math():
	return vim.eval('vimtex#syntax#in_mathzone()') == '1'

is a replacement which works perfectly for latex... but in markdown, neither this works.. nor does the original. So what can I do?

Like above should I do

call vimtex#syntax#in_marthzone() in the after/markdown.vim?

I also want to know how to add other features of vimtex in markdown....

  • I noticed the conceal has become awesome (or was it always that way?) .... referring to how if a concealling glyph is available the latex objects get concealed, but if not then the full code is visible..

  • With treesitter whenever I make a syntax error all lines get underlined in my theme.. but this doesn't happen in markdown... so I guess you did something to make this happen?

I tried going back to v. 1.6 which partly did the job, but I think there might be a better fix!

Thanks a lot!

@lervag
Copy link
Owner

lervag commented May 11, 2021

I recently updated to latest vimtex.. and I am facing an issue.

After getting the latest version, I see that

def math():
	return vim.eval('vimtex#syntax#in_mathzone()') == '1'

is a replacement which works perfectly for latex... but in markdown, neither this works.. nor does the original. So what can I do?

It would be convenient with a simple, but explicit example for me to test. Perhaps it is simply a bug? At least, on my end, it seems to work. I do this:

  1. Create the UltiSnips/markdown.snippets file and add the following code:

    global !p
    def math():
    	return vim.eval('vimtex#syntax#in_mathzone()') == '1'
    endglobal
    
    context "math()"
    snippet ,ff "Fraction" iA
    \frac{${1:numer}}{${2:denom}}${0}
    endsnippet
    
  2. Open a Markdown document, type i$,ff. It expands as expected into \frac{numer}{denom}.

I noticed the conceal has become awesome (or was it always that way?) .... referring to how if a concealling glyph is available the latex objects get concealed, but if not then the full code is visible..

If you like conceals, then yes, I think the updates after VimTeX v2.0 brings some improvements. It is, though, unclear what you find lacking in Markdown here. I think most of it should work well also for LaTeX syntax within Markdown.

Perhaps you simply do not have set conceallevel=2?

With treesitter whenever I make a syntax error all lines get underlined in my theme.. but this doesn't happen in markdown... so I guess you did something to make this happen?

I have no idea. VimTeX does not utilize treesitter, so I think this must be from e.g. your language server or something similar.

@physicophilic
Copy link
Author

It appears I was mistaken. I can't reproduce what I claimed now.

While the original python functions do not work now, (I don't mind)

global !p
def math():
	return vim.eval('vimtex#syntax#in_mathzone()') == '1'
endglobal

does work for both markdown and latex.

It may be because yesterday I simplified my config file and switched to using packer from using git submodules. I should have checked again thoroughly before asking you. If I see some problem with this later I will let you know. Sorry about it.

Conceal

It is as you say. Now that vimtex#syntax#in_mathzone() is being loaded, conceallevel=2 also makes behaviour of latex conceal in .tex and .md identical.

Syntax error

I see, thank you. Although I don't use LSP for tex, some other plugin must be responsible.

Here's a snapshot just in case you want to look at it:

Click

underlined-error
where I've disabled conceal to show the code. Works only inside \begin{env} \end{env}

@lervag
Copy link
Owner

lervag commented May 12, 2021

It appears I was mistaken. I can't reproduce what I claimed now.
...
It may be because yesterday I simplified my config file and switched to using packer from using git submodules. I should have checked again thoroughly before asking you. If I see some problem with this later I will let you know. Sorry about it.

No problem. :)

I see, thank you. Although I don't use LSP for tex, some other plugin must be responsible.

I'm sorry to say I don't know what causes this. If not an LSP, then perhaps it is ALE? Or Syntastic?


I'm still keeping the issue open as indicated earlier. Note to self: It should be possible to allow loading parts of VimTeX manually.

@clason
Copy link
Contributor

clason commented May 12, 2021

You might be seeing nvim-treesitter/nvim-treesitter@efbb1c6

Can you update nvim-treesitter (and neovim) and try again?

Also, I should point out that using nvim-treesitter's latex parser will disable VimTeX's syntax-based highlighting. So any errors with highlighting are tree-sitter issues and not at all related to vimtex.

@hermanmakhm
Copy link

hermanmakhm commented Dec 23, 2021

I seem to be having the same problem with getting context "math()" snippets on markdown. Firstly, I'm not entirely sure what to put in vimtex/after/ftplugin/markdown.vim to make this work. It seems that adding call vimtex#init_options() even after the line call vimtex#init() gives E117: Unknown function: vimtex#init_options and none of the text object lines seem to change anything (I don't know what they are, I just tried adding them).

More importantly, when I try load the following into .vim/UltiSnips/markdown.snippets

global !p
def math():
	return vim.eval('vimtex#syntax#in_mathzone()') == '1'
endglobal

context "math()"
snippet ,ff "Fraction" iA
\frac{${1:numer}}{${2:denom}}${0}
endsnippet

snippet ,fp "Fraction" iA
\frac{\partial ${1:numer}}{\partial ${2:denom}}${0}
endsnippet

typing i,fp or i$,fp works for the second snippet but typing i$,ff or even closing the $ signs before typing ,ff don't seem to work for it to recognise the math context. I'm trying to get this to work with https://github.com/gillescastel/latex-snippets and working with .md files for Obsidian, if you want a more solid example of what I'm trying to do.

Below is my .vimrc for vimtex and ultisnips

Plug 'lervag/vimtex'
	let g:vimtex_view_general_viewer = 'okular'
	let g:vimtex_view_general_options
		\ = ' -forward-search @tex @line @pdf'
		\ . ' -inverse-search "gvim --servername ' . v:servername
		\ . ' --remote-send \"^<C-\^>^<C-n^>'
		\ . ':drop \%f^<CR^>:\%l^<CR^>:normal\! zzzv^<CR^>'
		\ . ':execute ''drop '' . fnameescape(''\%f'')^<CR^>'
		\ . ':\%l^<CR^>:normal\! zzzv^<CR^>'
		\ . ':call remote_foreground('''.v:servername.''')^<CR^>^<CR^>\""'
	let g:tex_flavor='latex'
	let g:vimtex_quickfix_mode=1
	set conceallevel=1
	let g:tex_conceal='abdmg'
	let g:vimtex_compiler_latexmk = {
            \ 'build_dir' : 'build',
            \}
"
" " Make sure you use single quotes
"
" " Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
" Plug 'junegunn/vim-easy-align'
"
" " Any valid git URL is allowed
" Plug 'https://github.com/junegunn/vim-github-dashboard.git'
"
" " Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
    let g:UltiSnipsExpandTrigger = '<tab>'
    let g:UltiSnipsJumpForwardTrigger = '<tab>'
    let g:UltiSnipsJumpBackwardTrigger = '<s-tab>'

I apologise if I take a while to respond/test as it is Christmas and I will not have access to my work computer to test anything.

@lervag
Copy link
Owner

lervag commented Dec 27, 2021

Firstly, I'm not entirely sure what to put in vimtex/after/ftplugin/markdown.vim to make this work. It seems that adding call vimtex#init_options() even after the line call vimtex#init() gives E117: Unknown function: vimtex#init_options and none of the text object lines seem to change anything (I don't know what they are, I just tried adding them).

Since the first comments in this post (which are quite old now), there's been a bunch of updates. In particular, the options initializer is now called vimtex#options#init(). Thus, to enable text objects, you would put something like this in the after/ftplugin/markdown.vim:

call vimtex#options#init()
call vimtex#text_obj#init_buffer()

omap <silent><buffer> id <plug>(vimtex-id)
omap <silent><buffer> ad <plug>(vimtex-ad)
xmap <silent><buffer> id <plug>(vimtex-id)
xmap <silent><buffer> ad <plug>(vimtex-ad)
" ... (add more maps if you want)

More importantly, when I try load the following into .vim/UltiSnips/markdown.snippets

Are you using Tree-sitter? If so, then this will not work regardless. If you are not using Tree-sitter, then I think it should work.

Below is my .vimrc for vimtex and ultisnips

Below is my adjusted version which is equivalent to yours, but more condensed.

Plug 'lervag/vimtex'

let g:vimtex_view_general_viewer = 'okular'
let g:vimtex_view_general_options = '--unique file:@pdf\#src:@line@tex'
let g:vimtex_view_general_options_latexmk = '--unique'
let g:vimtex_quickfix_mode = 1
let g:vimtex_compiler_latexmk = {'build_dir' : 'build'}

" You should not mix Vim options with plugin config - conceallevel is a local
" option and setting it in your vimrc will only set it in the first window.
set conceallevel=1

I notice you have a very advanced configuration for Okular. But I doubt it works - if it does, can you please give me the reference for where you discovered this? I've used the suggested settings from :help vimtex-view-okular above; see also the same help docs for how to configure inverse search.

@jfab20
Copy link

jfab20 commented Apr 27, 2022

@lervag I have put in after/ftplugin/markdown.vim the line call vimtex#init() to initialize all of vimtex inside my .md files. Some mappings seems to work, for example the text object im works perfectly and I can change perfectly everything inside dollar signs. However some objects are missing and it seems they were not mapped when vimtex has called.

For example, I cannot do cse inside an environment, the mapping does not exist. Should I add the maps manually?

@lervag
Copy link
Owner

lervag commented Apr 28, 2022

Yes. I added a mechanism to prevent VimTeX from loading all the default maps if you load vimtex in "unsupported" filetypes (e.g. Markdown):

vimtex/autoload/vimtex.vim

Lines 370 to 372 in 5db1150

if (a:ftype == 0
\ || a:ftype == 1 && &filetype ==# 'tex'
\ || a:ftype == 2 && &filetype ==# 'bib')

Thus, you have to manually map the keys you want. E.g., in your after/ftplugin/markdown.vim:

call vimtex#init()

nmap <silent><buffer><nowait> cse <plug>(vimtex-env-change)
nmap <silent><buffer><nowait> dse <plug>(vimtex-env-delete)

It should be quite easy to determine which maps you want from looking at the code, here:

vimtex/autoload/vimtex.vim

Lines 121 to 307 in 5db1150

function! s:init_default_mappings() abort " {{{1
if !g:vimtex_mappings_enabled | return | endif
call s:map(0, 'n', '<localleader>li', '<plug>(vimtex-info)')
call s:map(0, 'n', '<localleader>lI', '<plug>(vimtex-info-full)')
call s:map(0, 'n', '<localleader>lx', '<plug>(vimtex-reload)')
call s:map(0, 'n', '<localleader>lX', '<plug>(vimtex-reload-state)')
call s:map(1, 'n', '<localleader>ls', '<plug>(vimtex-toggle-main)')
call s:map(0, 'n', '<localleader>lq', '<plug>(vimtex-log)')
call s:map(1, 'n', '<localleader>la', '<plug>(vimtex-context-menu)')
call s:map(1, 'n', 'ds$', '<plug>(vimtex-env-delete-math)')
call s:map(1, 'n', 'cs$', '<plug>(vimtex-env-change-math)')
call s:map(1, 'n', 'dse', '<plug>(vimtex-env-delete)')
call s:map(1, 'n', 'cse', '<plug>(vimtex-env-change)')
call s:map(1, 'n', 'tse', '<plug>(vimtex-env-toggle-star)')
call s:map(1, 'n', 'ts$', '<plug>(vimtex-env-toggle-math)')
call s:map(0, 'n', 'dsc', '<plug>(vimtex-cmd-delete)')
call s:map(0, 'n', 'csc', '<plug>(vimtex-cmd-change)')
call s:map(1, 'n', 'tsc', '<plug>(vimtex-cmd-toggle-star)')
call s:map(1, 'n', 'tsf', '<plug>(vimtex-cmd-toggle-frac)')
call s:map(1, 'x', 'tsf', '<plug>(vimtex-cmd-toggle-frac)')
call s:map(0, 'i', '<F7>', '<plug>(vimtex-cmd-create)')
call s:map(0, 'n', '<F7>', '<plug>(vimtex-cmd-create)')
call s:map(0, 'x', '<F7>', '<plug>(vimtex-cmd-create)')
call s:map(1, 'n', 'dsd', '<plug>(vimtex-delim-delete)')
call s:map(1, 'n', 'csd', '<plug>(vimtex-delim-change-math)')
call s:map(1, 'n', 'tsd', '<plug>(vimtex-delim-toggle-modifier)')
call s:map(1, 'x', 'tsd', '<plug>(vimtex-delim-toggle-modifier)')
call s:map(1, 'n', 'tsD', '<plug>(vimtex-delim-toggle-modifier-reverse)')
call s:map(1, 'x', 'tsD', '<plug>(vimtex-delim-toggle-modifier-reverse)')
call s:map(1, 'i', ']]', '<plug>(vimtex-delim-close)')
call s:map(1, 'n', '<F8>', '<plug>(vimtex-delim-add-modifiers)')
if g:vimtex_compiler_enabled
call s:map(0, 'n', '<localleader>ll', '<plug>(vimtex-compile)')
call s:map(0, 'n', '<localleader>lo', '<plug>(vimtex-compile-output)')
call s:map(1, 'n', '<localleader>lL', '<plug>(vimtex-compile-selected)')
call s:map(1, 'x', '<localleader>lL', '<plug>(vimtex-compile-selected)')
call s:map(0, 'n', '<localleader>lk', '<plug>(vimtex-stop)')
call s:map(0, 'n', '<localleader>lK', '<plug>(vimtex-stop-all)')
call s:map(0, 'n', '<localleader>le', '<plug>(vimtex-errors)')
call s:map(0, 'n', '<localleader>lc', '<plug>(vimtex-clean)')
call s:map(0, 'n', '<localleader>lC', '<plug>(vimtex-clean-full)')
call s:map(0, 'n', '<localleader>lg', '<plug>(vimtex-status)')
call s:map(0, 'n', '<localleader>lG', '<plug>(vimtex-status-all)')
endif
if g:vimtex_motion_enabled
" These are forced in order to overwrite matchit mappings
call s:map(0, 'n', '%', '<plug>(vimtex-%)', 1)
call s:map(0, 'x', '%', '<plug>(vimtex-%)', 1)
call s:map(0, 'o', '%', '<plug>(vimtex-%)', 1)
call s:map(1, 'n', ']]', '<plug>(vimtex-]])')
call s:map(1, 'n', '][', '<plug>(vimtex-][)')
call s:map(1, 'n', '[]', '<plug>(vimtex-[])')
call s:map(1, 'n', '[[', '<plug>(vimtex-[[)')
call s:map(1, 'x', ']]', '<plug>(vimtex-]])')
call s:map(1, 'x', '][', '<plug>(vimtex-][)')
call s:map(1, 'x', '[]', '<plug>(vimtex-[])')
call s:map(1, 'x', '[[', '<plug>(vimtex-[[)')
call s:map(1, 'o', ']]', '<plug>(vimtex-]])')
call s:map(1, 'o', '][', '<plug>(vimtex-][)')
call s:map(1, 'o', '[]', '<plug>(vimtex-[])')
call s:map(1, 'o', '[[', '<plug>(vimtex-[[)')
call s:map(1, 'n', ']M', '<plug>(vimtex-]M)')
call s:map(1, 'n', ']m', '<plug>(vimtex-]m)')
call s:map(1, 'n', '[M', '<plug>(vimtex-[M)')
call s:map(1, 'n', '[m', '<plug>(vimtex-[m)')
call s:map(1, 'x', ']M', '<plug>(vimtex-]M)')
call s:map(1, 'x', ']m', '<plug>(vimtex-]m)')
call s:map(1, 'x', '[M', '<plug>(vimtex-[M)')
call s:map(1, 'x', '[m', '<plug>(vimtex-[m)')
call s:map(1, 'o', ']M', '<plug>(vimtex-]M)')
call s:map(1, 'o', ']m', '<plug>(vimtex-]m)')
call s:map(1, 'o', '[M', '<plug>(vimtex-[M)')
call s:map(1, 'o', '[m', '<plug>(vimtex-[m)')
call s:map(1, 'n', ']N', '<plug>(vimtex-]N)')
call s:map(1, 'n', ']n', '<plug>(vimtex-]n)')
call s:map(1, 'n', '[N', '<plug>(vimtex-[N)')
call s:map(1, 'n', '[n', '<plug>(vimtex-[n)')
call s:map(1, 'x', ']N', '<plug>(vimtex-]N)')
call s:map(1, 'x', ']n', '<plug>(vimtex-]n)')
call s:map(1, 'x', '[N', '<plug>(vimtex-[N)')
call s:map(1, 'x', '[n', '<plug>(vimtex-[n)')
call s:map(1, 'o', ']N', '<plug>(vimtex-]N)')
call s:map(1, 'o', ']n', '<plug>(vimtex-]n)')
call s:map(1, 'o', '[N', '<plug>(vimtex-[N)')
call s:map(1, 'o', '[n', '<plug>(vimtex-[n)')
call s:map(1, 'n', ']R', '<plug>(vimtex-]R)')
call s:map(1, 'n', ']r', '<plug>(vimtex-]r)')
call s:map(1, 'n', '[R', '<plug>(vimtex-[R)')
call s:map(1, 'n', '[r', '<plug>(vimtex-[r)')
call s:map(1, 'x', ']R', '<plug>(vimtex-]R)')
call s:map(1, 'x', ']r', '<plug>(vimtex-]r)')
call s:map(1, 'x', '[R', '<plug>(vimtex-[R)')
call s:map(1, 'x', '[r', '<plug>(vimtex-[r)')
call s:map(1, 'o', ']R', '<plug>(vimtex-]R)')
call s:map(1, 'o', ']r', '<plug>(vimtex-]r)')
call s:map(1, 'o', '[R', '<plug>(vimtex-[R)')
call s:map(1, 'o', '[r', '<plug>(vimtex-[r)')
call s:map(1, 'n', ']/', '<plug>(vimtex-]/)')
call s:map(1, 'n', ']*', '<plug>(vimtex-]*)')
call s:map(1, 'n', '[/', '<plug>(vimtex-[/)')
call s:map(1, 'n', '[*', '<plug>(vimtex-[*)')
call s:map(1, 'x', ']/', '<plug>(vimtex-]/)')
call s:map(1, 'x', ']*', '<plug>(vimtex-]*)')
call s:map(1, 'x', '[/', '<plug>(vimtex-[/)')
call s:map(1, 'x', '[*', '<plug>(vimtex-[*)')
call s:map(1, 'o', ']/', '<plug>(vimtex-]/)')
call s:map(1, 'o', ']*', '<plug>(vimtex-]*)')
call s:map(1, 'o', '[/', '<plug>(vimtex-[/)')
call s:map(1, 'o', '[*', '<plug>(vimtex-[*)')
endif
if g:vimtex_text_obj_enabled
call s:map(0, 'x', 'id', '<plug>(vimtex-id)')
call s:map(0, 'x', 'ad', '<plug>(vimtex-ad)')
call s:map(0, 'o', 'id', '<plug>(vimtex-id)')
call s:map(0, 'o', 'ad', '<plug>(vimtex-ad)')
call s:map(0, 'x', 'i$', '<plug>(vimtex-i$)')
call s:map(0, 'x', 'a$', '<plug>(vimtex-a$)')
call s:map(0, 'o', 'i$', '<plug>(vimtex-i$)')
call s:map(0, 'o', 'a$', '<plug>(vimtex-a$)')
call s:map(1, 'x', 'iP', '<plug>(vimtex-iP)')
call s:map(1, 'x', 'aP', '<plug>(vimtex-aP)')
call s:map(1, 'o', 'iP', '<plug>(vimtex-iP)')
call s:map(1, 'o', 'aP', '<plug>(vimtex-aP)')
call s:map(1, 'x', 'im', '<plug>(vimtex-im)')
call s:map(1, 'x', 'am', '<plug>(vimtex-am)')
call s:map(1, 'o', 'im', '<plug>(vimtex-im)')
call s:map(1, 'o', 'am', '<plug>(vimtex-am)')
if vimtex#text_obj#targets#enabled()
call vimtex#text_obj#targets#init()
" These are handled explicitly to avoid conflict with gitgutter
call s:map(0, 'x', 'ic', '<plug>(vimtex-targets-i)c')
call s:map(0, 'x', 'ac', '<plug>(vimtex-targets-a)c')
call s:map(0, 'o', 'ic', '<plug>(vimtex-targets-i)c')
call s:map(0, 'o', 'ac', '<plug>(vimtex-targets-a)c')
else
if g:vimtex_text_obj_variant ==# 'targets'
call vimtex#log#warning(
\ "Ignoring g:vimtex_text_obj_variant = 'targets'"
\ . " because 'g:loaded_targets' does not exist or is 0.")
endif
let g:vimtex_text_obj_variant = 'vimtex'
call s:map(1, 'x', 'ie', '<plug>(vimtex-ie)')
call s:map(1, 'x', 'ae', '<plug>(vimtex-ae)')
call s:map(1, 'o', 'ie', '<plug>(vimtex-ie)')
call s:map(1, 'o', 'ae', '<plug>(vimtex-ae)')
call s:map(0, 'x', 'ic', '<plug>(vimtex-ic)')
call s:map(0, 'x', 'ac', '<plug>(vimtex-ac)')
call s:map(0, 'o', 'ic', '<plug>(vimtex-ic)')
call s:map(0, 'o', 'ac', '<plug>(vimtex-ac)')
endif
endif
if g:vimtex_toc_enabled
call s:map(0, 'n', '<localleader>lt', '<plug>(vimtex-toc-open)')
call s:map(0, 'n', '<localleader>lT', '<plug>(vimtex-toc-toggle)')
endif
if has_key(b:vimtex, 'viewer')
call s:map(0, 'n', '<localleader>lv', '<plug>(vimtex-view)')
if !empty(maparg('<plug>(vimtex-reverse-search)', 'n'))
call s:map(0, 'n', '<localleader>lr', '<plug>(vimtex-reverse-search)')
endif
endif
if g:vimtex_imaps_enabled
call s:map(0, 'n', '<localleader>lm', '<plug>(vimtex-imaps-list)')
endif
if g:vimtex_doc_enabled
call s:map(0,'n', 'K', '<plug>(vimtex-doc-package)')
endif
endfunction

@lervag
Copy link
Owner

lervag commented Apr 28, 2022

By the way, I've decided to close this issue. I don't see directly how to proceed to improve here.

If anyone feels strongly on this topic that there should be further development, then it would be very helpful with a new issue:

  • Describe clearly and explicitly what you want.
  • Include a minimal example! Sample documents and similar, indication on which type of configuration you expect.

@lervag lervag closed this as completed Apr 28, 2022
@jfab20
Copy link

jfab20 commented Apr 28, 2022

Yes. I added a mechanism to prevent VimTeX from loading all the default maps if you load vimtex in "unsupported" filetypes (e.g. Markdown):

Why is that behaviour desirable? First, there are some mappings which are loaded. As I said you can do ca$ or di$ in a markdown document, so some text objects are available, but not all. Is there a good reason of why you wouldn't want all mappings enabled?

lervag added a commit that referenced this issue Apr 28, 2022
@lervag
Copy link
Owner

lervag commented Apr 28, 2022

The reasoning is that some of the maps do not make much sense in a context that is not "fully TeX". The relevant changes were made for #1517, where I added more support for editing within bibtex files.

I'll not claim that the selection of maps is optimal. There may be several maps that we could and should safely allow for any buffer where we load vimtex (perhaps also for bib files). I've pushed an update where I've reevaluated the mappings. Let me know what you think.

@jfab20
Copy link

jfab20 commented Apr 28, 2022

Let me know what you think.

Excellent!

@Freed-Wu
Copy link
Contributor

Freed-Wu commented Apr 6, 2023

Comes from #1623. I use vimtex in markdown and pandoc by the following code:

let s:comments = &l:comments
let s:commentstring = &l:commentstring
call vimtex#init()
let &l:comments = s:comments
let &l:commentstring = s:commentstring

It allows me to use vimtex's hotkeys, conceal, ... Maybe helpful for others.

Because vimtex#init() will change &commentstring, &comments, I write some dirty wrap. Can we add a condition in https://github.com/lervag/vimtex/blob/master/autoload/vimtex.vim#L64-L65 to only set them when &filetype = tex? Thanks!

lervag added a commit that referenced this issue Apr 6, 2023
@lervag
Copy link
Owner

lervag commented Apr 6, 2023

Good point. I've refactored slightly and made the changes as suggested by you here. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants