0

How does one enter (and view) italic text in vim?

I am interested in a keymap by which I can toggle to "italic mode" and back.

Example from the infopage of a certain vim plugin: see the text under the heading Text Styles

enter image description here

  • This depends on your terminal to a certain extent. I haven't managed to get it working myself, but Greg Hurrell has done a video on it here: youtube.com/watch?v=n1cKtZfwOgQ (intro is NSFW) – kinbiko Jan 20 '18 at 22:38
  • @kinbiko Greg Hurrel doesn't discuss entering italics. – Mussé Redi Jan 20 '18 at 22:52
  • Anyways, I'm surprised that a plugin hasn't been made yet to just do the simple word-processing tasks like italicizing and boldfacing within vim, via some construct or another. Txtfmt, the supposed solution plugin for this problem, seems extremaly laborious to install; you have to copy everything manually to the right vim directories. It doesn't even support pathogen or Vundle! I've given up on it for now. :) – Mussé Redi Jan 20 '18 at 22:56
  • Plugins don’t have to do anything special to support pathogen or Vundle. Have you actually tried installing Textfmt using either of them? Having said that, I’m not sure if that plugin is actually the answer for you, for the reasons @KarlYngveLervåg explains below. – Rich Jan 21 '18 at 14:51
  • Please don't cross-post. stackoverflow.com/questions/48361326/entering-italics-in-vim – Herb Wolfe Jan 22 '18 at 15:34
5

TLDR: There is no such thing. Vim edits plain text, and there is no "italic mode" or anything like that.


To be more specific: Vim is not a word processor. You are confusing file formats and how they render in typical WYSIWYG interfaces (like Microsoft Word) with a text editor, like Vim, Emacs, Notepad, etc. The latter, including Vim, only edits plain text regardless of the file format.

To be more nuanced: There are different file formats, and in some file formats, Vim uses syntax highlighting to show formatted text in e.g. italics. As an example, if you use Vim to edit a file in the Markdown format, you could (with the right setup) make text between pairs of * appear italized.


The question was updated with an example that indicates more about what is wanted. Here is a general remark: With a plugin like vim-notes, syntax highlighting is used to provide italics in Vim. To make this work, one either has to use a terminal that supports italics (and bold font and so on), or to use a gui variant such as gvim. Further, one has to have the conceal feature. Most Vim's tend to have this nowadays. Finally, to get the italized font, you need to use the specified syntax, which is _text in italics_ for this particular plugin.

  • In the example I included in my edited post, you can see some italic text under the heading text styles. I'm interested in how one can first enter the text, whereafter it is highlighted in italic. How would you do this using the Markdown format? After you include the text in a pair of * does vim then automatically highlight it? – Mussé Redi Jan 20 '18 at 21:53
  • If your terminal and your vim are set up properly, then yes - delimiting text in a file vim knows to be markdown between _ or * will render in italics. Since this is a nonstandard escape sequence, you likely have to sort it out yourself. For instance, my .vimrc for iTerm2 terminals includes set t_ZH=<1b>[3m \n set t_ZR=<1b>[23m (<1b> being a literal escape). – brhfl Jan 21 '18 at 4:38
  • I updated the answer. The point is that text is rendered in italics whenever one uses syntax that is highlighted in italics, e.g. _text_ for the notes plugin. But your terminal has to support it. And if one wants to conceal the _s you need to have a "modern" Vim (which most people have today anyways). – Karl Yngve Lervåg Jan 21 '18 at 9:00
  • @KarlYngveLervåg Okay. So you're saying that the plugin uses vim's built-in syntax highlighting feature to italicize text, and the conceal feature will hide the used escape sequence in accordance with the plugin? (I want to understand the steps between: entered text with literal escape sequences -> italic text -> visual removal of escape sequence (so the vim user doesn't see the escape sequence although it is persisent on the background.)) – Mussé Redi Jan 21 '18 at 15:08
  • 1
    To understand, you should read the Vim help sections on the syntax feature. See :h syntax. – Karl Yngve Lervåg Jan 21 '18 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.