I'm using vim in Mac terminal. I want to have dashed lines in front of each line to indicate the tabs and indentations. Is there a way to configure this in .vimrc? The editor shown in the picture is sharelatex.
Many thanks!
Set listchars to that symbol (you might want one of these: ¦⁞⋮┆┊┋┇︙⸽) and a space:
set listchars=tab:¦\
That is "tab", followed by a colon, your desired character, a backslash and a space.
In addition, to see the effect, you have to set the list option:
set list
listchars can be used to set more characters to show in special places, e.g. eol to show a character at the end of a line, or trail to see trailing spaces. To set multiple ones, seperate them by commas:
set listchars=tab:¦\ ,trail:·
Related
Does anyone knows how to set this? Vim will display the indentation symbol when wrapping a new line, When input it will disappear.
These options will make sure trailing spaces are displayed as dots (or whichever other character you set instead). As you say, the dots disappear once another character is entered, as the spaces are then not trailing any more. Look through other listchars options as well, if you want to see e.g. tabs or other cool stuff.
set listchars=trail:·
set list
(See :help 'listchars', :help 'list')
After reading Vim regex replace with n characters, I've known how to replace tabs by spaces:
:%s/^\v(\t)*/\=repeat(repeat(' ',4),strlen(submatch(0)))/g
The command above allows me to replace n tabs at the beginning of each line with n four-spaces.
Now I want to inverse it: replace n four-spaces with n tabs at the beginning of each line, I think the command should be :%s/^\v( )*/\=repeat("\t",strlen(submatch(0)))/g, but it doesn't work: if there is one four-space, it will be replaced by four tabs (but I want to make it only one tab) after executing the command.
Besides, is it possible to get the length of tab of vim so that I can make the command as below?
:%s/^\v(\t)*/\=repeat(repeat(' ',getSizeOfTab()),strlen(submatch(0)))/g
You can get the value of an option in Vimscript by prepending &. So, the size of tab is &tabstop, or &ts. There's also &softtabstop (&sts), pick which one you actually care about.
Whereas you needed to multiply the number of spaces with size of tab, you need to divide the number of tabs. Then there's the remainder to take care of. So, first set your tabstop:
:set ts=4
Then you can convert from tabs to spaces and from spaces to tabs like this:
:%s/^\v(\t)*/\=repeat(repeat(' ',&ts),strlen(submatch(0)))/g
:%s#^\v( )*#\=repeat("\t",strlen(submatch(0))/&ts).repeat(' ',strlen(submatch(0))%&ts)#g
(changed the separator from / to # because I needed / for division :P )
However... it seems you're reinventing the wheel here. :help :retab! and :help 'expandtab'. First set tabstop as above, then:
:set et | ret!
:set noet | ret!
The first one will change tabs to spaces; the second one, spaces to tabs, according to tabstop.
When I split window, an ugly split line appears. I wonder why there is grey spaces between the '|' separator. I want only the '|'.
By the way, I use mac iterm2. I wonder some vim plugins cause this, but not sure.
In most fonts, the default pipe symbol (|) doesn't run the whole height of the display cell. In your screenshot, the spacing between lines is particularly pronounced.
You may either influence this in your terminal emulator settings (by changing fonts or reducing the line spacing), or in Vim by configuring a different character for the vertical separator:
set fillchars-=vert:\| | set fillchars+=vert:\
This replaces the default with a space (note the trailing space!) You can also try a Unicode character (should your terminal be able to display this); there are some vertical bars that run the whole length.
I’m trying to make vim look more similar to what I’m used to in Coda 2.
In my .vimrc I have this line:
set listchars=tab:➝.,extends:#,nbsp:.
That makes my whitespace look like this:
However, I’d rather those dots weren’t visible, so it’d look more like this:
I've tried using a space character, but I end up with this warning:
E474: Invalid argument: listchars=tab:➝
What character can I use that won’t be visible on the screen, and also won’t throw a warning?
You can escape the space character like this:
set listchars=tab:➝\ ,extends:#,nbsp:.
In listchars tab: takes to characters. Directly from the help file:
tab:xy Two characters to be used to show a tab. The first
char is used once. The second char is repeated to
fill the space that the tab normally occupies.
"tab:>-" will show a tab that takes four spaces as
">---". When omitted, a tab is show as ^I.
So you can just use a space instead of the dot that you are using for the second character, it does have to be escaped though: set listchars=tab:➝\ ,extends:#,nbsp:. to get the result you want.
I noted that the 'showbreak' symbol is highlighted with the highlight "NonText" color-element. NonText is also used for the EOL Characters.
I would like to keep the highlight-color for the EOL characters but want to change it for the showbreak symbol is that possible?
Another problem is that my showbreak symbol is not displayed.
I would like to use this symbol "↳" and put it in the linenumbers column (using set cpoptions+=n). I can't find out how to display the symbol and how to put a space after the showbreak symbol (between the text and the symbol).
Can anyone help me?
I don't think you're going to get highlighting to be different than the EOL character, at least I am not aware of a way to do that.
For the second part I can help with. I was able to get "↳ " to show up in my line number column with the following settings:
let &showbreak = '↳ '
set wrap
set cpo=n
Note that there is a space after the ↳. This lines up nice until you have > 9 lines in the file. If you wanted it to line up with the last character of the number column regardless of the number of lines I'm not sure what you're going to have to do.
Edit: I've recently written a proof-of-concept function for someone on IRC that highlights the first character on a line that has been wrapped with a different highlight group. It hasn't been tested much but it seems to work. Not exactly what you're looking for but maybe it's worth a look.
:help hl-NonText makes it pretty clear that you cannot have different colors for the 'showbreak' string and other non-text strings, of which eol is a member (see :help 'listchars'):
NonText
'~' and '#' at the end of the window, characters from 'showbreak' and
other characters that do not really exist in the text (e.g., ">"
displayed when a double-wide character doesn't fit at the end of the
line).
If you're willing to accept this limitation (#elliottcable) hi! link NonText LineNr will match the 'showbreak' string to the line number colors.
If you really wanted to get clever, as a compromise you could create a mapping or command to toggle between ':set list' and ':set nolist' that would also adjust the NonText highlight setting simultaneously.
If you use :set relativenumber (added in vim 7.3), :set showbreak=↳\ \ \ will reliably keep your 'showbreak' neatly lined up since the number width will not change as you navigate through the file. (This in addition to the :set cpo+=n and :set wrap #Randy Morris mentioned in his answer.)
You'll definitely need UTF-8 for the ↳ character, since it does not appear in other encodings. I'd strongly recommend you carefully document your encoding problems, with details about how to reproduce them along with your OS, its version, and the :version output of vim, and post them as separate questions. UTF-8 should be helping you wrangle multiple languages rather than being an impediment.