-
Notifications
You must be signed in to change notification settings - Fork 389
-
Notifications
You must be signed in to change notification settings - Fork 389
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
Comments
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 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". |
I can't get it to work. Each time it says
with further errors like
What I did I added these commands to I am using vim 8.1, and here are my vimrc settings for vimtex:
I feel like I am missing something basic to get it work? |
I'll look more into it myself later, but in the meantime, try to add |
I gues you meant 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! |
I am SO HAPPY to see that your text-objects work well with vim-operator-surrond! Today seems like a good day! |
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! |
Thanks, I try to implement things in a standard way so it should work with other plugins. Glad to hear you find it useful! |
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 expandimport 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
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
I also want to know how to add other features of vimtex in markdown....
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! |
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:
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
I have no idea. VimTeX does not utilize treesitter, so I think this must be from e.g. your language server or something similar. |
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)
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 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: |
No problem. :)
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. |
You might be seeing nvim-treesitter/nvim-treesitter@efbb1c6 Can you update 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. |
I seem to be having the same problem with getting More importantly, when I try load the following into
typing Below is my 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. |
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 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)
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 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 |
@lervag I have put in For example, I cannot do |
Yes. I added a mechanism to prevent VimTeX from loading all the default maps if you load vimtex in "unsupported" filetypes (e.g. Markdown): Lines 370 to 372 in 5db1150
Thus, you have to manually map the keys you want. E.g., in your 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: Lines 121 to 307 in 5db1150
|
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:
|
Why is that behaviour desirable? First, there are some mappings which are loaded. As I said you can do |
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. |
Excellent! |
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 |
Good point. I've refactored slightly and made the changes as suggested by you here. Thanks! |
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?)
The text was updated successfully, but these errors were encountered: