1. 79

I’ve been vivid user of vim for few years now. Inspired on previous emacs topic, how do you organize your config and dotfiles for vim? Show us what your setup looks like. What plugins or plugin manager do you use. Screenshots would be a huge plus.

Thank you all!

  1.  

  2. 11

    I don’t expect much from my text editors, and I don’t like mods/plugins that are too invasive. So, my vim config is pretty sparse:

    syntax on
    colorscheme koehler
    set number
    set mouse=a
    set autoread
    map <C-O> <ESC>:w<CR>
    map <C-X> :q!<CR>
    set colorcolumn=80
    autocmd VimLeave *.go :!go fmt
    

    Basically, show line numbers, show me the 80 character width boundary, enable some syntax highlighting, and let me save and close using CTRL-O and CTRL-X, respectively (yes, it’s a remnant of my younger days when I used nano). I program in Go a lot, so the last line is to run the code formatter whenever I exit a file with the “.go” suffix

    EDIT: The following is just a commentary on me. I’m not suggesting any of it is a relatable developer experience for others, and I don’t suggest it’s the “right” way or “wrong” way to do anything.

    It’s probably worth mentioning why I don’t expect much from my editor, mostly because I’d like to hear y’all’s thoughts on the matter as well. The reason I don’t expect much from my editors is because I don’t ever want my editor messing with the way content is presented. I don’t want it collapsing functions, I don’t want it making code completion suggestions, I don’t want it collapsing comments, I don’t want it replacing symbols (like lambda or square root), etc.

    Every time I open a file, I see every printable byte of it, and it’s a constant memory refresher of either where code is located and/or how it’s implemented. You’ll notice that my vim config only contains directives that affect things around the code (i.e. line numbers, 80 character boundary). I read the code raw, I write the code raw, I debug the code raw. I think that always seeing all the code ultimately helps me understand the codebase better and leads to me writing better code.

    1. 3

      map <C-O> <ESC>:w<CR>
      map <C-X> :q!<CR>

      Do you know about ZZ ?

      1. 1

        I don’t think so. What is that?

        1. 2

          Write and quit.

      2. 2

        I would add filetype plugin indent on, use non-recursive mappings for single mode only, and use proper 'equalprg' with formatting before save, not on closing Vim.

        1. 12

          I have literally no idea what any of that means or why I would do any of that

          1. 5

            map is recursive (which mean that 2 mappings map a b and map b c will cause a to work like c, which can be unexpected) and non-mode-specific (which mean that it works in normal, visual, select, and operator-pending modes). It is better to use non-recursive mode-specific mappings, which in this case is probably nnoremap which will cause for example that if one day you decide to swap : and ; then these mappings will still work.

            'equalprg' is program that will be used to filter provided input when = command is used, more info can be found in help :h = and :h 'equalprg'.

        2. 2

          autocmd VimLeave *.go :!go fmt

          That will clobber the buffer if the file isn’t valid Go, right? Doing that on VimLeave seems awkward since you can’t actually correct it (as Vim will exit)?

          1. 2

            No, it will not, as this only run command, not filter the content (to filter it would need to be :%!go fmt /dev/stdin).

            1. 1

              Ah yeah, so it’s just so that you can see an error on invalid syntax when you exit Vim?

        3. 6

          My heavily commented vimrc: here

          Most impactful changes have been:

          • happy_hacking colorscheme (can be found in repo above)
          • autofolding only if the file is longer than winheight
          • using buffers and splits a lot, especially with fzf
            • hjkl move in text, arrow keys move among splits, ctrl+arrow keys move among tmux panes

          Most of the other changes create a nicer and richer visual interface.

          1. 5

            happy_hacking colorscheme (can be found in repo above)

            Oh wow, somebody besides myself uses my color scheme! I’m glad you like it! :)

            1. 1

              Thank you! I have your preface in the code, let me know if you want more attribution! I use it with a kitty terminal conf which modifies the 16 base colors a bit, but the color differentiation between token types is very nice.

              1. 2

                The preface is fine :)

            2. 5
                  autocmd FileType rust nnoremap + :wa<bar>:!cargo build<cr>
              

              If you use nnoremap <buffer> + [..] then that mapping will only apply to the Rust buffer, instead of globally. See :help map-<buffer>.

            3. 5

              I use neovim (for no other reason than because I’m a hipster or something), with vim-plug as my plugin manager. Here’s my init.vim. I try to keep plugins to a minimum, with the heaviest being coc.vim or vim-polyglot. I have a few things configured with my leader key, and the recommended configuration for coc, but most everything else is default behavior.

              1. 7

                I use neovim for the sole reason of deleting most of my .vimrc. I haven’t been disappointed. Mouse integration into console vim is 👌

                1. 2

                  Yeah, the in-buffer console is great! I don’t use mice that much when I’m coding, so I don’t even bother turning on mouse support. To each their own, of course.

                  1. 2

                    I don’t use the mouse for coding either. However, I use my computer completely differently when I’m having conversations about code. Vim keybindings can be really alienating when someone just wants to scroll to make a point.

              2. 5

                Lots of my configuration is over at https://git.jacky.wtf/me/vimrc. I keep it up to date as I work on a lot of projects of different language backgrounds across different machines.

                1. 4

                  This is some next-level factoring of config.

                2. 5

                  First and foremost I alias vi to whatever version is my primary.

                  I tend to go in waves from way to much configuration to a bare bones and back, vim commentary and surround are essentials though. Lately I’ve been trying out https://vim-bootstrap.com/ with minimal extra custom configuration, it’s been nice so far but a bit chatty oob (I like to run lint and formatting manually).

                  For the post year or two I’ve slowly transitioned to use neovim as my primary vi-implementation, a couple of years the differences were still breaking my flow to much but now a days I don’t notice any downsides with neovim anymore, especially when they fixed proper shell command execution with stdout buffer.

                  1. 4

                    I read a piece a while back (maybe linked here?) that described vim users as either “purists” or “exobrains”. I think I probably started in the former category and have drifted towards the latter, especially since I started using vimwiki for day-to-day notes.

                    I have notes on my note-taking habits and maybe should write a similar thing for vim in general. My .vimrc is reasonably well-commented, and I used to make efforts to keep it in a state that could be easily borrowed by new users, but I think it’s become entirely too idiosyncratic and dependent on the rest of my dotfiles to be a drop-in configuration for the uninitiated.

                    1. 4

                      I use neovim, with a fairly minimal/native setup. I use a bunch of tpope plugins, and have some custom configuration changes for filetypes and some custom plugins for working with the :terminal and some simple note taking. I use configuration directories as outlined by this post, and other places I’m sure. Here’s my config.

                        1. 3

                          My Vim config is getting a little stale, because I use IDEs a lot of the time now, and for security reasons, I don’t always get to take my plugins with me wherever I go. To deal with lacking plugins I have my .vimrc split between a “plain” vimrc and an additional plugin-enabled “(potentially) unsafe” vimrc which is hidden behind a default commented:

                          "if filereadable(expand('~/.vimrc.unsafe'))
                          "    source ~/.vimrc.unsafe
                          "endif
                          

                          My plugins:

                          • Vundle (plugin management)
                          • syntastic (syntax checking)
                          • YCM (autocomplete)
                          • vim-airline (status line)
                          • nerdtree (file navigation)
                          • rust.vim (Rust support)
                          • vim-gitgutter, nerdtree-git-plugin (git integration)
                          • todo.txt-vim (todo management)
                          • indentLine (show indent guides)
                          • ctrlp.vim (fuzzy file opening)
                          • majutsushi/tagbar (method/class/types in sidebar)
                          • flazz/vim-colorschemes, vim256-color (colorschemes)

                          Probably the most useful thing I have is “highlight whatever under cursor” which doesn’t require a plugin, and I can’t remember where I found this:

                          " Highlights the current word under the cursor
                          let g:highlight_current_keyword = 0
                          function! ToggleKeywordHighlight()
                            if g:highlight_current_keyword == 0
                              augroup highlight_keyword
                                au!
                                autocmd CursorMoved * exe printf('match IncSearch /\V\<%s\>/', escape(expand('<cword>'), '/\'))
                              augroup END
                              let g:highlight_current_keyword = 1
                            else
                              augroup highlight_keyword
                                au!
                              augroup END
                              match none
                              let g:highlight_current_keyword = 0
                            endif
                          endfunction
                          call ToggleKeywordHighlight()
                          
                          1. 3

                            Here’s my setup https://camo.githubusercontent.com/4061ee31956c149df7e10f817c32237edbaf9096/68747470733a2f2f692e696d6775722e636f6d2f4e4974546c65692e706e67

                            It’s a 500 lines config :D https://github.com/huytd/vim-config/blob/master/init.vim

                            The most important stuff is coc.nvim, which gave me the VSCode alike experience. Other than that, nothing is unreplaceable.

                            1. 5
                              • As this is Neovim then L37 is not needed
                              • autocmds should be wrapped in proper augroups
                              • L68 can fail, it is better to use <SID> for local function calls
                              • NeoVim automatically handles undodir, you just need to set 'undofile' and magic will happen (it will also use proper path instead of storing temporary data in config folder)
                              • L496-497 does nothing in NeoVim (:h t_xx)
                              • highlight commands should be ran in autocmd to update on colour scheme change

                              These are comments from quick review.

                              1. 1

                                oh man, that’s awesome, thank you so much for the feedback!!

                            2. 3

                              Well, for one thing, I’ve configured it to be invoked when I type emacs

                              1. 2

                                My configuration is fairly cluttered so I’ve listed some of the notable plugins below - not including syntax/languages. That said, I’d suggest anyone using Vim and wanting to step up their skills read Practical Vim if they haven’t already.

                                I use Neovim with the following:

                                • dracula/vim # Colorscheme
                                • w0rp/ale # syntax checker
                                • itchyny/lightline.vim # Status line
                                • tpope/vim-surround
                                • scrooloose/nerdtree
                                • mattn/emmet-vim
                                • airblade/vim-gitgutter
                                • tomtom/tcomment_vim
                                • junegunn/vim-easy-align
                                • jremmen/vim-ripgrep
                                • junegunn/fzf.vim
                                • dyng/ctrlsf.vim
                                • tpope/vim-fugitive
                                • ncm2/ncm2
                                • roxma/nvim-yarp
                                • tpope/vim-endwise
                                1. 2

                                  vi(1), not Vim but still - here’s my /etc/vi.exrc:

                                  set errorbells
                                  set filec=\^I
                                  set flash
                                  set iclower
                                  set ruler
                                  set searchincr
                                  set showmatch
                                  set showmode
                                  set verbose
                                  

                                  and a bunch of maps.

                                  P.S. ^I on the 2nd line is a TAB character.

                                  1. 2

                                    I’m cross-posting, so I’m biased, but my take is: Always use default, prefer nvi over vim, optionally vis.

                                    1. 2

                                      I wrote a blog about my .vimrc with explanations/screenshot: https://j11g.com/2018/03/10/my-vim-setup/

                                      1. 2
                                        1. 2

                                          I use a fairly customized Neovim (adopted it back when only it had async, kept it for floating windows and native Lua).

                                          Despite my customization and plugin use (and due to more effort than I’d care to admit), everything still loads fairly quickly (~46ms average on my work machine, ~60ms average on my laptop).

                                          The config is here: https://github.com/wbthomason/dotfiles/tree/linux/neovim/.config/nvim

                                          1. 1

                                            Mine dotfiles, these need a little of update as I have updated it a little and extracted :Scratch commands to separate plugin.

                                            1. 1

                                              We use this on all of our development machines: https://github.com/braintreeps/vim_dotfiles

                                              Our leader key is \.

                                              It has enough plugins to give you similar ergonomics in most languages. I’ve heard we inherited most of it from thought works, but I actually don’t know the history.

                                              The biggest thing about this is the consistency it provides. Anywhere from my home nas to the places I develop at work. If you don’t have a simple git clone and ./activate, you are losing ergonomics on any improvements you make to vim.

                                              Also, there is lots of tribal knowledgebase about how to do things and what’s possible, so that consistency is multiplied across people and not just hosts.

                                              1. 1

                                                I use NeoVim. Originally I switched because of its async support and its approach to development. I stayed for the additional features added over time (e.g. floating windows), and the wide range of GUIs available.

                                                Since a few months I have been using neovim-qt, before that I was using NeoVim in GNOME Terminal. I switched to neovim-qt because it had the lowest input latency of all the setups I tested (using various terminal emulators such as GNOME Terminal, Kitty, Alacritty, etc, as well as using various GUIs around for Linux). I suspect I may have some OCD issues, but I can’t stand a delay of more than 20 (ish) milliseconds when typing; GNOME Terminal can easily go all the way up to 120 ms.

                                                My dotfiles can be found here, and the theme I use for NeoVim can be found here. Some things worth highlighting:

                                                • I try to keep the number of plugins I use small; the ones I have now are ones I use every day.
                                                • I have my own simple workspace approach: just a bunch of .vim files that I source using :so. Here is an example, which opens an editor tab, and a separate tab with two terminals in it.
                                                • I usually have one tab for code, and one tab with a NeoVim terminal. This way I don’t need a separate terminal emulator.
                                                • I use NeoVim’s floating window support for FZF, which is pretty neat but takes some hacking to get going. Here is a sloppy recording of this in action.
                                                • I don’t use any fancy status lines and what not, as I find this far too distracting and frankly a waste of time. Instead I have as little UI elements visible, and run NeoVim full screen (except for the odd case of quickly having to edit a random file). It looks like this (if the font looks a bit fuzzy, that’s some weird thing that happens when taking screenshots using an HiDPI display, in reality it’s crystal sharp).
                                                1. 1

                                                  Pieced together over the last 15 years:

                                                  https://github.com/colindean/hejmo/blob/master/dotfiles/vimrc https://github.com/colindean/hejmo/tree/master/dotfiles/vim

                                                  My silly hejmo system will symlink those into ~ with a dot in the appropriate place.

                                                  Then I wrote this silly script to manage vim-plug:

                                                  https://github.com/colindean/hejmo/blob/master/scripts/plug

                                                  1. 1

                                                    I keep cutting from my vimrc the more I learn about what’s already in vim.

                                                    My plugins:

                                                    Other neat hacks:

                                                    • Visualise whitespace:
                                                      set listchars=tab:·\ ,trail:·,extends:»,precedes:«

                                                    • Line numbers, the right way:
                                                      set number relativenumber

                                                    • Make % smarter:
                                                      runtime macros/matchit.vim

                                                    And finally:

                                                    " When editing a file, jump to the last cursor position.
                                                    autocmd BufReadPost,FileReadPost *
                                                    \ if line("'\"") > 0 && line ("'\"") <= line("$") |
                                                    \   execute "normal! g'\"" |
                                                    \ endif
                                                    
                                                    " Highlight VCS conflict markers.
                                                    match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$'
                                                    

                                                    I’d love feedback!

                                                      1. 1

                                                        Here’s what I do on a newly installed machine:

                                                        touch ~/.vimrc

                                                        That’s it. That is what it takes to defuse the (IMnsHO) horrid default vim behaviour on Debian with gratuitous colours and ‘helpful’ things like using a mouse to position the cursor but not to copy text from the buffer [1].

                                                        As to why I don’t go overboard in customizing tools the reason is simple, I just learn to use the defaults so I can get around on any system I happen upon. As a corollary I can mention that I’m left-handed but play a right-handed guitar (upside-down, of course), for the same reason: I can play any guitar I happen upon instead of needing a customised version.

                                                        …of course the real reason I play that way is that I just did not know any better, never having had any lessons but just learning to play by myself without paying too much attention to the way things are supposed to be done… which is sort of the story of my life.

                                                        [1] it does this by setting mouse=a in /usr/share/vim/vimXX/defaults.vim (where XX is the version number). I could add mouse=c to that ~/.vimrc but… why bother, it does the right thing without any configuration just as long as you tell it to ignore the defaults by creating ~/.vimrc.

                                                        1. 1

                                                          At ~850 lines my vimrc is admittedly a bit ridiculous. But it’s well commented and so maybe someone will find a few nice tweaks for their own setup in there :-)

                                                          1. 1

                                                            I used to configure my applications heavily. Over time, I have learned to appreciate defaults and vanilla version of each application.

                                                            My Vim configuration is very straightforward, extended by only few plugins. Some highlights:

                                                            • syntax off which might be unusual. It takes a day or two of getting used to but I is absolutely worth it.
                                                            • I use my own colorscheme that has very little colors. I like it simple and I don’t use syntax coloring anyway.
                                                            • I use pathogen for plugins.
                                                            • my bundle directory (plugins) contains 4-5 directories, because as I said I try to make out the most out of vanilla Vim
                                                            • When programming, ALE is a must-have plugin for me.
                                                            • Depending on the language I am writing in, I install the right plugin for code formatting (i.e. vim-go or black for python) and maybe some additional, less important features (:GoDef in Go or :Isort in Python).

                                                            I used to use plenty of plugins. Nerd tree, gundo, fugitive and more. Those are great plugins, but somehow I am happier without using them.

                                                            1. 1
                                                              • With :h packadd you do not need Pathogen anymore
                                                              • It is better to use non-recursive mappings
                                                              • Wrapping autocmds into augroups allows you to resource your .vimrc on edits (and it is good practice)
                                                              • Setting 'directory', 'backupdir', and 'undodir' to /tmp can be dangerous as these files will be readable by anyone, so it can cause data leakage, maybe instead use ~/.local/share?
                                                            2. 1

                                                              Recently did a split of my vim config1 using the built in folder structure (plugins, ftplugin, etc.). Also am using dein.vim for lazy loading most file specific plugins.

                                                              Gladly taking advices.

                                                              1. 1

                                                                I try to keep my setup slimmed, but I tend to meander between languages and setups. Got a few handy scripts for managing plugins, though. https://git.sr.ht/~jzp/dotvim

                                                                1. 1

                                                                  https://github.com/myfreeweb/dotfiles/tree/master/vim

                                                                  A bunch of crap accumulated over the years :)

                                                                  1. 1

                                                                    My .vim directory is published at github.com/roryokane/dotvim/. Its vimrc file is 1143 lines long. I based it off the 150-line Vim Tips wiki example vimrc when I started using Vim 9 years ago, and added to it over time.

                                                                    My config has a simple structure: it’s a .vim folder containing vimrc and gvimrc files that you can link to your home folder using the commands in the README. Though my vimrc is one big file, headers in comments organize it into sections: must-have features, Vundle plugins, plugin settings, options, indentation options, mapping and commands, mappings that rely on other mappings, autocommands, and a todo list.

                                                                    Every setting change in my vimrc is accompanied by a descriptive comment. I also have many comments that explain the reason for the change or are TODOs for ways I could improve the behavior of that setting in the future.

                                                                    I use Vundle for plugin installation. Though dein.vim is newer and some praise it, I’m not convinced that the extra verbosity it requires is worth the small performance improvement.

                                                                    I do opt into Vim 8’s new defaults with source $VIMRUNTIME/defaults.vim (see :help defaults.vim), but I haven’t removed the redundant settings from my vimrc yet because I haven’t checked which of those defaults Neovim also provides. Though the only client I currently use is MacVim, which is based on Vim 8, I want to keep my vimrc compatible with Neovim to ease migration to it whenever a good GUI for it is finally available.

                                                                    Though I love Vim’s system of keybindings, I’m getting tired of living without or reimplementing common features of newer text editors, such as easy-to-use Find and Replace and proportional-width fonts. Because of the limitations of Vim I have been noticing, I haven’t been updating my Vim config much recently. (Emacs has similar problems – for example, unlike all other editors, it has no concept of untitled files with no location on disk, so I would have to set up that feature myself.) For large projects I would rather use one of the JetBrains IDEs and the excellent IdeaVim plugin for it, which can understand mappings in my vimrc. For small files that I want to quickly open, I am trying out VS Code. Its modern conveniences may make up for the lack of Vim-compatibility in its Vim keybinding emulations, which makes its Vim emulation worse than the editor’s regular keybindings.

                                                                    1. 1

                                                                      (blank)

                                                                      1. 1

                                                                        I have the vim part of my dotfiles here: https://github.com/winks/dotfiles/tree/91ff1446dca3edad89926473522f06762a40476d/vim

                                                                        To be honest I didn’t really touch this for years, just checking out the repo and everything works - I suppose I could get rid of most of it, except the settings in the main file and the colorscheme. I think every addon except fuzzy search is kinda not needed.

                                                                        1. 1

                                                                          pretty small and no plugins. the most useful parts (that’s not too common) are

                                                                          " block cursor in normal mode, bar cursor in insert mode, underline cursor in replace mode
                                                                          let &t_SI = "\<Esc>[6 q"
                                                                          let &t_SR = "\<Esc>[4 q"
                                                                          let &t_EI = "\<Esc>[2 q"
                                                                          
                                                                          " less intrusive colorcolumn (-> youtu.be/aHm36-na4-4)
                                                                          call matchadd('ColorColumn', '\%81v.', 100)
                                                                          

                                                                          set undofile and friends to persist the undo history across vim-restarts.

                                                                          1. 1

                                                                            inoremap jj <esc>

                                                                            1. 1

                                                                              Not using it but surely you can take something out of https://fisadev.github.io/fisa-vim-config/

                                                                              1. 1
                                                                                • Syntax highlight is usually off, I only turn it on occasionally;
                                                                                • Wrote a handful of dumb plugins myself. One of them gives me an Emacs-like scratch buffer, other adds keybindings for cscope/GLOBAL navigation, for example;
                                                                                • Statusline is always on;
                                                                                • Either running in a separate screen window or as foreground process that I control through ^Z and fg.
                                                                                1. 1

                                                                                  Other responses will be more useful if you want tips for your own config. Mine is overgrown.

                                                                                  I have neovim (arbitrarily), a shell alias of e = nvim -p, an old diff-based dotfile script, vim-plug with a dozen plugins I mostly forget I have, and a whole lot of cruft accrued over the years - commented-out experiments, arrow key mappings for a terminal I don’t even remember the name of, things like that. It’s 126 lines of mess, but it works, so I don’t need to spend any time tidying it up.

                                                                                  The ones I’d absolutely have to redo if I lost my config somehow are colorcolumn 81, cursorline, swapped ; and :, mouse and syntax turned on, and the various autoindent settings.

                                                                                  1. 1

                                                                                    Mine is pretty close to default, I have things for syntax highlighting and I use neovim. Also I build it configured with nix and I alias it as vi.

                                                                                    1. 0

                                                                                      I aliased vim to nano. I just need basic editing when I have a device with vim and wasting 5 minutes every time just to google ‘how to quit vim’ is wasting too much of efforts.

                                                                                      _>