¬ at the end of each line in vim - vim

this might be a silly question, but I couldn't find an answer to it. So, how can I add a ¬ to the end of each line of my vim files? It's more about styling, avoid trailing spaces, etc, like this colorscheme: http://ethanschoonover.com/solarized/img/solarized-dualmode.png
Thanks in advance.

set list
set listchars+=eol:¬
See :help 'list' and :help 'listchars'.

If you type in:
:set list
then vi should show you the end of each line with a $ character. Assuming all you want is to capture trailing space, that will do the trick. You can then turn it off with:
:set nolist
It actually gives you other things like making tabs visible as well, very handy when trying to track down Python problems with indentation, or things that print differently due to different tab width settings.
Of course, if you're looking to remove white space at line end, you can use regular expressions in your substitute commands:
:g/ *$/s///g

:set list listchars+=eol:¬
Or if you're just interested in seeing trailing spaces you could use:
:set list listchars+=trail:∙

Related

How to eliminate the text "[n] lines folded"

I would like a folded line to display only "-" characters: no text at all.
I have tried defining foldtext per examples here and in help:. I was able to eliminate the first line contents, which were extremely annoying and completely illogical to my thinking, but it still displays
---"3 lines folded"-------
for example.
(For me it is visually distracting and irrelevant...partly defeats the purpose of folding for me, which is to HIDE the collapsed section, not to HIGHLIGHT it, which is what this redundant message does.)
You do not say what you tried that did not work, but with
:set foldtext='---'
I see a line of dashes (full width) in place of the fold. If you want even less distraction than that, try
:set fillchars+=fold:\ foldtext='\ '
(There are two spaces after the first backslash.)
You can use following settings in your .vimrc:
set foldtext=EmptyFoldText()
function! EmptyFoldText()
return '-'
endfunction
Works fine on my vim.

How can I make vim show spaces?

