I doing a code-review for a colleague. I have opened the diff using vimdiff. There are over 50 changes within the same file. Each line that has a diff is highlighted. Thus, I have close to 50 highlighted lines. As I work through the code review, I would like to mark the lines I have fully reviewed as OK. One way to do this, would be to tell vim to not highlight that line anymore. Is there a way to do this?
You could use this:
highlight Hignore ctermfg=black guifg=black
command! D call matchadd("Hignore",getline('.'))
Typing :D will highlight the current line according to Hignore. To recover the original highlighting do :call clearmatches().
Related
My line numberings in Vim are blue (background) and white (foreground) but this is not very clearly especially for large files.
I would like to have every fifth line numbers background in darkblue and every tenth line numbers foreground in red, so that one can distinguish between 5 and 10 lines of code easily without counting or having to focus at the line numbering.
How can I make this happen? Unfortunately I did not find any plugin doing this..
You cannot make different hl(highlighting) on the line number column. You can somehow highlight the text in the line however. But I guess this is not what you are looking for, you just want to see some flag/highlighting on the line number column. Then the sign might be the closest to your requirement.
source this codes: (I just randomly picked color, you can adjust them as you like)
hi FifGroup term=bold ctermfg=red
hi TenGroup term=bold ctermbg=darkgreen
sign define fifth texthl=FifGroup text=->
sign define tenth texthl=TenGroup text=>>
fun! PlaceLineSign()
for i in range(1+line('$'))
if i =~ '5$'
execute 'sign place '.i.' line='.i.' name=fifth buffer='.bufnr('%')
endif
if i =~ '0$' && i>0
execute 'sign place '.i.' line='.i.' name=tenth buffer='.bufnr('%')
endif
endfor
endf
fun! RemoveLineSign()
sign unplace *
endf
nnoremap <F6> <c-u>:call PlaceLineSign()<cr>
nnoremap <F7> <c-u>:call RemoveLineSign()<cr>
then you can press <f6> to display those flag, and <F7> to hide them.
Note, there is one problem with "sign", if you displayed the signs, and change the line numbers, i.e. removed/added new lines, the "sign"s won't change correspondingly. But hide and display again should go.
It looks like:
You can use my DynamicSigns plugin. It defines a SignExpression command, that works similar to the foldexpression. In your case, you could simply do:
:SignExpression v:lnum%10==0?'Line1':v:lnum%5==0?'Line2':''
Advantage of using my plugin is, it takes care of adjusting the line numbers automatically, when you add or delete lines. Note: depending on the size of your file, this might slow down Vim. But this is a problem, many sign plugins have in common, since there is no VimL API for accessing signs.
I'm also thinking about the same thing but unfortunately there's no easy way to do it (unless using sign support as other answers suggested, at the cost of slowing down).
The best close thing native to vim is LineNrAbove/Below. However, it's defined in vim source itself: https://github.com/vim/vim/blob/f3fa18468c0adc4fa645f7c394d7a6d14d3d4352/src/drawline.c#L1156-L1167; It should be easy to extend to highlight groups like every k-th relative line but it I don't think in the foreseeable future that it would be included in vim. I believe this is the only usable option because evaluating is done in the vim core which is fast than doing so at vim script.
I want to highlight the search keyword in Vim. Mainly I use vim to debug the logs.
I always have to use :se hlsearch to highlight the search keyword.
So, I want the solution that it should set command permanently, and I should not use the command always when vim starts.
Set the command in .vimrc.
Use the following commands:
Open ~/.vimrc file (or create it if it didn't exist).
Add set hlsearch in the file.
Save the file.
Now your search will always be highlighted in vim.
For single time use, just use :set hlsearch in vim, which will be in effect for that instance only.
If you want to highlight multiple searches (in parallel, with different colors), check out my Mark plugin; it also allows to persist the highlightings across Vim sessions through the viminfo file; cp. :help mark-persistence.
For those wanting to visually keep highlighted their search:
:syn match stupid "ctrl + /"
:hi stupid ctermbg=Red guibg=Red
Explanation:
The first line add your regex to a syntax type called "stupid" (note that ctrl + / means you must press ctrl+R then / to get the content of the search registry).
The second line gives a red color to the "stupid" syntax regex.
My SelX plugin allows you to highlight and search for many different things at once on a per-tab basis, with different colours. The highlight config can be saved to a vim session
https://www.vim.org/scripts/script.php?script_id=5875
Some how the first column of any vim buffer is being highlighted. I didn't notice until today so I'm not really sure when the change happened. I tried to mess around with the search options and highlighting options but I was not successful.
Does anybody have any idea to what may be causing this?
Here is a screenshot:
Here is my vimrc: https://tinyurl.com/mrbcu77
I don't know if you wrote your vimrc by yourself. If you search in that file for colorcolumn, you found two lines:
50:set colorcolumn=+1
and
70:set colorcolumn+=1
70 line, you force the 1st column to be highlighted.
remove that line and try again.
also you auto load (source) vimrc by autocmd when it was saved. you can try opening it in vim, and save it 10-20 times, see how slow your vim would be. You should clear autocmds before create them.
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
This has bugged me for a long time, and try as I might I can't find a way round it.
When I'm editing text (specifically latex, but that doesn't matter) files, I want it to auto-wrap at 80 columns. It does this, except if I happen to be in the middle of a parenthetical clause, it indents the text which is very annoying. For example, this works fine
Here is some text... over
two lines.
but this doesn't
Here is some text... (over
two
lines
If anyone can tell me how to turn this off (just for text/latex files) I'd be really grateful. Presumably it has something to do with the fact that this is desired behaviour in C, but I still can't figure out what's wrong.
:set nocindent
The other options do nothing, and the filetype detection doesn't change it.
There are three options you may need to turn off: set noai, set nosi, and setnocin (autoindent, smartindent, and cindent).
This may be related, when pasting from gui into terminal window, vim cannot distinguish paste modes, so to stop any odd things from occuring:
set paste
then paste text
set nopaste
I had similar issues trying to paste xml text, it would just keep indenting. :)
gvim, the gui version of vim, can detect paste modes.
You can have a look at the autoindent option :
autoindent - ai
Copy indent from current line when starting a new line (typing
in Insert mode or when using the "o" or "O" command). If you do not
type anything on the new line except and then type or
, the indent is deleted again. When autoindent is on,
formatting (with the "gq" command or when you reach 'textwidth' in
Insert mode) uses the indentation of the first line. When
'smartindent' or 'cindent' is on the indent is changed in specific
cases. The 'autoindent' option is reset when the 'paste' option is
set. {small difference from Vi: After the indent is deleted when
typing or , the cursor position when moving up or down is
after the deleted indent; Vi puts the cursor somewhere in the deleted
indent}.
From the official Vim documentation
filetype plugin indent on
This switches on three very clever
mechanisms:
Filetype detection. Whenever you start editing a file, Vim will try to
figure out what kind of file this
is. When you edit "main.c", Vim will
see the ".c" extension and
recognize this as a "c" filetype.
When you edit a file that starts with
"#!/bin/sh", Vim will recognize it as
a "sh" filetype. The filetype
detection is used for syntax
highlighting and the other two
items below. See |filetypes|.
Using filetype plugin files Many different filetypes are edited with
different options. For example,
when you edit a "c" file, it's very
useful to set the 'cindent' option to
automatically indent the lines. These
commonly useful option settings are
included with Vim in filetype plugins.
You can also add your own, see
|write-filetype-plugin|.
Using indent files When editing programs, the indent of a line can
often be computed automatically.
Vim comes with these indent rules for
a number of filetypes. See
|:filetype-indent-on| and
'indentexpr'.
:set noai
sets no auto indent tt may be smartindent though. Check out the doc and see if you can find something more
http://www.vim.org/htmldoc/indent.html