15

Does Vim (with or without a plugin - I don't care) support strikethrough text at all? I've found myself keeping a running list of "TO-DO's" in it, and would like to be able to "cross off" my done items, via strikethrough text.

Thanks!

2
  • why not just change the highlighting for that line to differentiate it? Commented Dec 13, 2011 at 0:40
  • 2
    @abcd why not just change the highlighting for that line to differentiate Maybe because it isn't SO beautiful? :) it's just a point of the question, and author explicitly gave us to understand he wants to be able to "cross off" my done items, via strikethrough text. That's why he was looking for support strikethrough text in Vim. It is the wish and will of the question's author. Why disregard him? Anyway, if you really want to supply another way to "cross off" text in Vim, maybe it's better to do it with details (in Answers)? Commented Jan 26, 2017 at 12:52

8 Answers 8

22

If you're working with Unicode text, you may be able to achieve this using combining characters. The following article describes how this can be accomplished in gvim:

http://vim.wikia.com/wiki/Create_underlines,_overlines,_and_strikethroughs_using_combining_characters

You will need to make sure that the font gvim is using supports the appropriate characters, on Windows both Consolas and Courier New appeared to handle this correctly, but most of the others did not.

Sign up to request clarification or add additional context in comments.

4 Comments

I can't get this to work under Vim73 on XP with either Consolas or Courier New. enc=utf-8, so is fileenc. Still displays "garbage".
+1, works fine in my TODO file. Also worked in TODOs in my code, thanks :).
The combining characters don't work with Vim74 with Consolas in ConEmu under Windows 7 for me. :( Still, good answer, +1.
This worked great for me on OS X. Another tip for those using iTerm2 -- the struck through characters in my default font (Inconsolata) didn't look good at all, so I enabled the "Use a different font for non-ASCII characters" option. Courier looks significantly better.
13

Going for a highlighting simpler solution, I would use a Vim custom syntax highlighting rule so that, for example, text marked like this:

~~ text ~~

is displayed in a different color (eg. a darker text color if you have a dark background, or as dark reversed colors). Which would be, in vimrc:

au BufRead,BufNewFile *.txt   syntax match StrikeoutMatch /\~\~.*\~\~/   
hi def  StrikeoutColor   ctermbg=darkblue ctermfg=black    guibg=darkblue guifg=blue
hi link StrikeoutMatch StrikeoutColor

(where the au command is used to apply the rule to filetype .txt files only)

4 Comments

Personally I found this to be the best/easiest implementation. I don't need actual strikethrough, I just need some indication that I can map in my brain to strikethrough, and this was the most simple approach. I added to this with some remap commands to suit my own tastes and now it's perfect.
I also like this approach. @Raj, would you share your mappings?
@pschulz in addition to the syntax highlighting above, I added nnoremap <leader>st I~~ <ESC>A ~~<ESC>:noh<CR> nnoremap <leader>ust :s/^\~\~ //<CR>:s/ \~\~$//<CR>:noh<CR> Which allow me to easily add or remove the strikeout highlighting per line. I found I didn't need selection but you could easily add a mapping for that as well.
Sorry I couldn't preview the comment and I was trying to get the formatting right and then my comment edit timed out, but those nnoremap commands are on two separate lines.
8

You can create a (single) strikethrough character by appending the unicode "long strike overlay combining character" (0336) to the character. For example, to create a strikethrough "Z", enter (in input mode):

Z^Vu0336

(where ^V is CTRL-V).

You can use :s (substitute) to strikethrough a bunch of characters, for example, to strikethrough the current line:

:s/./&^Vu0336/g

Wikipedia links: strikethrough and combining chaaracter.

2 Comments

and just to avoid confusion for others :s/./&^Vu0336/g is how you type it, so it will look :s/./&̶/g
I like this! Thank you. But how does one remove the strikeout?
7

You can put this in your .vimrc

map _ a<C-V>u0336<Esc><Space>

and then the underscore character will "strikout-ize" whatever is under the cursor, analogous to how ~ (tilde) changes the case.

It works like this:

