vim parenthesis matching only while typing - vim

In emacs, as you type, it will show you the matching parentheses, but there is a separate setting to highlight matching parentheses that the cursor is on. Is there something I can write in .vimrc to make this happen? Everything I've found completely turns off parenthesis matching, which is not quite what I want.
Thanks for any help!
EDIT: Addressing the comment about a possible duplicate, that answer explains how to turn on what I want to turn off. I want paren matching as I type, but I don't want highlighting when my cursor is on a parenthesis. Thanks!

" Briefly jump to the matching bracket when typing
set showmatch
" Turn off the default matchparen plugin (on demand):
NoMatchParen
" Alternatively (in your .vimrc, to completely disable the plugin):
let loaded_matchparen = 1

Related

remove the highlight for the current parenthesis but keep it for the matching pair

When I work in a fast paced with vim, one of the recurring annoyance is highlighting of {} or {} or []. When the parenthesis or brackets are adjacent to each other, it takes me a second (yes a whole second!) to figure out where the focus is. I do not like having to rely on the blinking and I still want the matching paren/bracket to be highlighted. So how can I remove just the highlighting for the current paren/bracket?
:hi MatchParen ctermbg=black guibg=black
show match is ok, but the highlight was driving me nutz. The above turns the highight black so you don't see it when editor has a black background
:NoMatchParen
type :help matchparen for more help on this .
this functionnality is really useful for me, so maybe you can look at the doc a little and find a way to hightlight the matching pair in a different color (or just underline it for example)
What you are looking is
set noshowmatch
to be set in vimrc

How to make words invisible in vim?

