Editing .php-Files adds ^M linebreak - wordpress

Recently when I edit my Wordpress files, after saving, I get this annoying ^M with every line break. I was told that this is a Windows issue, which is kind of confusing cause i am using a MAC. For editing I use PHPStorm with UTF-8 setup. Additional I don't know much or nothing about encoding. Anybody can help?

For brand new files (created in IDE) you can change default line ending in Preferences | Code Style | General | Line Separator.
For existing files -- it is automatically detected for each file individually. You can change line ending at any time by changing File | Line Separators (or via right click in status bar in appropriate place -- where current line ending is displayed).

if you can use a Vi editor.. open your file using vi ...
vi example.java
then press esc and type :
then type beside the colon %s/ctrl+v ctrl+M/
press enter/return
then press esc and :
now type wq
It would save the edits and ^M would be gone ..,,

Related

Zsh vi copy mode selection - character under cursor is not highlighted

If I switch to copy mode in zsh (vi mode), and begin selecting text using v, the character that is directly under the cursor is never highlighted properly even though it is selected (i.e. if I copy the selection, that character shows up in the pasted text).
I want zsh to properly highlight all selected characters, including the one under the cursor just like in vim. How can I do that?
Here is the highlighting/color portion of my .zshrc file
autoload -U colors && colors
PS1="%B%{$fg[red]%}[%{$fg[red]%}%n%{$fg[red]%}#%{$fg[red]%}%M %{$fg[red]%}%~%{$fg[red]%}]%{$reset_color%}$%b "
You can set the region parameter of zle_highlight array by adding this line to your .zshrc configuration:
zle_highlight=('region:bg=168,fg=251')
Adjust the colors to your liking.
Read more about character highlighting in zsh here.
I had a similar problem with a cursor not being highlighted in visual vi mode.
I found zsh-syntax-highlighting plugin and I was interested if this was fixed or workaround in this plugin. It wasn't by default, but I made some tests and tweaks with highlighters and it worked!
I added the following configs in my .zshrc and the cursor started to be highlighted in visual vi mode:
source ~/.config/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# zsh-syntax-highlighting
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern regexp line cursor)
typeset -A ZSH_HIGHLIGHT_STYLES
ZSH_HIGHLIGHT_STYLES[cursor]=bg=white

ZSH: Hide computer name in terminal

How would I hide the computer name in the prompt while using the terminal?
At the moment it shows both username and computer name like so:
It would save some space by removing anwarchoukah#anwars-mbp, seeing as I actually know who I am:)
Try to add export DEFAULT_USER=$USER to your .zshrc file
On MacOS 10.15 Catalina:
Open the file /private/etc/zshrc in a text editor
Locate the comment: # Default prompt
Modify the line that looks like this: PS1="%n#%m~ %& # "
Save the file. You will be prompted to enter a password to save it.
Load a new Terminal window.
For example, you can:
Remove "%n#%m" to get rid of both the username and computer name
Remove "%n" to get rid of the user name
Remove "%m" to get rid of the machine name
step 1. one your .zshrc file by vim .zshrc
step 2. go to end of your file.
Paste this code:
careful indent again your code
prompt_context() {
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
prompt_segment black default "%(!.%{%F{yellow}%}.)$USER"
fi
}
EDIT - explaining what this does
This will remove the machine#user name from the prompt IF:
- you are not logged in as the default user
- you are not in an ssh client shell
For most people, not needed, but if you regularly ssh to other machines and have multiple terminals open (eg remote sys admin type work) then this is extremely useful so when you look at your terminal you know which machine and user you are logged in as inside that terminal.
If you don't need/manage that type of complexity then use one of the other answers to just modify your export PROMPT/PS1 value.
* WARNING *
If you are using a custom shell or theme, this might not work and although the prompt will no longer show your computer and username it will keep throwing the error:
prompt_context:2: command not found: prompt_segment
For example, you can see with this (very popular) powerlevel9k it does not work. This is because the Powerlevel9k theme uses it's own magic and you simply add commands to your ~/.zshrc file to get the same result, eg:
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context)
More info on that here.
Open up .zshrc, find the line reading export PS1 or maybe export PROMPT.
Remove the variable that is used for the hostname, could be %m or %M.
Zsh on Archlinux wiki
You can use colors and also have a prompt (or some information) on the right side.
I like this approach (on my mac)
put in .zshrc
PS1="%n$ "
The terminal will look like
username$
Just add prompt_context() {} to .zshrc
Unfortunately none of the .zshrc changes worked for me.
Machine : Mac M1, Big Sur 11.4
So this is what worked.
I Navigated to where the ZSH themes were installed, opened my theme, agnoster in TextEdit, and modified the configuration where it chooses what do display, which by default is $username#%m.
Note : %m here is the machine name.
Here is a screenshot of delta. Yellow is what I did, Green is the default setting from github version of agnoster theme.
Voila this worked. Now to me it just displays the machine name, as I intended.
Hope that helps. Many links and SOF posts only made me click that solution.
Set DEFAULT_USER in ~/.zshrc file to your regular username. You can get your exact username value by executing whoami in the terminal.
Something like this:
export DEFAULT_USER=username
If you are using PowerLevel9k theme, there is a variable POWERLEVEL9K_CONTEXT_TEMPLATE that can change the view of your hostname and computer name.
The default option is %n#%m,
%n -> username
%m -> machine name
to hide hostname:
Open the .zshrc file using sudo nano ~/.zshrc
Add the line
POWERLEVEL9K_CONTEXT_TEMPLATE="%n" at the end of .zshrc file
Save the file.
Maybe this will help you [ Open Profile => Shell ]
PS1="~ $: ";clear;
Just add this to your ~/.zshrc file:
export DEFAULT_USER=\`whoami`
Install Oh My Zsh is the easiest solution for me:
https://ohmyz.sh/
One liner install:
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Result:
If you're using Powerlevel10k, then you can run p10k configure and configure the output a bit.
My username and computer-name was gone after having gone through it. It feel less hacky, than the other solutions here.
I don't know why I can't find a simplified solution.
So here is the simplified one.
Just jump into the themes directory,
# ~/.oh-my-zsh/themes
Select the theme, as I have been using
# vim agnoster.zsh-theme
Just remove %m to remove and also you can remove the username too.
Once done,
Just run
#zsh
To reflect the changes, Enjoy :)
Thanks to Wes Bos' amazing video series Command Line Power User , I managed to find the answer.. It's pretty simple. Stuff like that is set in the ZSH theme.
Open up .zshrc, change the theme from ZSH_THEME="agnoster" (which is what I was using) to something else.
Wes Bos has made a lovely theme called Cobalt2 which does exactly what I was looking for :)
I've now changed it to ZSH_THEME="cobalt2"