a - starts to append after the character under the cursor
<C-V>u0336 (stands for Control-V followed by u0336) - the strikout overlay combining character
<Esc> - exists append mode
<Space> - advances the cursor past the strikeout character

Vim assigns another meaning to the Underscore (_) character (see :help _) so you might want to choose another character (or sequence of multiple characters).

1 Comment

In order to strike out an entire section of visually selected text, try: s/\%V\(.\)/\=submatch(1) . "\u0336"/g, where \%V makes the substitution operate on a selection and \= makes it possible to have unicode characters in the replacement string.
3

it works perfectly well with a unicode vim in a terminal.

Just put it in my vim vundle file:

https://github.com/crux/crux-vimrc/blob/master/plugin/unicode.vim

-nargs=0 Overline        call s:CombineSelection(<line1>, <line2>, '0305') command! -range -nargs=0 Underline       call
s:CombineSelection(<line1>, <line2>, '0332') command! -range -nargs=0
DoubleUnderline call s:CombineSelection(<line1>, <line2>, '0333')
command! -range -nargs=0 Strikethrough   call
s:CombineSelection(<line1>, <line2>, '0336')

function! s:CombineSelection(line1, line2, cp)   execute 'let char =
"\u'.a:cp.'"'   execute
a:line1.','.a:line2.'s/\%V[^[:cntrl:]]/&'.char.'/ge' endfunction

vnoremap  :Strikethrough<CR> vnoremap __ :Underline<CR> ```

Comments

1

There is a patch pending, to make this work in the gui. Unfortunately, this is currently burried in the todo list, so it will take I while, until it will be applied by Bram.

Comments

-4

no, vim doesn't support this. it's a text editor, not a WYSIWYG editor.

1 Comment

-1 Obviously your statement is wrong.
-7

If you are using Vim under a terminal, no you can't.

  1. highlight arguments for normal terminals

                                  *bold* *underline* *undercurl*
                                  *inverse* *italic* *standout*
    

    term={attr-list} attr-list *highlight-term* E418 attr-list is a comma separated list (without spaces) of the following items (in any order): bold underline undercurl not always available reverse inverse same as reverse italic standout NONE no attributes used (used to reset it)

    Note that "bold" can be used here and by using a bold font. They have the same effect. "undercurl" is a curly underline. When "undercurl" is not possible then "underline" is used. In general "undercurl" is only available in the GUI. The color is set with |highlight-guisp|. ~

However, under GUI, you can do so. Under 'guifont', we have the following:

  For the Win32 GUI                                       *E244* *E245*
  - takes these options in the font name:
          hXX - height is XX (points, can be floating-point)
          wXX - width is XX (points, can be floating-point)
          b   - bold
          i   - italic
          u   - underline
          s   - strikeout
          cXX - character set XX.  Valid charsets are: ANSI, ARABIC,
                BALTIC, CHINESEBIG5, DEFAULT, EASTEUROPE, GB2312, GREEK,
                HANGEUL, HEBREW, JOHAB, MAC, OEM, RUSSIAN, SHIFTJIS,
                SYMBOL, THAI, TURKISH, VIETNAMESE ANSI and BALTIC.
                Normally you would use "cDEFAULT".

    Use a ':' to separate the options.
  - A '_' can be used in the place of a space, so you don't need to use
    backslashes to escape the spaces.
  - Examples: >
      :set guifont=courier_new:h12:w5:b:cRUSSIAN
      :set guifont=Andale_Mono:h7.5:w4.5

7 Comments

And since guifont being global, how would you make only a portion of the text, stroken-out?
-1 Obviously your statement is wrong.
@bitmask - And your statement is even worse - it is useless. It adds no information why the above is wrong, no useful information as to the solution of the problem, and serves only as SPAM, which we are trying to minimize here. So please refrain from leaving comments of type "this is bad".
@ldigas: I included a link to the answer that falsifies the statement. I extremely rarely downvote and I consider it polite to always leave a note, why I did so. I believe downvoting without saying why is considered rude by most people.
If this answer is wrong, why is it (still) accepted? Can't moderators un-accept it?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.