I'm currently trying to switch from gedit to vim. I try to make vim look similar to gedit:
Especially, I would like to show spaces with dots.
I currently have:
There are some differences, but it looks quite similar (this is my current .vimrc file). But I don't get those dots for spaces.
How can I make vim show spaces?
I found some answers (like this one) that seem to suggest to replace spaces by a special visible character and then replace it back. I don't want to do this every time. I want to be able to open vim and see those spaces.
Show non-space whitespace with
set list
Additionally show spaces as . with
set lcs+=space:·
Turn it off with
set nolist
There are times when I absolutely need to see which whitespaces are tabs and which are true space characters, as well as when spaces appear at the end of a line.
When I'm using vim, I use:
:set list
(which I can turn off with :set nolist)
With :set list, literal spaces show up as spaces, tabs show up as ^I, and the end-of-line shows up as a bright-pink $. (So any blank space you see to the left of the pink $ you'll know is a true space character, and the blank spaces to the right of it is just the "nothing" between the end-of-line and the right side of the editor.)
It's ugly, but it works well.
I don't recommend using it all the time -- just those times when it is crucial to see where literal spaces and literal tab characters exist.
While you can't do exactly what you want here, if your reasoning is like mine, you're wanting to see those spaces because it helps verify proper indentation (do I have 2 spaces there, or is it 3?). For Vim >= 7.3, you can use the indentLine plugin to add a marker at each indentation. It's awesome.
To install if you're using Pathogen:
cd ~/.vim/bundle
git clone https://github.com/Yggdroot/indentLine
It may be worth using undercurl to do the job.
hi WhiteSpaces gui=undercurl guifg=LightGray
match WhiteSpaces / \+/
or you can put this in your .vimrc
autocmd ColorScheme * highlight WhiteSpaces gui=undercurl guifg=LightGray | match WhiteSpaces / \+/
Show leading spaces (indent spaces) using the above mentioned plugin indentLine.
If you use Vundle as plugin manager you can add Plugin 'Yggdroot/indentLine' to your .vimrc and then run vim +PluginInstall +qall to install the plugin.
Add the following two lines to your .vimrc to show leading spaces as ·.
let g:indentLine_leadingSpaceChar='·'
let g:indentLine_leadingSpaceEnabled='1'
Using the answers of J-L and Cedric Simon. Edit ~/.vimrc and add:
set lcs+=space:·
nmap <F2> :set invlist<CR>
imap <F2> <ESC>:set invlist<CR>a
and when you work with vim just pres F2
Vim has been providing the 'listchars' option to show Tab vs. Space, and space characters in critical places, i.e. trailing at the end of lines. In previous versions (when the question was written), it did not offer a modification for all spaces: a blank square is a space, period. Other answers provided some workarounds, though.
In current Vim versions, there are many space-related options; cp. :help 'listchars' for details.
You can get the effect seen in your screenshot; persist by putting that command into your ~/.vimrc:
:set list listchars+=space:. listchars-=eol:$
You don't need to install any plugin to this:
set listchars=tab:\|\
"set listchars=tab:\┊\
"set listchars=tab:\┆\
"set listchars=tab:\¦\
set list

What is the Dollar sign ("$") at the end of every line in Vim

I am relatively new to Vim. Whenever I start Vim using vim LearnRuby.rb, a dollar sign appears at every line.
Why?
:set nolist
will turn off special characters for the current buffer, such as tabs being presented as ^I and end of line characters showing up as $.
However, if it's doing that consistently when you run vim, you need to look into your .vimrc (or other startup file where applicable) and find out what's doing the set list that causes it.
Open ~/.vimrc and check its contents
If you see a line like this:
set list
It means, it will display $ in every line to mark the end of line.
Either remove it or use :set nolist command in the vi editor.
Obviously, the solution is not to :set nolist, as that also disables other characters like tabs and trailing spaces, which can be very useful. :set nolist would be the correct answer if you wanted all of the special characters gone.
If you just want a quick fix, you could add this to your vimrc instead:
set listchars+=eol:\ .
That is a backslash followed by a whitespace.
Alternatively you can set all the arguments of listchars, for exampleset listchars=tab:>\ ,trail:. and not include the eol argument, which determines the character used for end of line.
Refer to :h listhcars and :h list

How do I make vim syntax highlight a whole line?

I'd like to have vim highlight entire lines that match certain patterns. I can get all the text in a line to highlight (by doing syn match MyMatch "^.*text-to-match.*$"), but it always stops at the end of the text. I'd like to to continue to the end of the term, like highlighting CursorLine.
I've tried replacing $ with a \n^, hoping that would wrap it around. No change. (I didn't actually expect this would work, but there's no harm in trying.) I also tried adjusting the syn-pattern-offset (which I read about here: http://vimdoc.sourceforge.net/htmldoc/syntax.html#:syn-pattern). Long story short, adding he=he-5 will highlight 5 fewer characters, but he=he+5 doesn't show any extra characters because there aren't characters to highlight.
This is my first attempt at making a vim syntax and I'm relatively new to vim. Please be gentle and include explanations.
Thanks!
(edit: Forgot to include, this is a multiline highlight. That probably increases the complexity a bit.)
It's not very adaptive as the filename (buffer) and line to full row highlight needs to be explicitly identified, but apparently the sign command can be used:
It is possible to highlight an entire
line using the :sign mechanism.
An example can be found at :help
sign-commands
In a nutshell:
:sign define wholeline linehl=ErrorMsg
:sign place 1 name=wholeline line=123 file=thisfile.txt
Obviously, you should pick a higlight
group that changes the color of the
background for the linehl argument.
source: Erik Falor, vim mailing list
From the documentation on syn-pattern:
The highlighted area will never be
outside of the matched text.
I'd count myself surprised if you got this to work, but then again, Vim is always full of surprises.
could also try
:set cursorline
:set cursorcolumn
change colors like this:
:hi cursorline
:hi cursorcolumn
using the usual term=, ctermfg=, ctermbg= etc
see this answer
VIM Highlight the whole current line

How to stop line breaking in vim

I like that the long lines are displayed over more than one terminal line; I don’t like that vim inserts newlines into my actual text. Which part of .vimrc I should change?
Use
:set wrap
To wrap lines visually, i.e. the line is still one line of text, but Vim displays it on multiple lines.
Use
:set nowrap
To display long lines as just one line (i.e. you have to scroll horizontally to see the entire line).
I like that the long lines are displayed over more than one terminal line
This sort of visual/virtual line wrapping is enabled with the wrap window option:
:set wrap
By default this will wrap at the first character that won't fit in the window. This means it will wrap in the middle of a word if that's where the window boundary lies. To change it to wrap on word boundaries, you can also:
:set linebreak
This will cause wrap to only wrap at the characters in the breakat setting, which defaults to space, tab, and small set of punctuation characters.
:set breatat
breakat= ^I!#*-+;:,./?
I don’t like that vim inserts newlines into my actual text.
To turn off physical line wrapping, clear both the textwidth and wrapmargin buffer options:
:set textwidth=0 wrapmargin=0
I'm not sure I understand completely, but you might be looking for the 'formatoptions' configuration setting. Try something like :set formatoptions-=t. The t option will insert line breaks to make text wrap at the width set by textwidth. You can also put this command in your .vimrc, just remove the colon (:).
:set tw=0
VIM won't auto-insert line breaks, but will keep line wrapping.
Use :set nowrap .. works like a charm!
You may find set linebreak useful; with set wrap on this will wrap but only cutting the line on whitespace and not in the middle of a word.
e.g.
without linebreak the li
ne can be split on
a word
and
with linebreak on the
line will be
split on
whitespace only
set formatoptions-=t Keeps the visual textwidth but doesn't add new line in insert mode.
Its strange that such a simple setting would require this amount of 'hocus-pocus' to work.
To answer your question now, for me it seemed to work with the combination of the following:
:set wrap linebreak nolist
(this seems to prevent existing lines from breaking, just wrap.)
AND
set formatoptions=l
(this prevents new/edited lines from breaking, while += does not do it for me as other settings/plugins seem to find space and add their own options which override mine.)
If, like me, you're running gVim on Windows then your .vimrc file may be sourcing another 'example' Vimscript file that automatically sets textwidth (in my case to 78) for text files.
My answer to a similar question as this one – How to stop gVim wrapping text at column 80 – on the Vi and Vim Stack Exchange site:
In my case, Vitor's comment suggested I run the following:
:verbose set tw?
Doing so gave me the following output:
textwidth=78
Last set from C:\Program Files (x86)\Vim\vim74\vimrc_example.vim
In vimrc_example.vim, I found the relevant lines:
" Only do this part when compiled with support for autocommands.
if has("autocmd")
...
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
...
And I found that my .vimrc is sourcing that file:
source $VIMRUNTIME/vimrc_example.vim
In my case, I don't want textwidth to be set for any files, so I just commented out the relevant line in vimrc_example.vim.
It is correct that set nowrap will allow you to paste in a long line without vi/vim adding newlines, but then the line is not visually wrapped for easy reading. It is instead just one long line that you have to scroll through.
To have the line visually wrap but not have newline characters inserted into it, have set wrap (which is probably default so not needed to set) and set textwidth=0.
On some systems the setting of textwidth=0 is default. If you don't find that to be the case, add set textwidth=0 to your .exrc file so that it becomes your user's default for all vi/vim sessions.
I personnally went for:
set wrap,
set linebreak
set breakindent
set showbreak=ͱ.
Some explanation:
wrap option visually wraps line instead of having to scroll horizontally
linebreak is for wrapping long lines at a specific character instead of just anywhere when the line happens to be too long, like in the middle of a word. By default, it breaks on whitespace (word separator), but you can configure it with breakat. It also does NOT insert EOL in the file as the OP wanted.
breakat is the character where it will visually break the line. No need to modify it if you want to break at whitespace between two words.
breakindent enables to visually indent the line when it breaks.
showbreak enables to set the character which indicates this break.
See :h <keyword> within vim for more info.
Note that you don't need to modify textwidth nor wrapmargin if you go this route.

Resources