tail -f did not continue output the new lines added using vi

When I invoked "tail -f myfile.txt", the new line added using the following command output the new line, but not the line added/saved using vi. Does anyone know why ?
$echo "this is new line" >> myfile.txt
Thanks.
It has something to do w/the fact that while you are editing the file, vi keeps your changes in a second file (.myfile.txt.swp in this case).
When you save the changes, it's likely that vi is replacing the original file w/the second file. This means the file that tail was watching is no longer valid.
To prove this, try your echo command after saving the file with vi. When you do that, the output won't be displayed by tail.
The tail program opens a file, seeks to the end, and (with "-f") waits, then checks again if that open file has anything new to read.
vi does not append to a file. It makes a copy, (not a "swap", which is something else altogether) writes it out, and then moves the new file to have the same name as the old file.
tail is still watching the old file, not looking up a file by that file name every time.
In addition, tail uses the location in the file, so if you delete 10 characters and add 15, the next loop of 'tail' will emit the next 5 it thinks are new because they are after its placeholder.
Run 'tail --follow=name ...' to get tail to look up the file every loop by name, instead of watching the location on disk of a file it opens at start.

Unable to change a pipe to be a normal file

I have the following file (above) which seems to be an Unix pipe
alt text http://dl.getdropbox.com/u/175564/problemFile.png
How can you make the pipe a default text file?
Unless there is some other complication that hasn't been mentioned, the easiest is to use the big hammer:
$ rm outside
$ touch outside
If there is a process currently using the file, you will need to kill the process first, then restart it so it uses the new file. Otherwise, the pipe will stay open but invisible until the process finally dies.
How can you make the pipe a default
text file, such that the first letter
changes to d?
The first character of 'd' means that that entry is a directory - not a normal file.

How to autocomplete at the KornShell command line with the vi editor

In the KornShell (ksh) on AIX UNIX Version 5.3 with the editor mode set to vi using:
set -o vi
What are the key-strokes at the shell command line to autocomplete a file or directory name?
ESC\ works fine on AIX4.2 at least. One thing I noticed is that it only autocompletes to the unique part of the file name.
So if you have the files x.txt, x171go and x171stop, the following will happen:
Press keys: Command line is:
x x
<ESC>\ x
1 x1
<ESC>\ x171
g<ESC>\ x171go
Extending the other answers: <ESC>* will list all matching files on the command line. Then you can use the standard vi editing commands to remove the ones you don't care about. So to add to the above table:
<ESC><shift-8> x.txt x171 x171go
Then use backspace to go get rid of the last two, or hit <ESC> again and use the h or b to go backwards and dw to delete the ones you don't want.

Resources