3

I often use vim via terminal wrapper (e.g. gnome-terminal --disable-factory --command='vim /tmp/firefox12345.txt') to edit a textarea on websites, e.g. when writing this question.

Whenever I put in a block of code I wonder if I can somehow:

  1. visually select whole indented part of text in the current buffer
  2. open it in a new one
  3. change the filetype to match the syntax (e.g. javascript)
  4. edit, write and close it
  5. have vim "update" all my changes in the original buffer
6

You may want to try the Emacs-inspired NrrwRgn ("narrow region") plugin.

Should allow you to do exactly what you ask - but you'll probably have to set filetype=javascript (as an example) yourself (or perhaps run filetype detect) in the narrowed region.

  • vim-sleuth may be a good plugin to have in order to automatically pick up indentation settings. (github.com/tpope/vim-sleuth) – Brett Y Dec 10 '15 at 2:10
  • 1
    If NrrwRgn doesn't bring the filetype of the original buffer with it, perhaps it could be modified to do so... Although if it is often used to handle snippets of embedded code (of a different filetype) then perhaps an automatic filetype detect would be preferable. – joeytwiddle Dec 12 '15 at 5:01
  • 1
    One could probably use :h NR-hooks for this :) – VanLaser Dec 12 '15 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.