mjbrownie / swapit

vim plugin: Extensible Keyword Swapper
39 stars 8 forks source link

Useful LaTeX swaps: #21

Closed kiryph closed 9 years ago

kiryph commented 9 years ago

Can you add following SwapLists for tex. 'tex_swapit.vim':

SwapList font_sizes tiny scriptsize footnotesize small normalsize large Large LARGE huge Huge
SwapList math_sizes displaystyle scriptstyle scriptscriptstyle textstyle
SwapList sectioning part chapter section subsection subsubsection paragraph subparagraph
SwapList documentclasses article report book letter slides
SwapList paper_sizes a4paper a5paper b5paper executivepaper legalpaper letterpaper
SwapList komaclasses scrbook, scrreprt, scrartcl, scrlttr2
SwapList column_style onecolumn twocolumn
SwapList page_style oneside twoside

Is it possible to change environments:

\begin{itemize}
\item
\end{itemize}

to

\begin{enumeration}
\item
\end{enumeration}

having something like SwapListEnv lists itemize enumerate description

mjbrownie commented 9 years ago

Hi, Thank you very much for the lists.

Regarding swapping environments. The short answer is no.

But in theory it is feasible.

The following code block handles the xml matches.

https://github.com/mjbrownie/swapit/blob/master/plugin/swapit.vim#L289-L316

It would be possible to hack the search patterns from '< foo >' to '\begin{foo}' but the code as is cant take in arbitrary delimiters.

Note this code is using matchit.vim which is often bundled in as standard I think.

http://www.vim.org/scripts/script.php?script_id=39

kiryph commented 9 years ago

Thanks for your feedback.

The Latex-suite plugin already offers with <Shift><F5> to change a surrounding environment by entering the name of the new one. I was wondering if this could even more simplified with your plugin.

However, I prefer lightweight plugins. So I wouldn't be in favour of extending your plugin, except your xml code would have been easy to adapt for it. Other plugins such as https://github.com/AndrewRadev/switch.vim could be used for this.

mjbrownie commented 9 years ago

No problems. It's always good to see the plugin being used :)

I wouldn't recommend adding this feature to the swapit plugin either. I'm happy it just has some filetype awareness.

As far as creating a lightweight solution to your specific problem. It doesn't sound too far removed from another block tag manipulation plugin I wrote which could be a guide. (you would need code to change the tag rather than delete them). It's very handy for django templates and It's better all round as it is using searchpair rather than relying on matchit.

https://github.com/mjbrownie/delete-surround-html/blob/master/after/ftplugin/html/delete_surround_html.vim (only ~100 lines to make sense of)

but it sounds like something the latex suite is handling.

kiryph commented 9 years ago

Can your 'delete-surround-html' plugin delegate ds commands to surround.vim if the third letter is not considered in 'delete-surround-html'?

mjbrownie commented 9 years ago

yeah that plugin only remaps 'dsh' and 'dsd' so ds(..anything else) will be passed through as is standard with all vim mappings.