[HN Gopher] Five lines I put in a blank .vimrc
       ___________________________________________________________________
        
       Five lines I put in a blank .vimrc
        
       Author : jiannengli
       Score  : 57 points
       Date   : 2020-12-13 21:20 UTC (1 hours ago)
        
 (HTM) web link (swordandsignals.com)
 (TXT) w3m dump (swordandsignals.com)
        
       | gpvos wrote:
       | Tastes differ; I would _never_ set  'ignorecase' as a default,
       | and instead of 'number', which is only occasionally necessary and
       | most of the time is visually disturbing, I'd set 'ruler', or a
       | slightly more fancy 'statusline'. The most important one,
       | however, for me is 'set guicursor+=a:blinkon0'.
        
         | repsilat wrote:
         | Usually smartcase does what I want. The only time it doesn't is
         | when I really really want just lower-case characters, but it's
         | a very good heuristic.
        
       | ulzeraj wrote:
       | Kinda derailing the thread but might ask anyway, does anyone got
       | recommendations on dot files synchronization through personal
       | devices? I'm currently using a git+ss repo on a personal server.
       | 
       | I wonder if there are more convenient ways to do this.
        
         | dbolgheroni wrote:
         | Not the simplest way of doing this, but ansible might be an
         | option. IMO the advantage is being able to customize the
         | configuration file depending on the host OS, IP address,
         | attached filesystem, etc.
         | 
         | This is useful because sometimes you want to use the same
         | configuration file on different systems and they usually need
         | some customizations to adapt to each one, which can be done
         | automatically by ansible based on jinja2 templates.
        
       | leephillips wrote:
       | It's not enough. You should go all the way:                   set
       | nobackup         set nowritebackup         set noundofile
       | set noswapfile
       | 
       | I explain why at https://lee-phillips.org/badvim/
       | 
       | Also, it's best to just have one instance of Vim running, in
       | server mode, so you can send files to it from the command line.
        
         | bananicorn wrote:
         | Why would you not just set the location of the backup and
         | swapfiles to a fixed place in your system?
         | 
         | Try this:                   set backupdir=~/.vim/backups,.
         | set directory=~/.vim/swapfiles,.
         | 
         | It will only write in the current directory, if ~/.vim/backups
         | does not exist, and the dot is just there for portability, so
         | nothing breaks when using my vimrc on a new system.
         | 
         | Edit: Upon actually reading your blog-post, I understand at
         | least one reason - my options may not change the behaviour of a
         | file not being written to the correct inode, so you have a
         | point for some build systems.
         | 
         | I actually learned rather much reading this, thank you for
         | sharing!
        
           | leephillips wrote:
           | In fact, I think your idea is better, and I'll probably
           | switch to doing that some day, just in case one of these
           | files turns out to save me.
        
         | rendall wrote:
         | I laughed at the poetry of the line "I don't really want Vim to
         | litter my filesystem with all of these piles of nervous
         | energy."
         | 
         | Truth
        
       | lucb1e wrote:
       | The swap file saved my work a number of times. If you never use
       | recover and use Vim regularly, then go ahead and disable it; if
       | you haven't used it because you don't know how to use it or you
       | only rarely use Vim, then I'd encourage you to either try it
       | first or leave it enabled (as it is by default) until it becomes
       | a nuisance.
       | 
       | And like u/strogonoff, I also disable line numbers, but that's
       | just personal preference of course. For vim newbies, relative
       | lines might also be worth checking out: "set relativenumber".
       | 
       | One thing that really annoys me is :Wq or :Q not being commands.
       | Or typing only Q because you didn't hit the : and accidentally
       | entering ex mode. Or hitting F1 instead of escape. I can
       | recommend:                   command Wq wq         command WQ wq
       | command W w         command Q q         nnoremap Q <nop>
       | map <F1> <Esc>         imap <F1> <Esc>
       | 
       | Or for the non-newbie that has the 'too many terminals' problem,
       | "set title" will give your terminals more useful titles. There
       | are a bunch more things, of course, but these are the lines in my
       | vimrc that I think are useful to most people.
        
         | OJFord wrote:
         | > Or typing only Q because you didn't hit the : and
         | accidentally entering ex mode.
         | 
         | I'm not certain this is different (because I don't use either
         | deliberately) but I'm forever hitting q (not even trying to
         | quit) and entering some kind of macro recording mode.
         | 
         | I think the only reason I haven't yet disabled it like you
         | suggest (after doing it for years now) is that... Well 'some
         | kind of macro recording' does sound like it might be pretty
         | useful if I bothered to learn to use it!
        
           | scns wrote:
           | Macros are really nice, you can automate transforming several
           | lines of text with them. The Vim plugin in Intellij supports
           | them. Worth learning IMHO.
        
       | lilyball wrote:
       | Keeping the swapfile on is really helpful when I accidentally
       | open the same file in two different vim editors. But I do
       | recommend configuring vim to place swapfiles in a different
       | location, so you're not scattering them all over your disk.
        
         | climb_stealth wrote:
         | I actually went full on in the other direction and often have
         | multiple vim instances working on the same file. It feels so
         | much better than having to deal with swap file error messages.
         | With the below it reloads the file when the window gets into
         | focus. Super helpful when working in lots of terminal tabs. You
         | just have to get into a habit of saving after every change as
         | it conflicts otherwise.                   " check for and load
         | file changes when a window is focused. Together with         "
         | `noswapfile` this allows to edit the same file in multiple nvim
         | instances and         " have the changes reloaded whenever the
         | focus is changed.         autocmd
         | WinEnter,BufWinEnter,FocusGained * checktime
        
           | throwaway744678 wrote:
           | Can't you also auto-save when losing focus?
        
             | climb_stealth wrote:
             | Hah, I would think so. I'm not really familiar with the
             | scripting side and end up searching for solutions online.
             | 
             | See [0] for something to try.
             | 
             | [0] https://vim.fandom.com/wiki/Auto_save_files_when_focus_
             | is_lo...
        
       | ogre_codes wrote:
       | I guess it depends if you are doing systems admin or coding, but
       | when I'm coding, I've gotten very dependent on Fuzzy Search like
       | what Sublime Text introduced.
       | 
       | So for me, installing CtrP or FZF is pretty much mandatory (I've
       | settled on FZF). I know this is about config options, and this is
       | an extension, but for me, fuzzy search is pretty much essential
       | for coding once you get to a moderate sized code-base.
        
       | CalChris wrote:
       | I'm not going to _set noswf_. However, I run into the problem the
       | writer mentions all the time where I 'm opening an already opened
       | file. Is it possible to just switch to the already opened file?
        
         | kolme wrote:
         | No, because it's open in a different instance. You can use one
         | vim instance for all your editing needs and you'll never see
         | that error again.
         | 
         | And you probably should, because vim is rightfully warning you,
         | that you might lose changes made in the other instance.
        
         | allis10 wrote:
         | Yes, it is (at least on Mac in 2013):
         | https://youtu.be/aHm36-na4-4?t=749
        
       | phodge wrote:
       | `set confirm` is another great option to turn on all the time. It
       | will save you having to retype a command with the `!` added.
        
       | toxik wrote:
       | I'd prefer one line it and use the "long" names and add
       | nocompatible                   set nocompatible hlsearch
       | incsearch ignorecase number
       | 
       | then sane tabs                   set et sts=4 sw=4
        
         | pletnes wrote:
         | Why nocompatible?
        
           | kolme wrote:
           | Not necessary, AFAIK, unless you invoke vim using the alias
           | "vi". If you call "vim" it'll start in nocompatibe mode by
           | default.
           | 
           | The nocompatible mode means adding some features to vim
           | rendering it "incompatible" with the original vi. For example
           | in the original vi you can only undo the last action, with
           | compatible mode on vim will mimic this behavior.
        
             | toxik wrote:
             | Takes a whole stroke off your shell game!
        
         | JoshTriplett wrote:
         | I switch between enough different projects with different
         | coding styles that I have shortcuts to change between them:
         | set expandtab         set shiftwidth=4         set
         | softtabstop=4         function Spaces(...)             if a:0
         | == 1                 let l:width = a:1             else
         | let l:width = 4             endif             setlocal
         | expandtab             let &l:shiftwidth = l:width
         | let &l:softtabstop = l:width         endfunction
         | command! T setlocal noexpandtab shiftwidth=8 softtabstop=0
         | command! -nargs=? S call Spaces(<args>)         autocmd
         | BufNewFile,BufRead ~/src/linux/* T         autocmd
         | BufNewFile,BufRead ~/src/git/* T         autocmd FileType html
         | S 2         autocmd FileType tex S 2
         | 
         | This sets the default to 4-space indents, but lets me do :T to
         | switch to tabs (and does so automatically for Linux and Git
         | which use that style), or :S N to switch to N-space indents
         | (and automatically switches HTML and TeX to 2-space indents).
        
         | jiannengli wrote:
         | Thanks, I've edited the post to mention about putting
         | everything in one lien.
        
       | adrianmonk wrote:
       | Another approach to the swap file thing:                   view
       | foo   # opens read-only, no swap file         vi foo     # opens
       | read-write
       | 
       | Another benefit of this habit is, if you know you're not going to
       | want to modify a file, you can protect yourself against errors
       | like accidentally changing something and then absentmindedly
       | saving the file.
        
       | strogonoff wrote:
       | Why not one line?                   set hls ic is nu noswf
       | 
       | On a serious note, personally disabling line numbers is the first
       | thing I do in a new editor. Reduces visual noise--status line
       | usually shows current line number anyway, jumping to a line might
       | take a second and I found I don't need to know my line numbers
       | more frequently than once per month or so.
       | 
       | What I do like to enable in an editor is visible whitespace
       | characters (helps notice levels of indent, for example). In Vim
       | that can be accomplished with:                   set list
       | listchars+=space:*
       | 
       | (Might take some tweaking to make whitespace appear subtly
       | enough, depending on your color scheme.)
        
         | falcor84 wrote:
         | Interesting. The first thing I always do in a new is enable the
         | line numbers. I pair-program a lot and find them to be
         | invaluable when talking about the code.
        
           | strogonoff wrote:
           | I can see how line numbers would be immensely useful if I
           | ever pair program remotely.
        
         | Ancapistani wrote:
         | Line number are super helpful for navigating in vim, though.
         | :54 when you're on line 20 is much faster than any alternative.
        
           | repsilat wrote:
           | Some folk like `34d` so they don't need to press shift. And
           | sometimes set relative line numbers so they don't need to do
           | the subtraction.
           | 
           | Others just search for known text, which IMO is a habit I
           | need to get into. I "got" hjkl after I disabled the cursor
           | keys for a day, but I never followed up and disabled hjkl (or
           | maybe even w and b!?) to get super efficient.
        
             | strogonoff wrote:
             | I have never considered disabling hjkl, quite an
             | interesting idea.
        
           | strogonoff wrote:
           | I see, I suppose it depends on one's habits then. Personally
           | I'm used to roughly approximating relative jumps or using
           | search to arrive at the desired identifier, but then I
           | wouldn't call myself especially efficient.
           | 
           | The only time I find using :number is when I am exploring a
           | codebase elsewhere, e.g. using GitHub's web interface, and
           | want to jump to a particular line in Vim to make edits--
           | rarely happens.
        
           | adrianmonk wrote:
           | I would type "8j8j8j8jjj". I type "8j" (and "8k") a lot.
        
         | laumars wrote:
         | Funny you say that about the visual noise because as someone
         | who's dyslexic, I find line numbers actually help with
         | readability since it is easier for me to remember a number than
         | it is text.
         | 
         | I also find it especially useful in vi when working with config
         | files. I'm sure you are aware of this feature but in case
         | others aren't, in vi if you type numbers before a command, it
         | runs that commend _n_ times. So you can quickly copy or delete
         | multiple lines.
         | 
         | It just goes to show how deeply personal a preference a persons
         | code editor is.
        
           | strogonoff wrote:
           | Indeed, to your last sentence.
           | 
           | I use shift+v and a j/k relative jump to select a range of
           | lines, then do the operation. Which is undeniably the slower
           | way.
           | 
           | Didn't know how dyslexia affects this, I will keep that in
           | mind in case I happen to work with someone with it.
        
         | enriquto wrote:
         | set list listchars+=space:*
         | 
         | This adds a lot of clutter! It's better to show only
         | indentations (of course, using tabs):                   set
         | listchars=tab:+-
        
         | SoSoRoCoCo wrote:
         | Line numbers are great, until you try to cut and paste. But
         | then again, VI/M wasn't designed for GUIs.
        
           | UI_at_80x24 wrote:
           | I set F12 to toggle line numbers off/on. Very quick and
           | handy.
           | 
           | :nmap <F12> :set invnumber<CR>
        
           | strogonoff wrote:
           | I don't copy and paste, I just don't see the need for line
           | numbers. But then I also code with syntax highlighting off
           | about half of the time.
        
             | mjochim wrote:
             | Very interesting, I don't think I've ever talked to someone
             | who would choose to disable syntax highlighting. Do the
             | colors actively annoy you or is it just that you don't
             | care?
        
               | strogonoff wrote:
               | I find that not having highlighting to rely on forces me
               | to write more readable code. I might turn it on if I
               | happen to work on a hairy codebase under time
               | constraints.
               | 
               | Sometimes also colors can get distracting and I turn on
               | grayscale mode system-wide, which also doesn't play with
               | highlighting since text ends up being varying shades of
               | gray with not enough contrast against the background.
        
             | bawolff wrote:
             | Yay im not alone!
             | 
             | I've always found syntax highlighting super distracting,
             | but everyone i have met thinks im crazy.
             | 
             | Otoh i do love me line numbers.
        
           | mssundaram wrote:
           | I have the default register mapped to the system clipboard so
           | doing yank in vim I can paste into anywhere else - no need to
           | use the mouse or worry about line numbers
           | 
           | " mac clipboard {{ if has("clipboard") set clipboard=unnamed
           | endif " }} mac clipboard
        
         | jiannengli wrote:
         | Thanks, I didn't know about putting everything on one line.
         | I've updated the post to include this tip.
         | 
         | As for showing line numbers, I'm often doing this to read logs
         | on a remote VM. In those scenarios, having easy access to where
         | you are in the file is really helpful.
        
       | thih9 wrote:
       | These seem a bit too opinionated to me, mostly because of 'set
       | noswapfile'.
       | 
       | For me vim-sensible [1] has a more useful set of defaults
       | (although more than five lines). Also, the readme of that project
       | lists benefits of using a universal set of defaults.
       | 
       | [1] https://github.com/tpope/vim-sensible
        
       | BalinKing wrote:
       | In Firefox on macOS, the font fallback to "Apple Color Emoji" is
       | doing really weird things on my machine (like cutting off the top
       | of the number "5").
       | 
       | With that said, thanks for the tips--`set noswapfile` definitely
       | fits my workflow more than not.
        
         | jiannengli wrote:
         | Oh wow I had no idea that it looks so bad on Firefox. Thanks
         | for pointing it out, I will look for a fix.
        
       | pletnes wrote:
       | I have <<relativenumber>> but I've never touched swapfile.
       | Otherwise I have the same 5. Funny - I often felt vim's defaults
       | are almost intentionally archaic.
        
       | ogre_codes wrote:
       | I find it odd that you would use the short version of a command
       | in a config file. Brevity is important when you are doing
       | repetitive tasks. In a config file (or code), clarity is more
       | important that brevity. I know you could argue that you know VI
       | so well that you know these commands off the top of your head..
       | even so, it's particularly pointless to list them this way in a
       | blog where you have to turn around and explain them anyhow.
        
         | wdobbels wrote:
         | As discussed in the article, the point is to quickly set up vim
         | on fresh linux installations (e.g. virtual machines). For the
         | vim on your own pc, you would likely use the full version, in
         | addition to whatever extra config you prefer.
        
         | jiannengli wrote:
         | Yes, I definitely am much descriptive for the config file on my
         | personal computer. The configs I'm recommending here is more
         | for ephemeral machines that you are using just to look at files
         | (such as sshing into a VM that was created to run integration
         | tests). For those cases, being able to quickly type something
         | into the .vimrc and improve your experience is nice.
        
           | ogre_codes wrote:
           | I guess I don't see a lot of situations where I use systems
           | so casually that I don't have config options set. Even when I
           | was managing a bunch of systems I would push out the same
           | config on them all.
        
         | xwdv wrote:
         | On a new machine with a blank vimrc you'd probably just be
         | piping in these commands in from the command line so it's more
         | convenient if they are short.
        
       | bonquesha99 wrote:
       | nmap ; :
        
         | Isognoviastoma wrote:
         | Yes, that's so relaxing for little finger. In fact my minimal
         | vi config is                 :nnoremap : ;       :nnoremap ; :
         | :nnoremap Y y$       :vnoremap : ;       :vnoremap ; :
         | :vnoremap Y y$
        
         | airstrike wrote:
         | I go with nnoremap but yeah, this is the absolute first edit to
         | my .vimrc
        
       ___________________________________________________________________
       (page generated 2020-12-13 23:00 UTC)