Accents in vim: Cannot write "â" - vim

I can't get "â" to be written. I can write "Â" though (carrot + capital A).
Any other accent can be written as in any other text editor.
Any suggestions?
Thank you in advance.

You may want to look at the :digraph comamnd in Vim. It will show you the combinations to use with <C-k> to make accented characters. In your case, you want <C-k> followed by a>.
Note: <C-k> means "Control + k" whereas a> means the letter "a" followed by a ">" (greater than sign).

If you are using a latin keyboard layout and are unable to directly type the accented character, check if there is any mapping using it:
:verbose imap â
If so, just remap the command to another key.

<C-K>a^ works for me in Vim 7.3.

You could use digraphs, as pointed out on other answers. But this kind of diacritical character is very common on some languages. If that is true for you, you could set the keymap option:
:set keymap=accents
The list of characters added by this option can be seen in $VIM\keymap\accents.vim.
That being said, this should be working without this option. It is possible that you are with some problem with the value your 'enconding' option, as mentioned here.

First look at digraphs, as mentioned before.
But just to be thorough, and because I haven't seen it mentioned yet, note that any unicode character at all can be inserted via <C-v>uXXXX<cr> (where XXXX is the hexadecimal code point number of the character.) More on this at :help i_^v
For a list of code point values for different characters, try:
https://en.wikipedia.org/wiki/List_of_Unicode_characters
Or use a handy Perl script called unum, which lets you search characters by name, and other fun stuff.
EDIT: markup fix

Related

Is there any way to enclose a variable with print() statement or any function in vim especially using vim vs code extension

suppose I have a variable named
a_variable
is there a surround or some combination of keystrokes which will do
print(a_variable)
or
print("a_variable: ", a_variable)
when my cursor in on the line where a_variable is defined ?
I could not find any relevant material on the web .
Any help is appreciated.
This answers is written with Vim in mind. Some, all, or none of it may apply to your specific Vim emulator so YMMV.
With the surround plugin
First case
You can position your cursor on a_variable and do:
ysiwfprint(<CR>
to obtain:
print(a_variable)
Second case
It is currently impossible to achieve with surround only.
Without surround
First case
You can position your cursor on a_variable and do:
ciwprint(<C-r>")<Esc>
Second case
The scond case is a variant of the first case where you insert the variable name two times instead of one:
ciwprint("<C-r>": ", <C-r>")<Esc>
Turn it into a mapping if you need to do it often.
See :help c, :help iw, :help i_ctrl-r, :help "".

Matching backticks using matchit --- possible?

I'm writing a lot of RST lately and I would like the % keystroke to match between grave accent (i.e. backtick) characters.
`The cursor is at the |vertical line`
and then hitting % moves the cursor as shown
`The cursor is at the vertical line|`
I have tried setting the b:match_words for the matchit plugin but that doesn't help.
Any tips appreciated.
Forgive me for tooting my own horn, but I am an expert on the matchit plugin.
Although it is designed to extend the built-in matching functionality, matchit extends it in several ways. For one, it allows you to match regular expressions, not just single characters. You can get very good results by using vim's start-of-word and end-of-word patterns:
:let b:match_words='`\<:\>`'
This certainly works on the one-line example you gave. Similarly, you might decide that the starting ` usually does not have a non-whitespace character before it, and the closing one is not followed by a non-whitespace character. (If that is too many negatives, then "This is markup" usually starts a new line or follows a space or tab; and it is usually followed by the end of a line or a space or tab.) Then you could use
:let b:match_words='\S\#<!`:`\S\#!'
The matchit plugin tries to live up to vim's design goals, including :help design-documented. The standard vim distribution includes both matchit.vim (the script) and matchit.txt in $VIMRUNTIME/macros/. You can either read the documentation there or follow the instructions at :help matchit-install and browse the documentation with :help.
Under :help b:match_words, it says,
Tips: Be careful that your initial pattern does not match your final pattern.
This is because, when you bang on the % key, the script has to be able to figure out whether it is on the starting pattern or the ending pattern. The only information it has to make this decision is what you have told it in b:match_words.
The matchit plugin is designed to work similar to the built-in % command and as such suffers some of the same limitations. In particular, from :help 'matchpairs':
Only character pairs are allowed that are different, thus you cannot
jump between two double quotes.
Thus, this works as expected (but not as you want):
:let b:match_words="`:'"
But this does not work:
:let b:match_words="`:`"
For some suggestions how to pair identical delimiters with matchit in common prose or markup files, such as rst, see my repository.

Delete surrounding whitespace in vim

I'm using the awesome https://github.com/tpope/vim-surround plugin to surround words with parenthesis, for example I often use: viws<space><space> to surround a word with spaces.
What I'm missing is the opposite of this, that is, deleting surrounding spaces around a word.
The most common use for me is function arguments like
foo(bar) vs foo( bar ) depending on code style.
Does anyone know a nice way to do this?
Note: This solution requires the surround plugin referenced in the question.
For your specific situation you could do the following:
cs()
This changes foo( bar ) to foo(bar), however, it is not a general solution to your problem.
I often productively procrastinate in search of vim plugins too, when I could just define a mapping for this.
nnoremap <leader>dd F<space>xf<space>x
EDIT more information
<leader> common key for user defined mappings (, is a good one)
dd combination to use (any other mnemonic one will suffice)
F<space>x search backwards for a space, then remove it
f<space>x search forwards for a space, then remove it
Maybe just BXElx in normal mode.
In fact, perfect solution for me is the mapping provided by #puk, but using the keys #sarnold expected in the first place (what one would expect from surround plugin if it implemented this).
This is:
nnoremap ds<space> F<space>xf<space>x

VIM: How to change the Showbreak Highlight color without using the NonText Color-element

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.

vim linebreak after hyphen with gq

Is there some way to configure vim's gq function so that it allows line breaking after a hyphen (in a compound word)? e.g.
twentieth-
century
And by the way, I'm not on my own laptop, but on one of the lab, which runs Windows, so any solution not using programs like par or fmt get bonus points :-) (though I'm also interested in solutions using these tools if this is not possible to do this using only vim -- at least I would be able to do it on my laptop).
Thanks in advance.
For the ASCII hyphen (0x2d), this isn't possible. If you're able to use Unicode, you can use the identically-looking Unicode variant (U+2010, cp. http://en.wikipedia.org/wiki/Dash) instead. This can be inserted via Ctrl-V (Ctrl-Q on most Windows installations of Vim), followed by u2010. Or define a digraph for it:
:digraph -- 8208 " hyphen, U+2010
With
:set formatoptions+=m
Vim will
Also break at a multi-byte character above 255.
Voila! If you need to persist the text as ASCII, you could even write mappings / a wrapper around gq that :substitutes the hyphens back and forth.

Resources