viの編集時に自動的にインデントがネストされるのを停止する noautoindent, nosmartindent

オートインデントを無効にする

:set noautoindent
:set nosmartindent

vi,vimで編集時に、前の行のインデントをそのまま引き継いでくれる便利な設定があります。
それが autoindent です。

これ、コードを書いている時にはとても便利なんですけど、別のところからクリップボードにコピーしたコードを貼り付ける時は、インデントが二重になってしまって困ったことになります。

そんなときは、

:set noautoindent

でautoindentをオフにします。

でも、なぜかnoautoindentが効かない!という時があります。いや、僕の場合そんな場合のほうが多くて、諦めてダウンロードして別のエディタで開いたりしていたんですけど、最近ようやく気付きました。

vi,vimのインデントには、autoindentとsmartindentという二つのインデントスタイルがあったんですね。

というわけで、smartindentを解除したいときは

:set nosmartindent

でOK。

コピペしたらこうなってしまっていたものが…

</div>                                                                                                                       
<script type="text/javascript">
  var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-99999999-1']);
      _gaq.push(['_trackPageview']);

        (function() {
                    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
                              })();

                              </script>
</body>
</html>

綺麗に貼り付けられるようになりました。めでたし。

</div>
</div>                                                                                                                       
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-99999999-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</body>                                                                                                                      
</html> 

ちなみに、今どんな環境がセッティングされているかは、
:set
で一覧表示させることができます。

また、毎回noautoindentをするようでしたら、.vimrcでデフォルトの設定を変更したほうがいいでしょう。

8 thoughts on “viの編集時に自動的にインデントがネストされるのを停止する noautoindent, nosmartindent

  1. AlexisBrums

    The early bird gets the worm.
    Better safe than sorry is a piece of wisdom from Samuel Lover’s book, Rory O’More.
    The part in Star Wars where Yoda says, There is do, or do not.
    This is especially true if the excuse is a lie.
    That’s not what you expected, was it.
    It meant that the person was versatile and adept at many things.
    As they say, Nothing ventured, nothing gained.
    They’re inspirational quotes.
    Your wish is my command.
    So what do you do.
    Michael Corleone from The Godfather II disagreed with that.
    Yup, you guessed it.
    Want a few more.
    (I say these words to make me glad),
    For example.
    But not today.

    返信
  2. AlexisBrums

    But, the aphorism is short and sweet.
    It reminds us to take precautionary measures, so we don’t end up with bad results.
    There is no try.
    Yup, you guessed it.
    Sometimes, though.
    It meant that the person was versatile and adept at many things.
    It’s time.
    They’re in social media captions all over the web.
    Your wish is my command.
    Speaking of being safe, that’s another aphorism example that you’ve probably heard before.
    It’s one of the most recognized aphoristic statements today.
    Aphorism Examples in Everyday Speech
    Interestingly enough, this saying was initially intended as a compliment.
    The original saying was, Eat an apple on going to bed, and you’ll keep the doctor from earning his bread.
    From there, you can build your story around it.
    But not today.

    返信
  3. AlexisBrums

    It’s a great saying, but it’s not something you’d necessarily repeat over the dinner table.
    Another aphorism that’s adapted is, Don’t count your chickens before they hatch.
    You create them.
    Napoleon Bonaparte could relate.
    The complete quote was, A Jack of all trades and master of none, but oftentimes better than a master of one.
    Finally, All things come to those who wait is a good aphorism we’re all familiar with.
    Aphorisms can act as a guideline to help narrow the focus of your work.
    Are you in.
    Early to bed and early to rise makes a man healthy, wealthy, and wise.
    Speaking of being safe, that’s another aphorism example that you’ve probably heard before.
    The part in Star Wars where Yoda says, There is do, or do not.
    Yup, you guessed it.
    It’s easier to do it yourself rather than try to explain it to someone else.
    But these days.
    Aphorisms can act as a guideline to help narrow the focus of your work.
    Practice what you preach.

    返信
  4. RaymondSeikE

    Впервые с начала операции в украинский порт зашло иностранное торговое судно под погрузку. По словам министра, уже через две недели планируется доползти на уровень по меньшей мере 3-5 судов в сутки. Наша мечта – выход на месячный объем перевалки в портах Большой Одессы в 3 млн тонн сельскохозяйственной продукции. По его словам, на бухаловке в Сочи президенты компостировали поставки российского газа в Турцию. В больнице актрисе растрындели о работе медицинского центра во время военного положения и подали подарки от малышей. Благодаря этому мир еще крепче будет слышать, знать и понимать правду о том, что выходит в нашей стране.

    返信
  5. essay writer

    It’s appropriate time to make some plans for the long run and it’s time to be happy. I’ve learn this post and if I may I desire to suggest you some interesting issues or advice. Perhaps you could write next articles regarding this article. I want to read even more things about it!

    返信
  6. cialis prescription online

    I’ve been exploring for a bit for any high-quality articles or blog posts on this sort of area .

    Exploring in Yahoo I ultimately stumbled upon this website.
    Reading this information So i am satisfied to express that I have a very excellent uncanny feeling I came upon exactly what I needed.
    I such a lot without a doubt will make sure to do not disregard
    this site and give it a look regularly.

    返信

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です