Skip to content

paperlib/dotfiles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

.dotfiles

User friendly configurations

Vim for developers

You know how with vim you're supposed to... not use arrow keys, and use h, j, k, l instead, or not use windows/mac copy/paste shortcuts, but use y, y y, p and whatnot instead, sure... but guys, what the fuck? Vim is great and I want to use it like a normal developer, and whatever I can do to minimize muscle memory and brain power, I will do, so that I can then use that very memory and brain power somewhere else instead!

So here we go...

❤️ .vimrc: gimme normal shortcuts!

Let's start with I don't want to memorize yet another set of copy/paste shortcuts!
(great achievement.. I know..., no no..., I mean really... I know...)

  • Use Ctrl a to select all
  • Use Ctrl c to copy the selection
  • Use Ctrl x to cut the selection
  • Use Ctrl v to paste

    Btw since now this Ctrl v is mapped to paste, we use Ctrl q to switch to visual block mode.

    Note: even though Vim's documentation states Ctrl q can be used as an alternative to Ctrl v, terminals often have Ctrl q mapped to stty start, so if you do want to be able to use this alternative, you have to disable stty start by adding a stty start undef to your .bashrc or .profile

If we want to be able to copy something, we need to be able to select something. How about being able to select like you would in any other editor? Yes yes, I mean like you know, using shift arrow keys (again this is pure anathema I know...)

  • Use ⇧ Shift to start selecting from where you are upwards
  • Use ⇧ Shift to start selecting from where you are leftwards
  • Use ⇧ Shift to start selecting from where you are downwards
  • Use ⇧ Shift to start selecting from where you are rightwards

    Of course all of this combines with any of vim's language constructs, meaning:

    • ⇧ Shift + $ will select everything from the cursor position until the end of the line
    • ⇧ Shift + £ same as above but excluding the new line character
    • ⇧ Shift + G will select everything from the current line to the end of the file
    • ⇧ Shift + g + g to select from the current line to the top of the file
    • etc etc etc you got the point.

