Vim - keeping track of exact whitespace counts - vim

In both Eclipse and Notepad++, I have my text editors configured so a space has a semi-transparent dot in the center, which makes it easy to count whitespace. I prefer to use spaces instead of tabs in my text editing, and this feature is crucial when working with a whitespace-sensitive language like Python.
I have attached a screenshot with some dummy code in case my wording wasn't clear.
At any rate, is there any way to come close to this functionality in Vim (or GVim)? I suppose there is highlighting but that does seem a bit subpar. There's also good old fashioned math by looking at the column number. What are my other options?

Thes lines in your vimrc should give you an approximation but you won't get dots for normal or leading space: only trailing spaces. That's a Vim limitation.
set list
set listchars=
set listchars+=tab:»\
set listchars+=extends:›
set listchars+=precedes:‹
set listchars+=nbsp:·
set listchars+=trail:·
See :help 'list' and :help 'listchars.

I agree with romainl's answer, but would like to add a mention of the indent guides, which can colour indentation based on your current tab size settings.

Related

Highlighting and syntax trouble in vim using rmarkdown

I would like to get Vim to stop highlighting list characters (-,*) and heading characters (#) in rmarkdown. You can find a screenshot here: https://imgur.com/a/0YSB8V8.
This is happening when I set the file type to either pandoc or rmd. This is also happening no matter what terminal or colortheme I use.
I have the plugins: vim-pandoc, vim-pandoc-syntax, and vim-rmarkdown installed.
I would like to know a way to make the two characters just appear normally.
I would also like to know if there is a way to make italicized text in tables and headings appear italicized. As far as modifying the appearance of italicized text, I've tried using: hi Italic ctermfg=red cterm=italic in my vimrc, but that does not seem to affect the text in between asterisks (*) in rmd files. I admit I don't know much about the way that syntax works in Vim. Do I need to modify after/ftplugin/rmd.vim or runtime/syntax/rmd.vim? What is the difference between the two?
Any help would be appreciated!
Your syntax highlighter does not seem to recognize the bullet points, but thinks that they mark the beginning of an italic span. Maybe you have a clash of plugins. You could also try another highlighter (e.g. vim-polyglot, supports italics).
vim-pandoc-syntax uses the conceal feature (:h conceal). You can recolor the highlighting group Conceal to change the appearance of the replacement characters.
You can put changes to existing syntax files in .vim/after/syntax/rmd.vim. Files in syntax are executed when they are needed for the first time, but at most once per session. Files in ftplugin are executed every time the file type is changed.

How to start using vim with a non-english keyboard

I recently started using git, and by default it would want to use vim. I always wanted to look a bit deeper in this editor, but was always thrown back, only using it if for some reason (such as in case of a near dead Linux system) it was unavoidable. Even now I soon ended up reconfiguring git to use mcedit instead (which I use for programming).
The problem was that OK, I gave the command :help to see how I could start. Then in the help system it suggests me to jump to the subject interesting me using CTRL-]. And here I am lost. I have a Hungarian keyboard, and simply couldn't find where it excepted to find ]. So I can just scroll around in a list of topics I can not enter.
This is just the beginning: In general how much such "weird" combinations I may except? And how I could fix those up? An other problem with the Hungarian language is that it has a bunch of extra vowels which have to be mapped on the same amount of keys like English with it's 26 letters (there are 9 extra letters, so 9 keys "lost"!). Would this hinder the use of vim for writing Hungarian text (where I would require these keys to produce the language-specific vowels)?
How this problem could be solved in a way that if I happen to get an English keyboard (for which layout I guess vim was originally designed), I wouldn't have to re-learn the positioning of the keys? (Since I have no English keyboard around I can't try what happens. As I tried neither of the two keys on the left of 'P' would suffice for the CTRL-] combination while as far as the layouts I checked the second should be it. Of course my system is configured for Hungarian layout)
The language truly is irrelevant, I guess everyone having non-English keyboards might face similar problems. So how you work yourself around these?
Look at /usr/share/vim/vim74/keymap/ directory (in debian/ubuntu it is a part of the vim-runtime package), you should see a bunch of keymap files for different locales. Chose the one you like. In the example I use russian-jcukenwin.vim.
Add to your .vimrc file →
set keymap=russian-jcukenwin
set iminsert=0
set imsearch=0
highlight lCursor guifg=NONE guibg=Cyan
Now you can switch layout with Ctrl-^ keys. Note: layout is switchable when in insert-mode.
As you can guess the first line is the name of the file I mentioned. The next two lines sets the iminsert and imsearch in order to start writing the very first time with latin layout. In fact Ctrl-^ toggles them between 1 and 0. And the last line draws the caret with cyan color when layout is changed.
You can remap all vim defaults bindings with the map function.
For further information, you can read this tutorial
simple solution
you can switch to English layout when using vim:
setxkbmap us
and switch back to hungarian keyboard (hu) afterwards.
xkb
To show you another way:
the xkeyboard layout for hu keyboard is located in /usr/share/X11/xkb/symbols/hu. Try to compare the layout with /usr/share/X11/xkb/symbols/us.
There are also layout variants for hu keyboard than just default.
See my post here
If you want to do something advanced, you could also apply the english keyboard to the CAPS LOCK modifier LEVEL

