In vim, when I have a Bash function that ends with a Bash keyword, my vim highlighting starts highlighting it and assumes a new scope (if applicable):
values-for() {
...
}
^yellow "for" highlight
^syntax error highlight
But when I rename the "for" word to "for1" then those undesired highlights disappear.
How do I tell vim to ignore keywords like "for" when it is used as part of a function name?
I cannot reproduce this with the $VIMRUNTIME/syntax/sh.vim script (that ships with Vim 8.0.1358), version 172 from Oct 02, 2017 (assuming a proper #!/bin/bash shebang, so that the syntax detects the Bash dialect).
On the maintainer's web site, there's an even newer update (version 174).
If you can still reproduce the problem with that version, please contact DrChip via email and report this bug.
Just to be clear, this is something that you cannot fix "in Vim"; it's a bug in the syntax definition itself, so that must be changed.
Word boundaries are \< and \>. So use \<for\>.
Related
I am trying to learn UNIX.
I am using a book called “Wicked Cool Shell Scripts”.
I am told that .bash_profile contains my login for bash and that I can add paths to it so that commands I enter in Terminal will find the scripts I am writing.
The contents of my current bash_profile is:
export PATH=~/bin:$PATH
When I type echo $PATH I get:
/usr/local/opt/php#7.0/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/Frameworks/Python.framework/Versions/3.3/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
I would like to add a path so that - as the book suggests - I can write scripts and refer to them directly from the command line, instead of having to constantly navigate to that directory to run them.
I have a file with a shebang. It runs fine when I type its name and am in the same directory. I have moved that file to the folder scripts, which is located under crg/Users/ (ie: Users/crg/scripts)
According to this book, I can now alter my $PATH to include that directory, so that when I type that filename, the program will run.
I cannot do this successfully.
I don’t know why.
After every edit, I quit terminal and reopen it, to ensure it is using the newly edited bash_profile.
As per the books instructions on page 5, I have tried entering this in my bash_profile:
export PATH=”/Users/crg/scripts/:$PATH”
I save my bash_profile, quit Terminal, reopen it and type echo $Path
This is the result:
”/Users/crg/scripts/:??
This is not right. In fact, it's wildly wrong. And it does not allow me to run scripts from the folder indicated. It also seems to completely overwrite whatever was in the bash_profile before this, so I cannot - after doing this 'simple edit' suggested by a 'professional' - run a php -version command from the Terminal.
I am at a complete loss as to why this is happening.
Why is there a quotation mark at the beginning of this line (but not at the end)?
What's with the colon and the 2 question marks at the end of this line?
How do I add/append a path to my bash_profile?
More questions:
When I try and solve this on my own using “the Internet”, I discover many interesting versions of this ‘simple’ process: Here’s one suggested by a ‘professional’:
export PATH="${PATH}:/path/to/program/inside/package"
This is very different from what the book says...
Here’s another version of ‘how to do it’ by ‘a professional’:
export PATH=$PATH:/usr/local/sbin/modemZapp
Notice that this one doesn’t even have quotes. In both, the PATH variable comes before the actual path.
Why are there so many 'versions' of how to perform this simple task?
Can someone please tell me how to add a path to my .bash_profile?
UPDATE: I have followed the advice here, (add it to etc/paths) but this does not work either.
I get the exact same thing when I type echo $PATH in a new Terminal:
/usr/local/opt/php#7.0/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/Frameworks/Python.framework/Versions/3.3/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr:/usr/local/share/npm/bin:/Users/fhb/scripts:/opt/X11/bin
I can't help but note a comment on that last page: "I have been through at least a dozen different methods for adding directories to $PATH. Why are there so many and why do so few of them work?"
To answer your first question if you look closely your quotes are ” instead of ". I'm guessing you edited either your bash_profile or this post in a rich text editor instead of a plain text one. I would recommend notepad for Windows or nano for *nix if you are writing code. To fix this issue, replace the ” with ".
To answer your second question, bash is quite forgiving and will allow you to set a string variable in multiple different ways, even without quotes. However you can run into issues when a string contains whitespace, for example: /Users/lilHenry/my scripts.
The "${PATH}" syntax is just another way to declare a string. It has the benefit that it allows you to interpolate variables into a string like so:
prefix="foo"
echo "${prefix}bar"
This will output foobar, whereas echo "$prefixbar" will not output anything as the variable prefixbar has not been set. I would suggest sticking with the export PATH="/Users/me/bin:$PATH" syntax.
Tried debugging this one a few different ways and bash -x and setting display lines was no help. I screened it for non-ascii chars and still no dice.
Went through and checked for logical errors and didn't see anything that unterminated or inf loops. I am thinking my getopt syntax is to blame but I followed the guidlines in manpage and couldn't find any issues.
It's a decently long setup script but so I hosted it here:
cdr.sh - deployment script
#cyrus spotted it.
The # without space next to closing brace on that function, thanks!
I'm surprised spellcheck didn't find that one and I guess i should change my synax colors in vim because the functions were same blue as comments.
In vi, the % key can be used to jump to a matching opening or closing parenthesis, square bracket or a curly brace.
Could it also be used to jump between matching "do" and "done" in a bash loop?
Not "vi" as such. vim does that.
There is a script matchit.vim which can do this:
The script is documented in the vim wiki page Moving to matching braces.
It part of the vim distribution, but is not installed (in your ~/.vim/plugin directory) by default. See the vim help for matchit-install for details.
Once installed, it has to be enabled, e.g., (see matchit.zip : extended % matching for HTML, LaTeX, and many other languages):
filetype plugin on
in your vimrc file.
For further reading:
Vim: Jumping to if endif in fortran uses simply runtime macros/matchit.vim rather than the two-part install from the vim wiki.
Matchit not working has several answers, some disagreeing.
The runtime macros/matchit.vim line in ~/.vimrc did not make matchit.vim work in my quick test; the procedure in matchit-install, plus the filetype line did work. As usual, your configuration may differ.
I maintain (and of course use) vi-like-emacs, and wrote comparable functionality for that editor using a different approach (see discussion of "fences" in documentation). In a quick test, I see that matchit.vim does not know about the syntax for case-values in a shell case statement. So there is some room for improvement.
I'd like to know if it is possible to make bash auto-completion highlight the matched part of the auto-complete suggestion.
For example,
I am have directories with files such as these:
LSFJOB_647169535/ LSFJOB_647158534/
In this case, if I type LSF and hit Tab, then I get:
LSFJOB_6471
But then I have to focus hard to get which character should I type next.
I'd like bash to suggest me something like:
LSFJOB_647169535/ LSFJOB_647158534/
or
LSFJOB_647169535/ LSFJOB_647158534/
Do you know a way of doing it?
That is a good question!
Dennis Williamson already answered it there (SuperUser).
So it turns out that there is a "ReadLine Variable" that does exactly that: colored-completion-prefix.
Sadly it's only available in Bash v4.4 :c Link to the diff
You can check its value with bind -v|grep color
I tried to play with compgen but it appears that it strips colors away /:
Instead of colored-completion-prefix, which requires Bash 4.4, you could add the older (Bash 4.0)
set completion-prefix-display-length 2
to your ~/.inputrc (see manual). This replaces any common prefix longer than 2 characters with an ellipsis when showing the completions:
$ ls
LSFJOB_647158534 LSFJOB_647169535
$ cd LSFJOB_6471<tab>
...58534/ ...69535/
I've just started using Terminal (the CLI for Mac OS X).
When I run a command, get some information back, run another command, get more info etc., it is hard (on the eyes) to find a certain point on the screen (e.g. the output for the command before last).
Is there a way of adding a vertical empty space to the end of each output/ after each command is run that has no output?
Each new command that you enter is preceded by a "prompt", and these can be customized (though the exact way to customize depends on the shell). Since you mention Mac OS X I'm assuming you are using the default bash shell, in which case the absolute simplest way to add a blank line is like this: PROMPT_COMMAND=echo. You can run that command to try it out, or add it to a startup file (like .profile in your home folder) to have it done automatically each time.
If you use Bash 4.4 and you want a blank line after your prompt, you could set the PS0 prompt to a newline:
PS0="\n"
Now, this will be inserted every time you run a command:
$ echo "Hello"
Hello
Wondering this too, I've looked at the menu options in Terminal & most of the control characters one can type in and nothing does this on a keystroke. You can however enter an echo command, it alone to leave a single blank line below it before the next prompt. echo \n will add an extra blank line to that, echo \n\n to do 2 extra, ie. 3 blank lines, etc. (you can also do echo;echo;echo getting the same effect)
You can create a shell alias like alias b='echo;echo' (i couldn't seem to get the \n notation to work in a alias), then entering b on a prompt will leave a double-blank line, not bad. Then you gotta figure out how to save aliases in your .profile script.
I tried making an alias for the command ' ' ie. space character, which I though you could type like \ (hmm, stack overflow not formatting this well, that's backslash followed by a space, then return to execute it), but the bash shell doesn't seem to allow an alias with that name. It probably wouldn't allow a function named that either (similar to alias), though I didn't check.
I often use the fish shell, and I found that it does allow a function with that name! Created with function ' '; echo \n; end and indeed it works; at the shell prompt, typing the command \ (again backslash space) leaves a double blank line.
Cool, but.. I tried saving this function using funcsave ' ' (how you save functions in fish, no messing with startup scripts!) and afterwards the function no longer works :^( This is probably a bug in the fish shell. It's in active development right now though, I think I'll report this as a bug since I would kind of like this to work myself.
One could also send Apple a feature request through their bug reporter for an Insert Blank Line menu/keyboard command in Terminal. If someone pays attention to your request it might be implemented in a year maybe.
I wanted to solve exactly the same, and for anyone interested in doing the same, I used what tripleee said in his comment here - I created a .bash_profile (see details here) with the line export PS1="\n\n$ ".
Hopefully that helps someone else too!