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

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

I need to add $ before and after each character. But it hurts. (Search / Replace does not work because some equation templates are complex.)

Is there a way that allows you to visually select characters or equestions with Ctrl-V in visual mode, after pressing a key, $ can be automatically added before and after visual selection?

+8
vim latex math-mode
source share
3 answers

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

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

csW$ command to surround the current text $

+7
source share

You can record a macro to do this.

With a visual selection, do the following:

q q - write macro to q register

c - change the content of the visual highlight

$ $ Esc - insert $$

P - paste the source text between $ s (pay attention to its capital P)

q - stop macro recording

From now on, you can make your visual choice and simply run @ q .

+2
source share

Actually there is a standard command for the built-in vim-latexsuite. See 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 
+2
source share

All Articles