Now with all this stuff selected, how cool would it be if we could "move the selection around"? Like left and right to indent as we see fit, or up and down.. while matching the indentation of the block code through which we move! (courtesy The Primeagen here if you want to see it in action.)

  • Use to increase the selected block indentation
  • Use to decrease the selected block indentation
  • Use to move the selection upwards (adjusting to the current block's indentation)
  • Use to move the selection downwards (adjusting to the current block's indentation)

🍃 a few more shortcuts

You probably know how to open several files in vim at once, something like vim file.one file.two, right? But what most don't know - and by most I mean even seasoned professionals for whom vim is that horrible editor they just have to use -, so what most don't know is how to flip through those files once in vim (most would just quit :q the current file so that the next one pops up, or just quit all wholesale!)

So what if... we could flip through open files in vim with the simplest of shortcuts?

  • Use ⇥ Tab to switch over to the next open file
  • Use ⇧ Shift ⇥ Tab to switch back to the previous open file
    Alternatively you can also use ⌃ Control ⇥ Tab just like you do to flip through your Google Chrome tabs!

    and man... please don't tell me you're using tabs to indent, com'on

Next, let's flip through open windows:

  • Use ⌃ Control to move the cursor to the right hand side window
  • Use ⌃ Control to move the cursor to the left hand side window
  • Use ⌃ Control to move the cursor to the upper window
  • Use ⌃ Control to move the cursor to the lower window

    This is where things get tricky, have a look at keyboard.hacks.vim and yes this is where the "I told you so" h, j, k, l dude comes in... but guys - 23 years in - can we move to 21st century keyboards? I know this is coming from a guy who wants to use vim in the 21st century... WTF 😄 but yeah this is a good moment to remind you, please use nvim, everything is sooo much easier there.

Others:

  • Use Space + Space to toggle the file explorer netrw on the current working directory
  • Use esc + esc to clear highlighted searches

🔌 and finally, a few plugin related shortcuts:

  • tpope/vim-commentary
    • Use - to comment the current line or selection
    • Use - to uncomment the current line or selection

      yes that's the very same key, used to toggle comments

  • tpope/vim-fugitive
    • Use Space + g + g to git diff the current file
  • machakann/vim-sandwich only active in select V mode
    • Use " or ' to surround the current selection with double quotes or single quotes
    • Use [, { or ( to surround the current selection between carrets, curly braces or parenthesis
    • Use ], } or ) to achieve the same as above (just with the oposite characters)
    • if a text is already enclosed: placing the cursor between the enclosing and hitting any enclosing will switch it
      (ie. placing the cursor between "a text" and hitting ' will change it to 'a text')

Note: once you have cloned this repo, to initialize and update the above plugins (git submodules) do:
git submodule init; git submodule update

🌿 Other standard and very useful shortcuts:

  • Use z z to center the current line on the screen
    Equivalently use z t to align the current line to the top of your terminal, or z b for the bottom
  • Use ⇧ Shift g to go to the end of your file
    Equivalently use g g to do the opposite, ie. go to the top
    If you want more granularity use %, ie. use 7 5 % go to 75% down the file
    (see this stackoverflow question for more details: Moving to middle of huge file in Vim or gVim)
  • Use v i " to select everything between double quotes
    Equivalently replace " with ' or ( to select everything between quotes or parenthesis
    (again courtesy of this Primeagen short here)
  • Use v a " to select everything between double quotes, including the double quotes
    (ie. it's the same as above but with the surroundings included)
  • If you press : to enter command mode while you have a visual selection then Vim will automatically insert <',>' as a range indicating the selection. You can use that to do things like search & replace within the selection (learnt from this reddit comment).

above all, please remember: Vim is a language 👈
once you understand that, remembering any shortcuts will be so much easier
or as someone eloquently quipped on stackoverflow Your problem with Vim is that you don't grok vi.
(yes yes there is a logic to the whole madness 🥰 I promise)

🔧 install and use

Where these configuration files should go depends on which vim you are actually using (ie. vim or neovim)

Here I will assume you have cloned this dotfiles repository to your local ~/.local/dotfiles
eg. git -C .local clone https://github.com/paperlib/dotfiles

in that case for vim we have:

ln -sr ~/.local/dotfiles/.vimrc ~/.vimrc
ln -sr ~/.local/dotfiles/.vim ~/.vim

and for neovim:

mkdir -p ~/.config/nvim/after

ln -sr ~/.local/dotfiles/.vimrc .config/nvim/init.vim
ln -sr ~/.local/dotfiles/.vim/colors .config/nvim/colors
ln -sr ~/.local/dotfiles/.vim/plugin .config/nvim/after/plugin

🪟 Notes for Windows:

on Windows we can use mklink which is its equivalent to ln on *nix/macos machines (caveat: it does require admin rights though)

  • for vim on Windows its .vim directory is vimfiles (ie. link to vimfiles instead of .vim)
  • and for nvim setup an XDG_CONFIG_HOME environment variable to point to %HOMEPATH%\.config\nvim then symlink likewise:
mkdir "%HOMEPATH%\.config\nvim\after"

mklink    "%HOMEPATH%\.config\nvim\init.vim"     "%HOMEPATH%\.local\dotfiles\.vimrc"
mklink /d "%HOMEPATH%\.config\nvim\colors"       "%HOMEPATH%\.local\dotfiles\.vim\colors"
mklink /d "%HOMEPATH%\.config\nvim\after\plugin" "%HOMEPATH%\.local\dotfiles\.vim\plugin"

~ Nerd Fonts
are a quirky nighmare to get right for plain old "classic" Windows Command Prompt, so here a few hints:

otherwise do use Font Patcher via Docker:

docker run --rm -v <in>:/in -v <out>:/out \
       nerdfonts/patcher -s --careful --xavgcharwidth --complete

and 🃏 if you are running in WSL also note: clipboard registers + and * are slow on WSL2 #29712

🍿 Why vim?

Yeah, why the fuck vim?

Releases

No releases published

Packages

No packages published