我修改了我在此处找到的一些代码,用于乳胶。我证明了两种情况的所需输出。请看看
- 处理乳胶命令
- 处理乳胶环境
http://vim.wikia.com/wiki/wrap_a_visual_selection_in_an_an_html_tag
处理乳胶命令
给定:
elephant
- 视觉上选择"大象"
- 按F7
- 输入"测试"
输出:
test{elephant}
VisualcommandTagWrap
的示例代码
这适用于单线选择。我想让它适用于多行选择。只需使用视觉选择器选择要包装的文本,然后按F7。
" Wrap visual selection in a latex command tag.
map <F7> : call VisualcommandTagWrap()
function! VisualcommandTagWrap()
let tag = input("Tag to wrap block: ")
if len(tag) > 0
normal `>
if &selection == 'exclusive' "set selection=exclusive means position before the cursor marks the end of the selection vs. inclusive
exe "normal i\".tag."}"
else
exe "normal a}"
endif
normal `<
exe "normal i\".tag."{"
normal `<
endif
endfunction
处理乳胶环境
给定:
elephant
- 视觉上选择"大象"
- 按F7
- 输入"测试"
输出:
begin{test}
elephant
end{test}
VisualenvironmentTagWrap
的示例代码我不知道如何实现涵盖多行的功能。
其他示例
对于那些不熟悉乳胶的人。有两种情况可以满足乳胶命令和环境的要求。
Here is some visual mode selected text.
And another line of visual mode selected text.
命令情况:
- 类型函数键在.vimrc中定义为调用函数
- vim提示用户输入(例如,"请输入命令名称:")
- vim用命令选择。
结果:
inputstep2{Here is some visual mode selected text.
And another line of visual mode selected text.}
环境状况
- 类型函数键在.vimrc中定义为调用函数
- vim提示用户输入(例如,"请输入环境名称:")
- VIM环境环境的选择。
结果:
begin{inputstep2}
Here is some visual mode selected text.
And another line of visual mode selected text.
end{inputstep2}
步骤1:
您可以将所需的文本(如test
)存储在寄存器a
中。
:let @a='test'
(直到您更改它,它将保持不变并可以重复使用。如果您希望将其更改,则必须再次遵循该步骤。)
步骤2:然后,使用Visual选择(v
,V
或ctrl V
)选择文本,然后按Escape取消选择。
步骤3; 将光标保持在屏幕上的任何位置(最好在您要包围的线路中),然后按正常模式按s
。
将以下映射放入〜/.vimrc文件中。让我们创建一个映射以缠绕。
对于第一个示例:(开始和结束类型)
:nmap s '<Obegin{<C-R>a<ESC>}'>oend{<C-R>a}
对于第二个示例:(开始类型)
:nmap s '<O{<C-R>a<ESC>'>a}