emacs adding spaces to file - text

I'm loading a text file into emacs and it is displaying a vertical column of slashes as a big blob of slashes with different spacing for each line. It displays correctly in VIM and notepad++, but not in emacs. What could cause this to happen?
emacs display error

This is probably because the file contains tabs, and Emacs uses a different tab width than VIM and notepad++.
You can make Emacs show what kind of whitespace there is with M-x whitespace-mode.
To change how Emacs displays tabs, use M-x set-variable, and change tab-width. The Emacs default is 8, but many editors use 4 instead.

Related

Copy text without including formatting characters that are not actually present

I have some formatting configured in vim for tabs, trailing spaces and line wrapping:
I have set mouse=v, I copy text by selecting it on the terminal and pasting it into another application. How can I configure vim so those formatting characters are not included into the copied text?
When you don't let Vim handle the mouse, it'll be the terminal that processes the text selection. For the terminal, any application is just driving the cursor and printing characters here and there. It doesn't have any semantic background for the terminal contents; it's just lines and columns of characters.
So, you cannot expect the terminal to be able to detect line wrapping inside Vim. Neither can the terminal discriminate between actual text characters and surrounding visual information (the same applies to statuslines, number and fold columns, etc.)
Therefore, if you want access to the actual text, do the copying through Vim; it has the registers * and + for the X selection and system clipboard, respectively. For these to work, certain preconditions need to be met. There are plenty of related questions here and elsewhere on the Internet (depending on your OS, terminal, and how and what version of Vim you've installed).
If you really can't get this to work, you can :write (parts of) the buffer to a temporary file, and do the copy from there. If you connect to a different host, use Samba, scp, or ftp to transfer the file. As a last resort, temporarily disable the visual embellishments inside Vim, copy from the terminal, and undo hard wraps in the target application after pasting.
I created a Vim plugin to toggle linenumbers, listchars, etc. using a mapping: https://github.com/timakro/vim-copytoggle
Ingo Karkat's answer to use the clipboard feature of Vim is an alternative. I decided against it since debian packages Vim without the feature (the vim-gtk package includes it) and I don't want to set up X11 forwarding everywhere, and I don't want to install X11 libraries on headless servers. Also just selecting text with the mouse is more convenient for me. That though can also work using the clipboard feature by setting set mouse=a and set clipboard=autoselect,autoselectplus, see :help 'clipboard'.

Remove tab highlighting in vim

When I write .f90 or .f file I have the problem that vim always highlight the first number of empty columns with red See figure. I have tried to use :noh but did not work. If I use "set list" they disappear but then a lots of symbols appear.
My vimrc file can be see here
Tab isn't part of the Fortran character set, so a properly formatted Fortran source file shouldn't contain tabs. You might want to configure vim to replace tabs with spaces.

Prevent vim vertically split view resizing to 20 characters

I have files that I am comparing side-by-side using the vertical split functionality in gvim, and am sizing them to 4-5 characters wide. Whenever I focus on one of these files, gvim automatically resizes the file view to 20 characters.
How do I disable this functionality?
NOTE: I am running vim 7.4.161 on Debian Jessie.
In the split that you don't want to be resized you have to
:set winfixwidth
If you don't want vim to make splits equal everytime you split or switch to a window you can do the following:
:set noequalalways
Of course #René Nyffenegger solution of using 'winfixwidth' works well too.
For more help see:
:h 'ea'
:h 'wfw'

Gvim does not write tabs

In C++ files that I edit with Gvim I have noticed that code lines which are in inside blocks
(curly braces {})
although are being shown on the screen with the correct amount of tabs in Gvim
(i.e. plus one tab from the code which is outside of this code block)
when I open the same files with an another editor
like sublime text
that extra tab that must exist in every line inside the code block does not exist.
So after opening these files with a hex editor I noticed that Gvim does not write those extra tabs in the code blocks?
Why does this happen?
Is it because of cindent?
Also how can I fix this rather than auto-reformat every time?
I am pretty sure that vim will faithfully save all the characters that are in the buffer. Various options affect how tabs are displayed, and whether actual tab characters or spaces are used for indenting. You can check their values, and see where they were set (default, in your vimrc file, or by some plugin) with
:verbose set ts? sts? et? sw? sta? ci? pi?
(These and more related options are grouped together if you open an options window with :options and look at Section 15.) If you want to visually check where you have tab characters rather than spaces, you can :set hls and then search for tab characters (or :match Search '\t') or you can :set list.
If you try all that and you still think that vim is not saving what is in the buffer, then there are odd things to check, like whether you have any BufWrite or related autocommands.

Vim file misaligned when opened in text editor

I have a javascript file that I created in Vim and it looks fine, but when I open it in another program such as just a text editor, the indentations are much greater (like 10 times the space) and some lines are misaligned. The only thing I have relating to lines in my ~/.vimrc file are:
"set tab indentation to 2 spaces"
:set tabstop=2
filetype plugin indent on
Has anyone seen this behavior or know what could be the issue?
Your vimrc file is configured to show tabs as 2 spaces, but the way tabs are shown isn't the same in every program. Sometimes they're shown as 4, sometimes 8. A typical argument is to use multiple spaces instead of actual tabs, to make the file look consistent regardless of the text editor's tab settings, but at the cost of increased file size. A search for "tabs vs spaces" will yield plenty of arguments for both sides.
If you decide to use spaces, you could, for example, configure vim to insert spaces whenever you press the tab key:
:set tabstop=2
:set shiftwidth=2
:set expandtab
(from vim wiki)
The default tab spacing in many text editors is 8 spaces, not 2, so the indentations for any source code that contains tabs will appear much greater in those text editors.

Resources