I open an XML file in Vim and found that there are a lot of ^M and ^G symbols showen in it.So I try to use dos2unix to drop the ^M symbols,but it told me that the file is binary file, which makes it skipping the file.After drop the ^G symbols manunally, dos2unix is successfully process that file. My question is: what does ^G actually mean here ? Is it ^G in a file makes it a binary file?
^G is the bell character. When the file is displayed on a traditional terminal, you will hear a beep when you reach that character. There is no difference between "binary" and "text" files, really, so dos2unix is just guessing, and in this case guessing wrong. You can use the option -f to force it to convert files it thinks are binary.
To add to the above answer, Ctrl-M is also usually an end-of-line / linebreak character corresponding to the "\r\n" carriage return used by Windows.
You can read more about in the answers to this question, which include some methods of converting them to unix-style line endings (if you need to): What does ^M character mean in Vim?
Related
I have a project in Visual Studio that can build and run successfully. I need to make it work in Linux. One problem is that the newline character is different from that in Linux, thus I'm getting tons of warnings saying that "no newline at end of file". Appending newline characters to all files one after another is tedious, I'm wondering whether there is a Linux command that I can use to perform the same operation (here, the operation is append newline to end of file) to all files in a directory in Linux?
Thanks in advance!
-Leonora
Most linuxes have a dos2unix command that helps with file conversions.
I have a file with mac format, I know I can use :e! ++ff=mac to change to the correct fileformat. What I'd like to know is if there is a command line option I can pass when I open the file to open it directly with the correct fileformat.
You can do this using the command line, try:
$ vim -c "set fileformat=mac"
-c <command> executes before loading the first file. As jammessan has noted, this will only affect the first file that is loaded, subsequent files will require that you change fileformat for each buffer.
If that doesn't work, you can also try:
$ vim -c "e ++ff=mac"
But it's better to set this up in your .vimrc on that machine:
set fileformats=mac,unix,dos
specifies which formats to try when starting a new buffer. This also can influence what fileformat is chosen for existing files.
See help file-formats, :help 'fileformat' and :help 'fileformats' for more details.
The better solution would be to make Vim automatically recognize files in that format. You can do this by updating the 'fileformats' option in your ~/.vimrc
set fileformats=unix,dos,mac
This will make Vim check all three formats when determining which format a file is in.
Quiet simply I am trying to add new files to my repository, my command goes like this:
svn add * --force
but this produces:
svn: File 'install/config.xml.php' has inconsistent newlines svn:
Inconsistent line ending style
The thing is that this file is not yet under version control, so when I try to propdel or anything similar it doesn't work.
I am sure this file is not under version control because svn status shows this:
? install/version
? install/config.xml.php
I have already enabled the autoprops in svn default config but this did not help.
Any ideas?
Btw: this is a server, so no GUI.
vim makes it easy to force line endings to entirely CRLF or entirely CR.
:set ff=unix
:wq
d2u, dtox, dos2unix, are some names for simple utilities that are often installed on systems to do this task. You could also use the standard tr(1) utility:
tr -d '\r' < input > output
While working on Windows OS use Notepad ++:
Edit -> EOL Conversion.
- Windows Format
- UNIX/OSX Format
- Old Mac Format
You have current format information in the status bar.
When I'm working in vim, my current working directory (./) contains all my source. I build in an objdir, let's call it ./builddir/. When I build from vim, using makeprg=make\ -C\ builddir, the compiler warnings and errors all have a prefix of ../, which means vim brings the cursor to a file which doesn't exist.
If I try a different tactic, launching vim from the objdir, then I can't do commands like gf or :e myfile.h simply.
Is there a middle ground where all of this will work, like giving vim a second directory to search from if it can't find files in the current working directory? Or maybe getting gcc to use a different prefix?
The most simple solution would be to filter make outputs with sed to replace the output pathnames. (I've implemented a very similar thing to convert cygwin pathnames into windows pathnames for the win32 flavour of vim).
Something like:
:let &makeprg .= '2>&1 | sed "s#^\.\./##g"'
(It may be \| and not |, I don't remember)
How can I clear certain criteria from my .viminfo file?
I want to clear the command line history, file marks, jumplist, etc.
However, I want to keep the search string history.
Is there any way to do this?
I can think of 3 ways to do this.
1. Automatically
Run Vim,
Type: :set viminfo='0,:0,<0,#0,f0
'0 means that marks will not be saved
:0 means that command-line history will not be saved
<0 means that registers will not be saved
#0 means that input-line history will not be saved
f0 means that marks will not be saved
no % means that the buffer list will not be saved
no / means that the search history will be saved
These options are correct in Vim 7.2, but might be different in other versions. For more details on the format of the viminfo string, run :h 'viminfo'
Quit Vim. It will save a new version of the .viminfo file, containing only the information you want to keep.
2. Manually
Open the .viminfo file in vim,
:set viminfo= to turn off the auto-saving of info to the .viminfo file. If you don't do this, Vim will overwrite all your changes when you quit,
Remove everything you don't want (perhaps by using Johnsyweb's answer, or just by deleting the lines with manual edit commands), save the file, and quit vim,
3. In a different editor
Edit the .viminfo file in a different text editor and simply delete everything you don't want,
Open the .viminfo file.
The following command will remove all lines that are neither blank, comment nor search history:
:v/^\([#/?]\|$\)/d
#Rich's answer will help you prevent these lines being repopulated.
You can use vim itself to modify the file, and your changes will stay put if you invoke it like this:
$ vim -i NONE ~/.viminfo
Starting vim with the -i option sets which viminfo file to use for that session. The special value NONE means that nothing is saved at all. This can be handy for editing other auto-generating files or sensitive data.
From man vim:
-i {viminfo}
When using the viminfo file is enabled, this option sets the filename
to use, instead of the default ~/.viminfo. This can also be used to
skip the use of the viminfo file, by giving the name NONE.
VIM seems not having a built-in command for this job. But you can do it in a shell with "grep".
For example, the following command will clear the Command Line History,File marks, Jumplist:
bash $ grep -v "^[:'-]" .viminfo > .viminfo_clear
bash $ cp .viminfo_clear .viminfo
If you open the .viminfo, you will find that the command line history is started with ":", the file mark is started with "'", and the jumplist is started with "-".
Copy useful part out and delete .viminfo, then open/close Vim. It will regenerate .viminfo. Then copy useful part back.