I want to set let g:tex_conceal="" to disable mathematical symbols appearing instead of original text in a .tex file (as described here) in my .vimrc.
This setting is not working if I do it inside a function like
function! New_function()
let g:tex_conceal=""
endfunction
autocmd BufReadPost,BufNewFile *.tex, call New_function()
Why is it not working? Other things I do inside a function are working correctly except this.
Also, these math symbols do not expand even if the cursor is over them in both normal and insert mode.
I am not using any latex related plugins.
Related
I think I might have possibly seen some similar questions on here, but I don't really have anything that answers the question, in a way that I understand. I'm somewhat new to using Vim, so I don't really have much understanding of it's true potential (beyond knowing it is almost limitless). Basically, I have some custom syntax that I want to enable when I open a particular file in Vim. For the purposes of making sure that I don't mess up the implementation of the answer, I'll post the commands in here.
:syntax region Topic start="{==" end="==}"
:syntax region Symbol start="<" end=">"
:highlight Topic guifg=#abcdef
:highlight Symbol guifg=#fedcba
I can probably guess that giving people guidance to have them figure out the exact answer with a short hop or two is optimal, but I am somewhat frustrated at having to run this particular command every single time I start the file in question. If possible, what could I put, and where would I put, a certain series of characters that would result in not having to type these commands every time I open it?
Apologies if this is a dupe, I just haven't found any answers that I have understood as answers.
I think putting the vim commands inside a function and calling that function via using augroup might work.
Define the function in your .vimrc as:
function! Syntax_Highlighter()
syntax region Topic start="{==" end="==}"
syntax region Symbol start="<" end=">"
highlight Topic guifg=#abcdef
highlight Symbol guifg=#fedcba
endfunction
And then again in your .vimrc, by using augroup command call the above function:
augroup highlighter
au!
au BufNewFile *.html call Syntax_Highlighter()
augroup END
In above snippet, change *.html with whichever file extension you want to.
EDIT :
METHOD 2 :
If you want to custom map a key combination to perform those commands then rather than using augroup you may use autocmd.
autocmd FileType html map ,l :call Syntax_Highlighter()<cr>
This will map the key combination , followed by l to calling the Syntax_Highlighter function only when the current file is having html extension.
Here also, replace html with the required file extension.
In the first method, the function will be called whenever you open a new file with the appropriate extension. In second method, the function will be called only when you pressed the key combination inside the file which has appropriate extension.
I started using a plugin that conflicts with my existing maps, but instead of remapping all of it's maps, I just want to add a prefix. I thought I'd be able to do this with LocalLeader.
Vimdoc says:
<LocalLeader> is just like <Leader>, except that it uses
"maplocalleader" instead of "mapleader". <LocalLeader> is to be used
for mappings which are local to a buffer.
It seems that the only way to set localleader is to set a global variable (the docs don't mention this, but b:maplocalleader didn't work):
let maplocalleader = '\\'
And I don't see how I'd cleanly unset that variable (an autocmd that clears it after plugins are setup!?)
Is there a way to do this? Or is LocalLeader only to give one global prefix and one filetype-specific prefix?
Your last hunch is correct. If the plugin uses <Leader> (and it should unless it's a filetype plugin), there's no use in messing with maplocalleader.
Remapping is canonically done via <Plug> mappings, which the plugin hopefully offers. Some plugins do define a lot of similar mappings, some of those define a g:pluginname_mappingprefix (or so) variable to save you from having to remap all mappings individually. If your plugin doesn't, maybe write a suggestion / patch to the plugin author.
While #IngoKarkat solution is a prefered one, there is a hack which lets you do what you want: the SourcePre event:
autocmd SourcePre * :let maplocalleader='\\'
autocmd SourcePre plugin-name.vim :let maplocalleader='_'
. This works for <Leader> as well. There are lots of cases when this won’t work though. You can as well use SourceCmd for this job, using something like
function s:Source(newmll)
try
let oldmll=g:maplocalleader
let g:maplocalleader=a:newmll
source <amatch>
finally
let g:maplocalleader=oldmll
endtry
endfunction
let maplocalleader='\\'
autocmd SourceCmd plugin-name.vim :call s:Source('_')
in SourceCmd is the only way I see to restore maplocalleader after plugin was sourced, but SourceCmd event here won’t be launched for any file sourced inside plugin-name.vim. For some poorly written plugins (I mean, those that emit errors while sources) putting :source inside a :try block will break execution at the point where error occurs. Should not happen most of time though. You may also want to use */ftplugin/plugin-name.vim as a pattern instead of plugin-name.vim.
Sometimes when I'm working on a project I want to play around with some data. Often times the data is on one line and is huge (>25k characters). I understand I could set nowrap and have this line just run off the screen, but I tend to like set wrap for other reasons. So, as a workaround I want to hide these long lines in a marker fold (e.g. {{{ long line }}}). This works fine but I run into a problem with synmaxcol for some reason. If the folded line exceeds synmaxcol then when I open the file, the syntax highlighting runs over. For example:
However, as soon as I open the fold the syntax corrects itself:
Having to open the fold every time is annoying though. As you can see in this example the line is not actually all that long -- it just exceeds synmaxcol. Since synmaxcol is exceeded at a "string" element, the rest of the file is highlighted as a string (so nothing but a singular double quote will stop it).
Why is this happening and how can I fix it? I've tried this with different syntax files and filetypes and it still occurs. I've also tried it with no plugins, a minimal vimrc (containing only syn on) and a modeline to set fdm=marker:synmaxcol=60 and it still happens.
You can manually enter :syntax sync fromstart to force Vim to rescan the syntax from the beginning of the opened file.
I would suggest defining a hotkey for convenience:
noremap <F5> <Esc>:syntax sync fromstart<CR>
inoremap <F5> <C-o>:syntax sync fromstart<CR>
Now you can press F5 to clean up most syntax highlighting problems.
Also, have a look at Vim's fixing syntax highlighting - wiki page
Moreover reading :help :syn-sync-first might shed some more light on the issue.
UPDATE:
I was able to reproduce this behavior on my machine (I'm running Vim 7.3.429).
However, when I wrapped the fold markers {{{ and }}} in block comments, vim correctly rendered the syntax. You can create appropriately wrapped fold-markers using the zf command. See Vim tips: Folding fun.
Normally Vim picks the correct blockcomment string based on the currently active syntax. However, my Vim is pretty vanilla and didn't recognize Ruby syntax. I could specify autocmd FileType ruby set commentstring==begin%s=end in my .vimrc file to set the proper block comment. See :fold-create-marker for more details.
Another solution is to set synmaxcol=0, which will effectively set it to infinity. This causes Vim to check the syntax of the entire line, no matter how long it is. However, I'm not sure what kind of performance penalty you'll have to pay for that.
I've set this on my .vimrc:
let g:clang_snippets=1
let g:clang_snippets_engine='clang_complete'
let g:clang_conceal_snippets=1
set conceallevel=2 concealcursor=inv
I don't know how conceal is expected to work, maybe the clang_complete's docs should have a tip for a specific setting to hide the snippets adorns.
How do I hide it? I'm using MacVim built with +conceal, but it's not working. This is my messy .vimrc by now.
NOTE:
I'm sticking with g:clang_snippets_engine='clang_complete' because it seems to be more smart than the snipMate parameter completion, switching to NORMAL mode is a wiser choice to navigate between parameters since I can use SuperTab completion for params in INSERT mode while being able to navigate through them with the same tab at NORMAL mode. snipMate engine was acting weird to me sometimes too, sometimes it switched to a parameter after a completion, sometimes not.
Also, I'm missing a final tab to go after the last parameter, right after the function call (snipMate does that), so I can just insert ; and hit Enter.
Disclaimer: This question is related with the issue at https://github.com/Rip-Rip/clang_complete/issues/176.
EDIT:
My problem was with this line at my .vimrc:
au BufNewFile,BufRead *.cpp set syntax=cpp11
I'm using C++11 Syntax Support and #xaizek has discovered and pointed it out as the problem in the comments bellow in the accepted response, it seems the root cause is the use of the syntax clear command in it.
According to :help 'concealcursor':
Sets the modes in which text in the cursor line can also be concealed.
When the current mode is listed then concealing happens just like in
other lines.
n Normal mode
v Visual mode
i Insert mode
c Command line editing, for 'incsearch'
So with concealcursor=iv you asked Vim to hide concealed text in insert and visual modes, but show it in normal mode. So just do:
:set concealcursor=inv
How can you open the following PATH by ctrl-w-f to a new window?
Path
/usr/masi/codes/11
The PATH refers to a file 11.tex.
I need to use 11 instead of 11.tex
because my LaTeX or pdflatex does not understand PATHs with tex
when I input/include the file.
Possible solutions are
to add something to .vimrc
to use perhaps differently pdflatex
In Vim 7.2, you can set the suffixesadd to .txt as below:
:set suffixesadd=.tex,.latex,.java
see :help suffixesadd
It seems you'll need to override CTRL-W_f to add a extension.
For instance, you could add the following in a tex-ftplugin:
nnoremap <buffer> <c-w>f :exe ':sp '.globpath('.', expand('<cfile>').'.*')<cr>
NB: this mapping is far from perfection. It's still need to glob on , and .*, to keep only one file (or none) if several match. And to support the no-match case.
I don't know about latex to answer from its side, but I don't see a setting to make Vim look for the path with extensions, so you will have to create a custom mapping. Unfortunately, there are no command-line equivalents to the gf and f style of commands, so you have to mimic something equivalent (sorry, untested).
function! OpenFile()
try
exec "normal! \<C-W>f"
except
if filereadable(expand('<cfile>').'.tex')
split <cfile>.tex
endif
endtry
endfunction
nnoremap <silent> <C-W>f :call OpenFile()<CR>
You can put this in an ftplugin (with option for nnoremap) to restrict it to your latex files only.
Note: If you want to cover different cases such as gf, F, you will need a more sophisticated function, or just write different functions for each.
I use vim 7.2 and it really works with default settings. If i understand the problem well.
It works with soft link and hard link both.