Enabling and disabling word wrap automatically on different file extensions on Vim

前端 未结 3 1668
南笙
南笙 2021-01-06 01:47

I usually have to read .txt files with long lines, and at the same time edit some source file, and I like to see word wrap on the .txt files, and not in the ones that aren\'

3条回答
  •  悲&欢浪女
    2021-01-06 02:28

    There are two options that I can think of. Firstly, you can use an autocmd as suggested by Tassos:

    :au BufNewFile,BufRead *.txt set wrap
    

    See:

    :help autocmd
    

    An alternative (that is probably more applicable if you've got multiple settings as you have suggested): create a file in the after/ftplugin directory of your vim configuration folder (see below) called txt.vim and it will be sourced whenever you open a .txt file. You can put it in the plain ftplugin directory (rather than after/ftplugin), but it any built-in settings for .txt files will then not be loaded.

    Put any commands you want in this file:

    " This is txt.vim in the ftplugin directory
    set wrap
    set linebreak
    

    See:

    :help after-directory
    :help ftplugin
    

    Vim Configuration Folder

    On Windows this would typically be something like:

    C:\Documents and Settings\%USERNAME%\vimfiles\after\ftplugin\txt.vim
    

    (I think), or

    C:\Program Files\Vim\vimfiles\after\ftplugin\txt.vim
    

    or even:

    C:\vim\vimfiles\after\ftplugin\txt.vim
    

    On Linux, it is:

    ~/.vim/after/ftplugin/txt.vim
    

    For more info, see:

    :help runtimepath
    

提交回复
热议问题