Creating different tab pairs in vim

Vim newbie here.
I would like to be able to create tabs in Vim such that, for example, the tabs are at 4" left and 1.5" right for one type of section, 1.5"/1.5" for another, etc.
I know how to set tab stops, etc. but the trick here is I would like vim to recognize key combinations like shift-enter to go to one kind of formatting, plain enter to go to another kind, etc.
Is this even possible with vim?
TIA
I think you're confusing Vim with a word processor (like Word or Writer). There's no measurement in inches, no left / right margins, etc.
Vim's 'tabstop' option is a multiple of the width of a single space character that a <Tab> character (ASCII 0x09) expands to. This is fixed for the entire buffer (though you could use a set of :autocmds to change it in different parts of a buffer). Vim has no notion of paragraph text styles like a word processor, where you can define different styles. Vim only has a rather primitive :hardcopy command for printing.
If you need elaborate text formatting capabilities, Vim probably is the wrong tool, except if you choose to edit a source code document (like Latex, HTML, or Markdown), which is only compiled into a document (for those, like editing programming languages, it's actually well suited and powerful).
The vimtutor command (see :help vimtutor inside Vim) provides a good introduction to Vim's capabilities.
Check out these screenplay scripts. At least the first one contains custom tab widths as required in the traditional play formats. Perhaps they provide you the right idea on what's possible with Vim:
http://www.vim.org/scripts/script.php?script_id=2447 by Mike Zazaian
http://www.vim.org/scripts/script.php?script_id=1842 by Alex Lance

Using linebreak and line options at the same time

The documentation of linebreak says:
This option is not used when the 'wrap' option is off or 'list' is on.
I find this unsatisfactory. Is there a workaround to use certain listchars and linebreak?
My ideal .vimrc looks like this:
set linebreak
set list
set listchars=tab:▸–,trail:·,extends:»,precedes:«,nbsp:⍽
… so I’m not actually interested in eol:$, which is presumably the reason why list conflicts with linebreak (that’s just my assumption but I see no other plausible reason for them to conflict).
There’s a closely related question but in that the OP specifically wants the EOL mark, and the accepted answer addresses only this, so it’s not useful for me.
I would guess (but do not know for sure) that the current implementation cannot deal with the change of the displayed width when a Tab character shrinks to ^I (assuming it has no value in 'listchars'). In any way, I think Vim could be enhanced to do just what you want, though it might not be easy to implement. It might be worth to raise this request on the vim_dev mailing list.
There are little good workarounds; one could theoretically use the new conceal feature to emulate certain things of :set list, but it interferes with syntax highlighting and there's only one choice for highlighting.

My tab spaces do not align properly - VIM

I'm currently collaborating with a colleague on a project and we both use Vim to code.
However I've noticed that my code does not align the same way as his does and this causes some extra work on his part to re-indent the code.
So I turn on :set list to see to see the differences in tab space marked with (^I) and line endings marked with $.
For some reason when I type in (:list) mode my text does not indent or even show traces of tab markers (^I) similarly to his code. Why is this?
Here's an example of what I mean:
^I^I$this->greeting('Hello world');$
Whilst my code would show up like this in the same file:
$this->reply('Hello you');$
Notice the uneven space?
These are my vimrc settings:
set expandtab
set softtabstop = 4
set tabstop = 4
set shiftwidth = 4
I hope I'm on the right track, there may be some other problem that I haven't considered. Please do share your knowledge on the matter.
Sincerely,
Why
set expandtab means that typed tabs become spaces. This is fine, as long as you both agree on what a tab is; chances are they're using the Unix- (and, I think for historical reasons, vim-) default set tabstop=8.

Resources