auto highlight dictionary words when opening text file in vim - vim

How would I make vim highlight all the words that are in my dictionary when opening a text file (at startup)?
My preferred way would be to add some 2 or 3 lines settings/fun/autocmd to my vimrc, but if it is not possible, what would be the plugin offering exactly this dictionary word highlight function?
Thanks in advance.

I tried various approaches such as creating custom dictionaries and then
redefining the highlighting for Normal and SpellBad words. I also tried
marking the desired words as being “rare” (since Vim uses different
highlighting for rare words) but those ideas didn’t work out. Here's the best
I could come up with:
Define highlighting
First, define how you want the words to be highlighted. In this example, I
want all the numbers from one to ten to be highlighted so I call my group,
“Numbers” and tell Vim that I want these words to appear in red with either
the terminal or the GUI version.
highlight Numbers ctermfg=red guifg=red
Option 1: Syntax
If there are a lot of words, use the syntax command to define the keywords
to be highlighted:
syntax on
syntax keyword Numbers one two three four five six seven eight nine ten One Two Three Four Five Six Seven Eight Nine Ten
Option 2: Match
Note that using syntax option, you need to include different permutations of
upper and lower case. If you don’t want to do that, you could instead use the
match keyword which operates on regular expression patterns rather than a
list of words. Use the \c option to ignore case.
match Numbers /\c\<one\>\|\<two\>\|\<three\>\|\<four\>\|\<five\>\|\<six\>\|\<seven\>\|\<eight\>\|\<nine\>\|\<ten\>/
The drawback to using match is that Vim has to keep evaluating the match
pattern for changes in the text. This becomes computationally expensive if the
regular expression pattern is too long (lots of words). This would cause
Vim to become too slow.

Related

How to highlight in Vim sequences of two symbols?

For more comfortable work with YAML/Ansible I wanna highlight pairs of spaces with different colors in a row.
For example where we write " - name" (six spaces here in the beginning of string) first pair of spaces will be yellow, next two will be red and so on.
But I can't understand how to write it in my .vimrc. Someone can help?
These aren’t exactly the two-space highlighting your looking for, but vim-indent-guides and indentLine both can get you the essential feature of highlighting columns of indent.
The alternative I think would be to create n match groups where group i matches 2 spaces (after the first 2(i-1) spaces), and then color those differently.

VIM: How to count a pattern on a line restricting from column A to column B similar to :s/,//gn?

I have a line that looks like the following, which I am viewing in vim.
0,0,0,1.791759,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5.278115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
It is from a feature vector file, each row is an instance and each column is the feature value for that feature number. I would like to figure out which feature number 5.27 corresponds to. I know the
s/,//gn
will count the number of commas in the line, but how do I restrict the command to count the number of commas in the line up to the columns with the number 5.27?
I have seen these two posts that seem relevant but cannot seem to piece them together: How to compute the number of times word appeared in a file or in some range and Search and replace in a range of line and column
s/,\ze.*5\.27//gn
The interesting part is the \ze which sets the end of the match. See :h /\ze for more information
Select the wanted area with visual mode and do
:s/\v%V%(,)//gn
\v enables us to escape less operators with \
%V limits the search to matches that start inside the visual selection
%() keeps the search together if you include alternations with |
It's not pretty but it works. See help files for /\v, \%V and \%(
There are also several versions of a plugin called vis.vim, which offers easier commands that aim to do just the above. However I haven't gotten any of them to work so I'll not comment on that further.
try this
s/,.\{-}5.27//gn
it should work.

vim syntax highlighting for partial overlap (*not* nested) regex matches?

I have a long .vim file of arbitrary strings to be highlighted. I have it working, except that where two expressions overlap, the first is highlighted, and the second is not. For example, two of the lines are...
the third part
part of the trilogy
... and in the phrase "the third part of the trilogy," only the first three words are properly highlighted, because the second line is not matched. Is there any to match both lines, so the whole phrase is highlighted?
It's not at all clear what you are trying to match here but
third.*\n.*the
will hilight across lines.
If you want to highlight third AND part then
third.*\n*part will work.
Have a look here http://vim.wikia.com/wiki/Search_across_multiple_lines for the other other options as I don't totally understand why the \n needs a * after it to complete the match.

How to highlight multiple words in vim

I am checking a log file using vim. There's only one word can be highlighted, when I search another word,the second word is highlighted but the previous one is not highlighted anymore.
Can anyone show me a way that easily highlight/cancel highlight multiple words in vim? For example, I want to highlight words "stack", "over" and "flow", then I want to cancel the highlight of "stack" and highlight another word "error". So that I can analyze the log more efficiently.
Thanks.
There are two simple ways to highlight multiple words in vim editor.
Go to search mode i.e. type '/' and then type \v followed by the words you want to search separated by '|' (pipe).
Ex: /\vword1|word2|word3
Go to search mode and type the words you want to search separated by '\|'.
Ex: /word1\|word2\|word3
Basically the first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.
/\v\/folder|\/copy - search for \folder and \copy
and add to .vimrc set hlsearch
To have all words highlighted in the same color and be able to search and replace all of then, add them as alternatives to the search pattern, e.g. /foo\|bar. My SearchAlternatives plugin provides handy mappings to add and remove patterns.
If you want different colors for different matches, you need a highlight mechanism different from the built-in search. My Mark plugin is used by many people for that. (The plugin page has links to alternative plugins.)

Replace colon with tab to make columns

I have word lists where the word or expression in Spanish is separated by its translation with a colon (":"). I want to make two columns, one for Spanish, the other for English. In vim I tried with
:%s/:/^I^I^I/g
But it does not give the desired output. The different columns are not aligned.
When deleting the colon by hand and inserting the number of tabs with the same amount of tab strokes, it always ends up aligned.
Any idea how to solve this, preferably in vim?
On a Linux/*nix system I use column(1)
:%!column -s':' -t
followed by
:%retab!
I'd probable do a
:s/:/^I/g
followed by a
:set ts=25
Where 25 is the length of the longest word expected + 2. So, if you expect the longest word of your input (on the left side of the colon) to be 12 characters, I'd choose something around 14 instead.
With Tabular.vim it's quite easy, just type :Tab /:\zs and it does the rest.
When in insert mode a setting of yours makes tab to reach a nth column. This is set with the 'softtabstop' settings if I am right.
For those tasks you could use a plugin like Align.vim or Tabularize.
Another option is to insert a huge number of spaces, and then use Visual Block with < operator as many times as necessary, if you have to do it once. Otherwise prefer reusable methods.

Resources