ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
1) The coloring of "words" (search patterns) is done by search highlighting. It highlights (colors) all the patterns found, not just the one you jump to. This has nothing to do with opening a file and jumping to a specific word.
Syntax highlighting is in general set in the /etc/vimrc or ~/.vimrc file and looks like this on my machine:
Code:
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
2) I'm not sure what you mean by this:
Quote:
if there are few words the cursor goes to the first line that the word exist.
When searching for a pattern, the search will stop at the first occurrence it finds. Pressing n in command mode will jump to the second (third etc).
The solution is a combination of my previous 2 asnwers.
1) set up general search highlighting (see point 1 post #4). <- I think this is not set up at the moment
2) start as stated in post #2 (vi +/marked_word infile).
If both are working correctly, the infile should be opened, all marked_word's should be highlighted and the cursor should be at the beginning of the line that contains the marked_word (first instance of that marked_word).
Do you want to search for 2 (or more) different words at the same time (and see them highlighted)?
If that is the case:
You can use an OR ( | ) construct, which needs to be escaped. Normally you do (from command mode) /foo and press enter and vi goes to and highlights foo.
If you want to look for foo and bar: /foo\|bar Both foo and bar are highlighted and the cursor will jump to either of the 2 that comes first.
I didn't realize you did this from the command line, not from within (g)vim itself.
You indeed need to keep the search part together. Using double quotes is probably the easiest, although the following would probably have work as well (it does for vim): gvim +/word1\\\|word2 file.txt
I'm not sure if this can be set in the configuration file (I don't think it can, never tried it). It is something that needs to be addresses when construction the regular expression.
This: /\<foo will only look for foo and not foobar or barfoo. It also doesn't matter if foo is at the beginning or end of the line.
Give this a try:
gvim +/\\\<word1 file.txt
or gvim +/"\<word1" file.txt
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.