Not able to hide <# and #> with parameters for clang_snippets=1 with clang_complete - vim

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

Related

Disable autoindent in vim

I use vim since almost 20 years and recently someone told me about the usage of = key for indenting a block of code. Sometimes I try a new vim key but stop using it because it isn't doing exactly what I want or I just don't need the feature. But in this case I find its a nice feature.
So I downloaded vim script 1120 (PHP-correct-Indenting) and installed it. My .vimrc contains:
filetype indent on
set smartindent
Now I can use = to indent a visually marked code block.
But I do NOT want vim to automatically indent code while I am typing. This is just irritating me as I am usually doing indentation myself and I am very much used to it ...
So how can I stop vim from automatically indenting my code while typing but can still continue to use = for indenting a visually marked block of text.
PS: Use hjkl for moving around in vim. It will make you about 1.5 times faster :)
My complete vimrc:
syntax on
set tabstop=3
set shiftwidth=3
execute pathogen#infect()
filetype indent on
set smartindent
Commenting the last two lines stops autoindenting but also using "=" does not use the mentioned vim script anymore
The plugin sets 'indentexpr', which controls both explicit reindenting via = as well as indenting-as-you-type. Fortunately, you can control the triggering of the latter via the 'indentkeys' option, so clearing that should work.
Put the following into ~/.vim/after/indent/php.vim; this way, it'll apply after the plugin:
setlocal indentkeys=
The effect I want can get achieved using:
:set paste
This is exactly(?) the mode I wanted to switch into. No autoindenting at all. But the "=" key works to indent a marked block of text.
Maybe I will add "set paste" to my .vimrc :)
Thanks for your support anyways.

Vim: How to compose search with another command?

I just installed sweet vim plugin that provides context colouring for javascript. I've fiddled with the colours so that they are just right, and am pretty pleased. However, there are times when I don't want the context colouring:
in insert mode, since the colouring doesn't work well while I'm editing
when I'm search, since the colouring seems to override the search hl
I resolved the first problem with:
autocmd InsertEnter *.js :JSContextColorToggle
autocmd InsertLeave *.js :JSContextColorToggle
However, the second problem is trickier. At first I thought I could just map /, my search key, so that it would first toggle the context colouring and then perform the search. I haven't been able to figure out how to write that mapping, though. How would I store "the original meaning of /" for use in my map?
Thanks,
p.s. check out this sweet context colouring (with solarized).
Hi I'm the author of the plugin. I fixed the conflict with hlsearch so it should just work now (try pulling latest version from git, I've not updated vim.org yet..)
As for the insert mode behaviour, there is a difference in behaviour between vim 7.3 and 7.4. 7.4 has the 'TextChanged' and 'TextChangedI' events, which fire when text is changed in normal , and insert mode respectively. This triggers the highlighting to update. However the TextChangedI event only fires on leaving insert mode. So if this is the behaviour you want, you can get it by upgrading to 7.4. In 7.3 I had to hook into the cursormoved event, which checks the 'b:changedtick' variable, which vim updates whenever changes occur... I'm not sure if this can occur during insert mode, but I think it might, which would explain odd behaviour if you're using 7.3.
I'm still trying to figure out what the best behaviour should be in insert mode...its tricky because the code syntax my be invalid during editing, and when the code cannot be parsed the plugin cannot work (and you will see regular syntax highlighting appear.. this may be a good thing as one value of syntax highlighting is visual syntax checking!). Another option would be to assume it is the same level as at the point where editing started, and offset the following text by however many characters are added/deleted during editing. Yet another option would be to have syntax highlighting in the area being edited (current line?) .
/ will enter command-mode.
if you only want to toggle highlighting with /, I think you need map <expr>.
something like
nnoremap <expr> / YourFunction()
in YourFunction(), you first do turn off the syntax hi, then return a /.
However you have to think about when to restore the hi. you can create another command mode mapping, map <cr> to first turn on the js hi, then return <cr>.
or just create an autocmd, when entering Normal mode, turn on the highlighting.
I didn't test above idea, hope it helps.

how to autocomplete options in vim command mode

my setting for command mode completion is:
set wildmenu
set wildmode=longest,list,full
currently when i type
:set fdm=
in command mode, then press tab, manual appended, if i Press tab again , character ^I appended, what i want is manual changed to another foldmethod options such as syntax, indent and so on.
does anyone know is that possible or if there is any plugin could do that ?
thanks !
As you say, when you press <Tab> after :set fdm=, you get manualinserted.
That could seem the usual autocomplete behaviour we are used to in many places, manual being just the first of all possible values. So, you expect that repeating <Tab> will give you more possibilites.
But that's not indeed the case. What you get when pressing <Tab> in such a situation is not the first autocompletion alternative, but the current option value. So, you're getting manual because that's in fact the default value for that option. Successive <Tab>s get inserted literally, as this behaviour is only fired right after =.
From Vim's help:
The old value of an option can be obtained by hitting 'wildchar' just after
the '='. For example, typing 'wildchar' after ":set dir=" will insert the
current value of 'dir'. This overrules file name completion for the options
that take a file name.
So, what you described is expected behaviour. See :help cmdline-completion for the whole story.
I don't know about any plugin capable of changing this to what you want.

Using folds with synmaxcol in 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.

Vim function hints for C

I'm trying to achieve something simple, usually called "function hints". For example, scintilla-based editors have it:
You type a name, and just get the prototype. There are a few problems with that in vim:
You have to rebuild the ctags to keep it up to date
You can't type C-X C-O after the (, you'll just get "Pattern not found"
You can't type C-X C-O in normal mode, the cursor will just jump around
You get the annoying preview window at the top
I've tried a few plugins; most of them mess things up even more [^1].Can anyone recommend a simple way to get just that ? A simple rectangle containing the function prototype and nothing more.
[^1] It's really mind-numbing how idiotic some of these plugins are. One plugin (I won't mention it) actually contained in the .vim file a list of functions from libc.
ctags for autocompletion is a mess. I suggest you try a compiler based plugin such as clang-complete or gcc-sense (haven't tried this one). Advantages are:
more accuracy as what they do is pretty much compiling
compile errors are marked on the fly over the source code
You have to rebuild the ctags to keep it up to date
you don't need to deal with ctags (they are still useful to jump around though)
You can't type C-X C-O after the (, you'll just get "Pattern not found"
what would you expect?
You can't type C-X C-O in normal mode, the cursor will just jump around
you can always remap that sequence if you think it's a frequent mistake (something like nnoremap <C-x><C-o> a<C-x><C-o>)
You get the annoying preview window at the top
You can disable this by removing preview fromcompleteopt option. see :help completeopt
I'm using the following setup:
clang-complete for completion
supertab to complete with tab key
ultisnips for function signature placeholders. (also works with snipmate)
and some vimrc settings:
set pumheight=10 " so the complete menu doesn't get too big
set completeopt=menu,longest " menu, menuone, longest and preview
let g:SuperTabDefaultCompletionType='context'
let g:clang_complete_auto=0 " I can start the autocompletion myself, thanks..
let g:clang_snippets=1 " use a snippet engine for placeholders
let g:clang_snippets_engine='ultisnips'
let g:clang_auto_select=2 " automatically select and insert the first match
Enjoy!
Try to use eclim (plugin for integration with Eclipse).
This solution is overheaded a lot but it works in all cases.

Resources