user875367
user875367

Reputation: 313

editing latex in vim : how to change text to math mode

I am using vim-latexsuite to edit a latex file. The text is originally from google doc and there are many math symbols not written in math mode.

I have to add $ before and after each symbol. But that is painful. (Search/Replace does not work because some equation patterns are complicated.)

Is there a way that allows me to visually select the symbols or equestions using Ctrl-V in visual mode, then after pressing the key, the $ can be automatically added before and after the visual selection?

Upvotes: 9

Views: 1837

Answers (3)

cowlicks
cowlicks

Reputation: 1138

There actually is a standard command for this built into vim-latexsuite. See the vim-latex docs for macros here.

In addition the visual mode macros are provided:

    `(  encloses selection in \left( and \right)
    `[  encloses selection in \left[ and \right]
    `{  encloses selection in \left\{ and \right\}
    `$  encloses selection in $$ or \[ \] depending on characterwise or
                                          linewise selection

Upvotes: 3

Matthew Strawbridge
Matthew Strawbridge

Reputation: 20610

You can record a macro to do this.

With a visual selection, do this:

qq – record macro in register q

c – change the content of the visual selection

$$Esc – insert $$

P – paste the original text between the $s (note it's a capital P)

q – stop recording the macro

From then on, you can make your visual selection and just run @q.

Upvotes: 2

Jeff
Jeff

Reputation: 12418

I don't think there is any standard command for this, but you can use the surround.vim plugin to do this:

http://www.catonmat.net/blog/vim-plugins-surround-vim/

The command is csW$ to surround the current text with $

Upvotes: 9

Related Questions