last time i too often feel the need to write both ‘prose’ and ‘code’ stuff. my fav editor is vim and i’m using it for any file editing purpose.

unfortunatelly, it can be very uncomfortable to use the same vimrc for writing prose and code. when you are writing prose some plugins (or settings) which intended to use while writing code can make your ass burns (and vice-versa). you can use autogroup to deal with it, but it’s very inflexible and makes your vimrc looks ugly. you can also use filetype plugins, but as long as i can see, it’s inflexible too. also, actually i can be wrong with all this stuff and there is some more neat way to solve the problem instead of the next one.

the main idea is pretty simple - to split vimrc into three parts. the first part is the core, where i have stored the common settings. the second and third parts are depending on first part and they contain appropriate settings for writing prose or code. such splitting is very scalable and makes possible to manage the whole vimrc for such purpose instead of brainfucking with autogroup or filetype plugins.

if you are already interested in, you can find the sources at the end of note.

here is just the very-generalized description of steps and tips to get a working solution:

  • create three files: vimrc.core, vimrc.code, vimrc.prose. these files i have described above.

  • fill it with appropriate configuration stuff, move the common settings to vimrc.core and make others source it. these things are very simple to implement and you can get in trouble just with per-mode plugins. actually it can be solved easily if you are using dein.

  • setting up shell aliases sometimes can be handy. i have done it like that:

    alias vp="vim -u $XDG_CONFIG_HOME/vim/vimrc.prose"
    alias vc="vim -u $XDG_CONFIG_HOME/vim/vimrc.code"
  • to not care about current ‘mode’ in the most of situations, my vimrc now contains some logic to determine it and load appropriate config (generally it’s just sourcing vimrc.prose or vimrc.code). for now the logic just depends on file extension and maybe it will be nice to make it use filetypes but seems like it’s not so easy as i thought in the beginning. my variant looks so (yea, that’s whole vimrc):

    let s:prose_types = ['md', 'txt']
    if index(s:prose_types, expand('%:e')) != -1
      source $XDG_CONFIG_HOME/vim/vimrc.prose
      source $XDG_CONFIG_HOME/vim/vimrc.code

check the sources here.

have a nice day.