Search code examples
linuxvimoutlinervimoutliner

How to insert code into a vimoutliner file?


How to insert code into a vimoutliner document (.otl)? Is there something like:

<code>
...
</code>

Solution

  • You can insert a "preformatted body text" block by starting a line with ;, e.g.:

    Hello world
        This is "Hello world" in Ruby
        ; def hello(name)
        ;   puts "Hello, #{name}!"
        ; end
    

    According to the docs:

    The preformatted text marker, ;, is used to mark text that should not be reformatted nor wrapped by VO or any post-processor. A post-processor would use a fixed-space font, like courier, to render these lines. A post-processor will probably not change the appearance of what you have written. This is useful for making text picture, program code or other format-dependent text.

    You can also use < for a "user-defined preformatted text" block, which allows you to give a "style" to the block (e.g. to label which language it's in):

    Hello world
        This is "Hello world" in Haskell
        <Haskell
        <hello :: String -> IO ()
        <hello name = putStrLn ("Hello " ++ name ++ "!")
    

    As implied by the docs, what actually happens to those text blocks depends to what you're doing with your outlines once written - if you're using some tool to process them into another form, you'd want to check what that tool does with preformatted text blocks. I use a custom-written tool that takes the user-defined preformatted blocks and outputs syntax-highlighted HTML <code> tags.