├── README.rst ├── VimFlavor ├── addon-info.json ├── after └── ftplugin │ └── tex │ └── textobj-latex.vim ├── doc └── textobj-latex.txt └── ftplugin └── tex └── textobj-latex.vim /README.rst: -------------------------------------------------------------------------------- 1 | textobj-latex — Vim text objects for LaTeX code 2 | =============================================== 3 | 4 | This plugin provides text objects for common LaTeX stuff that are not 5 | conveniently described by builtin Vim text objects. 6 | 7 | Currently supported text objects are: 8 | 9 | === === ================================================ 10 | a i Description 11 | --- --- ------------------------------------------------ 12 | a\\ i\\ Inline math surrounded by ``\(`` and ``\)``. 13 | a$ i$ Inline math surrounded by dollar signs. 14 | aq iq Single-quoted text ```like this'``. 15 | aQ iQ Double-quoted text ````like this''``. 16 | ae ie Environment ``\begin{…}`` to ``\end{…}`` 17 | === === ================================================ 18 | 19 | Example 20 | ------- 21 | Let █ be the position of the cursor. 22 | 23 | Start with this:: 24 | 25 | \begin{document} 26 | \begin{frame}{Example} 27 | \begin{minipage}[t]{0.4\textwidth} 28 | The ``quick'' brown fox jumped█ 29 | over the ``lazy'' dog 30 | \(\sum_i n_i\) times this month 31 | where \(n_i\) is the number of jumps 32 | on day $i$. 33 | \end{minipage} 34 | \end{frame} 35 | \end{document} 36 | 37 | Press ``>ae`` to indent the minipage:: 38 | 39 | \begin{document} 40 | \begin{frame}{Example} 41 | \begin{minipage}[t]{0.4\textwidth} 42 | The ``quick'' brown fox jumped█ 43 | over the ``lazy'' dog 44 | \(\sum_i n_i\) times this month 45 | where \(n_i\) is the number of jumps 46 | on day $i$. 47 | \end{minipage} 48 | \end{frame} 49 | \end{document} 50 | 51 | Press ``Fq`` and then ``gUiQ`` to convert 52 | the double-quoted text to uppercase:: 53 | 54 | \begin{document} 55 | \begin{frame}{Example} 56 | \begin{minipage}[t]{0.4\textwidth} 57 | The ``█QUICK'' brown fox jumped 58 | over the ``lazy'' dog 59 | \(\sum_i n_i\) times this month 60 | where \(n_i\) is the number of jumps 61 | on day $i$. 62 | \end{minipage} 63 | \end{frame} 64 | \end{document} 65 | 66 | Press ``jj`` and then ``ci\`` to start changing the equation:: 67 | 68 | \begin{document} 69 | \begin{frame}{Example} 70 | \begin{minipage}[t]{0.4\textwidth} 71 | The ``QUICK'' brown fox jumped 72 | over the ``lazy'' dog 73 | \(█\) times this month 74 | where \(n_i\) is the number of jumps 75 | on day $i$. 76 | \end{minipage} 77 | \end{frame} 78 | \end{document} 79 | 80 | Type something, then ```` and ``jjh``:: 81 | 82 | \begin{document} 83 | \begin{frame}{Example} 84 | \begin{minipage}[t]{0.4\textwidth} 85 | The ``QUICK'' brown fox jumped 86 | over the ``lazy'' dog 87 | \(n_1 + \cdots + n_30\) times this month 88 | where \(n_i\) is the number of jumps 89 | on day $i$█. 90 | \end{minipage} 91 | \end{frame} 92 | \end{document} 93 | 94 | ``da$``, ``B`` and ``p`` moves the equation 95 | before its preceding word:: 96 | 97 | \begin{document} 98 | \begin{frame}{Example} 99 | \begin{minipage}[t]{0.4\textwidth} 100 | The ``QUICK'' brown fox jumped 101 | over the ``lazy'' dog 102 | \(n_1 + \cdots + n_30\) times this month 103 | where \(n_i\) is the number of jumps 104 | on $i$█day . 105 | \end{minipage} 106 | \end{frame} 107 | \end{document} 108 | 109 | ``i``, ``-th``, ``fx`` and you're done:: 110 | 111 | \begin{document} 112 | \begin{frame}{Example} 113 | \begin{minipage}[t]{0.4\textwidth} 114 | The ``QUICK'' brown fox jumped 115 | over the ``lazy'' dog 116 | \(n_1 + \cdots + n_30\) times this month 117 | where \(n_i\) is the number of jumps 118 | on $i$-th day.█ 119 | \end{minipage} 120 | \end{frame} 121 | \end{document} 122 | 123 | Installation 124 | ------------ 125 | Textobj-latex depends on Kana's `textobj-user`_, 126 | so you have to install it first. 127 | 128 | If you use Vundle_, add the following lines to your .vimrc:: 129 | 130 | Bundle 'kana/vim-textobj-user' 131 | Bundle 'rbonvall/vim-textobj-latex' 132 | 133 | and then run ``:BundleInstall`` from within Vim. 134 | 135 | If you use Pathogen_, clone both repos in your bundle directory:: 136 | 137 | cd ~/.vim/bundle 138 | git clone git://github.com/kana/vim-textobj-user 139 | git clone git://github.com/rbonvall/vim-textobj-latex 140 | 141 | If you don't use either: you should. 142 | 143 | I have included dependency information for Vim Addon Manager and Vim Flavor, 144 | but have made no effort whatsoever to test if they work properly. 145 | 146 | .. _textobj-user: https://github.com/kana/vim-textobj-user 147 | .. _Vundle: https://github.com/gmarik/vundle 148 | .. _Pathogen: https://github.com/tpope/vim-pathogen 149 | 150 | Author 151 | ------ 152 | Roberto Bonvallet 153 | 154 | License 155 | ------- 156 | Same terms as Vim itself. 157 | 158 | 159 | -------------------------------------------------------------------------------- /VimFlavor: -------------------------------------------------------------------------------- 1 | flavor 'kana/vim-textobj-user', '~> 0.3' 2 | -------------------------------------------------------------------------------- /addon-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "textobj-latex", 3 | "author" : "Roberto Bonvallet ", 4 | "repository" : { 5 | "type": "git", 6 | "url": "git://github.com/rbonvall/vim-textobj-latex" 7 | }, 8 | "dependencies" : { 9 | "textobj-user": { 10 | "type": "git", 11 | "url": "git://github.com/kana/vim-textobj-user" 12 | } 13 | }, 14 | "description" : "Text objects for LaTeX code" 15 | } 16 | -------------------------------------------------------------------------------- /after/ftplugin/tex/textobj-latex.vim: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /doc/textobj-latex.txt: -------------------------------------------------------------------------------- 1 | *textobj-latex.txt* Text objects for LaTeX code *textobj-latex* 2 | 3 | Author: Roberto Bonvallet 4 | License: Same terms as Vim itself (see |license|) 5 | 6 | 7 | INTRODUCTION *textobj-latex-introduction* 8 | 9 | This plugin provides text objects for common LaTeX stuff that are not 10 | conveniently described by builtin Vim |text-objects|. 11 | 12 | 13 | INSTALLATION *textobj-latex-installation* 14 | 15 | Requirements: 16 | - Vim 7.0 or later 17 | - Kana's |textobj-user| plugin, available at 18 | https://github.com/kana/vim-textobj-user 19 | 20 | If you use |Vundle|, add the following lines to your |vimrc|: 21 | > 22 | Bundle 'kana/vim-textobj-user' 23 | Bundle 'rbonvall/vim-textobj-latex' 24 | < 25 | and then run |:BundleInstall| from within |Vim|. 26 | 27 | If you use |Pathogen|, clone both repos in your bundle directory: 28 | > 29 | cd ~/.vim/bundle 30 | git clone git://github.com/kana/vim-textobj-user 31 | git clone git://github.com/rbonvall/vim-textobj-latex 32 | < 33 | If you don't use either: you should. 34 | 35 | I have included dependency information for Vim Addon Manager and Vim Flavor, 36 | but have made no effort whatsoever to test if they work properly. 37 | 38 | 39 | LATEX TEXT OBJECTS *textobj-latex-text-objects* 40 | 41 | Currently supported text objects come in pairs. The a-textobjs include its 42 | delimiters, while the i-textobjs don't, just like many of the builtin Vim 43 | text objects. 44 | 45 | *textobj-latex-paren-equation* 46 | a\ *textobj-latex-a\* 47 | i\ *textobj-latex-i\* 48 | Text objects for inline math surrounded by \( and \). 49 | 50 | *textobj-latex-dollar-equation* 51 | a$ *textobj-latex-a$* 52 | i$ *textobj-latex-i$* 53 | Text objects for inline math surrounded by dollar 54 | signs. 55 | 56 | *textobj-latex-single-quote* 57 | aq *textobj-latex-aq* 58 | iq *textobj-latex-iq* 59 | Text objects for single-quoted text `like this'. 60 | 61 | *textobj-latex-double-quote* 62 | aQ *textobj-latex-aQ* 63 | iQ *textobj-latex-iQ* 64 | Text objects for double-quoted text ``like this''. 65 | 66 | 67 | *textobj-latex-environment* 68 | ae *textobj-latex-ae* 69 | ie *textobj-latex-ie* 70 | Text objects for LaTeX environments. 71 | 72 | Text objects for environments assume that both the 73 | \begin{...} and \end{...} delimiters are on lines on 74 | their own. By following this simple convention it is 75 | much easier to support environments that accept 76 | parameters. 77 | 78 | The leading whitespace of the first line after 79 | \begin{...} is not included in the "ie" text object. 80 | This allows to retain the indentation when deleting or 81 | changing the content of the environment. 82 | For example, if '█' represents the position of the 83 | cursor: 84 | 85 | Before After typing "cie" ~ 86 | -------------------- -------------------- ~ 87 | \begin{document} \begin{document} 88 | Theorem: Theorem: 89 | \begin{equation} \begin{equation} 90 | x^2 + █ 91 | y^2 =█ \end{equation} 92 | z^2. \end{document} 93 | \end{equation} 94 | \end{document} 95 | -------------------- -------------------- ~ 96 | 97 | vim:tw=78:noet:ft=help:norl: 98 | -------------------------------------------------------------------------------- /ftplugin/tex/textobj-latex.vim: -------------------------------------------------------------------------------- 1 | " textobj-latex - Text objects for LaTeX code 2 | " Author: Roberto Bonvallet 3 | " GetLatestVimScripts: 2100 1 textobj-user 4 | " GetLatestVimScripts: 4506 1 :AutoInstall: textobj-latex" 5 | 6 | if exists('g:loaded_textobj_latex') 7 | finish 8 | endif 9 | 10 | call textobj#user#plugin('latex', { 11 | \ 'environment': { 12 | \ '*pattern*': ['\\begin{[^}]\+}.*\n\s*', '\n^\s*\\end{[^}]\+}.*$'], 13 | \ 'select-a': 'ae', 14 | \ 'select-i': 'ie', 15 | \ }, 16 | \ 'bracket-math': { 17 | \ '*pattern*': ['\\\[', '\\\]'], 18 | \ 'select-a': 'ab', 19 | \ 'select-i': 'ib', 20 | \ }, 21 | \ 'paren-math': { 22 | \ '*pattern*': ['\\(', '\\)'], 23 | \ 'select-a': 'a\', 24 | \ 'select-i': 'i\', 25 | \ }, 26 | \ 'dollar-math-a': { 27 | \ '*pattern*': '[$][^$]*[$]', 28 | \ 'select': 'a$', 29 | \ }, 30 | \ 'dollar-math-i': { 31 | \ '*pattern*': '[$]\zs[^$]*\ze[$]', 32 | \ 'select': 'i$', 33 | \ }, 34 | \ 'quote': { 35 | \ '*pattern*': ['`', "'"], 36 | \ 'select-a': 'aq', 37 | \ 'select-i': 'iq', 38 | \ }, 39 | \ 'double-quote': { 40 | \ '*pattern*': ['``', "''"], 41 | \ 'select-a': 'aQ', 42 | \ 'select-i': 'iQ', 43 | \ }, 44 | \ }) 45 | 46 | let g:loaded_textobj_latex = 1 47 | 48 | --------------------------------------------------------------------------------