Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create short snippets in Vim?

Tags:

vim

I have recently started using Vim as my text editor and am currently working on my own customizations.

I suppose keyboard mappings can do pretty much anything, but for the time being I'm using them as a sort of snippets facility almost exclusively.

So, for example, if I type def{TAB} (:imap def{TAB} def ():<ESC>3ha), it expands to:

def |(): # '|' represents the caret 

This works as expected, but I find it annoying when Vim waits for a full command while I'm typing a word containing "def" and am not interested in expanding it.

  • Is there a way to avoid this or use this function more effectively to this end?
  • Is any other Vim feature better suited for this?

After taking a quick look at SnippetsEmu, it looks like it's the best option and much easier to customize than I first thought.

To continue with the previous example:

:Snippet def <{}>(): 

Once defined, you can expand your snippet by typing def{TAB}.

like image 476
guillermooo Avatar asked Aug 18 '08 22:08

guillermooo


People also ask

How do you make a snippet?

You can also insert a snippet when logging an activity or leaving a comment on a record using the HubSpot mobile app for Android. There are two ways to add a snippet: Type the # symbol into the text editor. Start typing the snippet shortcut, then select the snippet from the dropdown menu.

How do you insert a snippet?

To insert the snippet, choose Snippet > Insert Snippet from the right-click or context menu in a Visual Basic code file. Then, choose Code Patterns > Properties, Procedures, Events > Define a Property.

How do you make a snippet in Ultisnips?

i : In-word expansion - By default a snippet is expanded only if the tab trigger is the first word on the line or is preceded by one or more whitespace characters. A snippet with this option is expanded regardless of the preceding character. In other words, the snippet can be triggered in the middle of a word.


1 Answers

Snipmate - like texmate :) http://www.vim.org/scripts/script.php?script_id=2540

video: http://vimeo.com/3535418

snippet def       """ ${1:docstring} """      def ${2:name}:          return ${3:value} 
like image 110
SergioAraujo Avatar answered Sep 27 '22 19:09

SergioAraujo