In vimwiki, I can input a link like this:
[[link]]
When I put cursor on the line, [[]] is visible:
>[[http://www.google.com/]]<
When the cursor is moved away, [[]] is invisible:
>http://www.google.com/<
I notice this behavior in vim's help manual(:help vim): *vim:*(*s are invisible until I type V).
I cannot figure out how it works. Thanks for your help.
This is a feature called "conceal" that was added in vim 7.3 (if I recall correctly). For a simple example, try this.
Open a buffer and type three lines, the middle one being "foobarbaz". Then enter the following ex commands:
set conceallevel=2
syntax match Todo /bar/ conceal
When your cursor is on the "foobarbaz" line, "bar" will be visible (and highlighted with the Todo highlight group if you have syntax highlighting on). Once you move off the line, "bar" will disappear.
For more information see :help conceal and :help conceallevel.
I think that hiding text can be a very helpful feature. Think about text folding or readability of links.
To hide text Vim 7.3 has introduced the "conceal" argument. Hiding text is a well defined Vim feature. It is not a dirty trick.
See
:help :syn-conceal
:help 'conceallevel'
:help 'concealcursor'
Please note that conceal works only for syntax regions, not for matches.
I have no experience with conceal, so I can't provide an example out of the box.
Habi

Highlight current search result in vim

In emacs, when you do a search, there will be one highlight color for all occurences in the buffer, and another color for the occurence that your cursor happens to be on. I was wondering if anyone knew about similar behavior in vim, a vim plugin, or even some ideas on how to accomplish it myself in vimscript.
(note, I already know about hl-IncSearch, which is close, but not what I am looking for)
It sounds like you want to highlight all results in the buffer. You can say
:set hls
Which will turn on hlsearch. Then you can say
:set nohls # turn off permanently
:noh # turn off until next time you search.
You can also search for / highlight the word under the cursor with * (forwards) or # (backwards).
As far as I know there isn't a built-in way to do what you want.
If I were to try to implement it myself... Well one way you could do it is by overriding *, n and p and combining it with something like this function:
noremap n n:call HighlightNearCursor()<CR>
noremap p p:call HighlightNearCursor()<CR>
noremap * *:call HighlightNearCursor()<CR>
function HighlightNearCursor()
if !exists("s:highlightcursor")
match Todo /\k*\%#\k*/
let s:highlightcursor=1
else
match None
unlet s:highlightcursor
endif
endfunction
I haven't tested it out, so this isn't a complete solution, but I think it is at least a viable approach.
EDIT : You will probably have to set some custom highlight colours. This vimwiki page gives some information about that, although I remember seeing a terser example somewhere.
EDIT AGAIN: Maybe a cleaner solution is to use Mark.vim in conjunction with the first technique. Then it would all boil down to something like:
noremap n \nn\m
noremap p \np\m
noremap * \n*\m
I just wrote a vim plugin that does what you requested.
https://github.com/timakro/vim-searchant
I don't have a real answer, but a simple way to get maybe 75% of what you want may be to just change the highlighting of the cursor. The default gray cursor block doesn't contrast well with the default yellow of search highlights. So just change cursor highlighting to (a) something that contrasts more with yellow and (2) also contrasts with other colors in your colorscheme. For me something like this works pretty well:
highlight Cursor guifg=green guibg=red
For me the blinking red cursor on first letter of current search match stands out pretty well. Not as good as a full-blown solution, but dead-simple. (I assume it works just as well in terminal Vim if you add those items to the highlight command but haven't tested it there.)

How do I make vim syntax highlight a whole line?

I'd like to have vim highlight entire lines that match certain patterns. I can get all the text in a line to highlight (by doing syn match MyMatch "^.*text-to-match.*$"), but it always stops at the end of the text. I'd like to to continue to the end of the term, like highlighting CursorLine.
I've tried replacing $ with a \n^, hoping that would wrap it around. No change. (I didn't actually expect this would work, but there's no harm in trying.) I also tried adjusting the syn-pattern-offset (which I read about here: http://vimdoc.sourceforge.net/htmldoc/syntax.html#:syn-pattern). Long story short, adding he=he-5 will highlight 5 fewer characters, but he=he+5 doesn't show any extra characters because there aren't characters to highlight.
This is my first attempt at making a vim syntax and I'm relatively new to vim. Please be gentle and include explanations.
Thanks!
(edit: Forgot to include, this is a multiline highlight. That probably increases the complexity a bit.)
It's not very adaptive as the filename (buffer) and line to full row highlight needs to be explicitly identified, but apparently the sign command can be used:
It is possible to highlight an entire
line using the :sign mechanism.
An example can be found at :help
sign-commands
In a nutshell:
:sign define wholeline linehl=ErrorMsg
:sign place 1 name=wholeline line=123 file=thisfile.txt
Obviously, you should pick a higlight
group that changes the color of the
background for the linehl argument.
source: Erik Falor, vim mailing list
From the documentation on syn-pattern:
The highlighted area will never be
outside of the matched text.
I'd count myself surprised if you got this to work, but then again, Vim is always full of surprises.
could also try
:set cursorline
:set cursorcolumn
change colors like this:
:hi cursorline
:hi cursorcolumn
using the usual term=, ctermfg=, ctermbg= etc
see this answer
VIM Highlight the whole current line

Issue with smartindent in Vim

In vim with smartindent on:
Press Enter after say an if-statement
Type in {
Press Enter twice
Type in }
If you hit ↑ and go to the previous line, indentation is removed from the blank line.
Even the vim documentation says that:
If you do not type anything on the new line except <BS> or CTRL-D and then type <Esc>, CTRL-O or <CR>, the indent is deleted again.
Is there any way to keep this indentation and not have it deleted?
Use Shift+S to start editing on a blank line (from command mode, obviously). This will start your cursor off with the expected level of indentation.
Another doesn't-answer-the-question-as-asked-but-is-a-better-solution-overall:
When typing an opening brace in insert mode, this will insert a matching set of braces
and leave the cursor on a new line in the middle.
:imap { {<CR>}<Esc>O
Similarly, this will auto-insert matching parens and square brackets.
:imap ( ()<Left>
:imap [ []<Left>
(Strip off the leading : when adding to vimrc.)
As I commented on Victor's answer, changing Vim's indentation behavior will leave "empty" lines containing extraneous spaces throughout your files. IMO, this is completely intolerable.
When this happens to me, I sometimes use ddko (or ddO) to delete the line without enough spaces and open a new line with the correct indent. Or, I'll just press A and then Tab enough times to get to the correct indent.
the article here talks about you're very same problem, and what to put in vimrc to fix it.
inoremap <CR> <CR><Space><BS>
nnoremap o o<Space><BS>
nnoremap O O<Space><BS>
I havn't exactly tested this tho.
also the same article links to a shorter alternate solution.
My preferred method is {<CR>}<esc>shift+o as it outpaces {<CR><CR>}<esc>k shift+s by several strokes. I get in a rut with it, though, and end up just using o or O to grab new, properly-indented lines off an empty when I should be using S.
That is, set up your bracing structure and open line-above:
if (true) {
}//cursor here, press shift-o
And you get the indenting you expect.
The open-above trick isn't any fewer keypresses than <up><end><cr>, but with escape remapped and shift being chorded, you can throw it in quite fast.
Also, don't forget your manual indent reset and block-movement. If you're inside a mangled curly brace block, simply use ={ (or =i{ if you're on top of one of the braces). I use that when I have a Good Idea that needs to see text asap, and I don't worry about any formatting frippery until I take a breather.

Resources