Intermediate Vim Yet another editor – simple and powerful.

공개가능

Contents

Vim

Vim

It all started out innocently enough. You experimented with it once or twice in your first year of college, but Nano and Pico were easier – closer to what you had already been using during high school on the Windows machines and Macs. (..) Staying late one night to finish an assignment that was due at midnight, you happened to catch a glimpse over one of the quiet uber-programmer’s shoulders. Your eyes twinkled from the glow of rows upon rows of monitors in the darkened computer lab as you witnessed in awe the impossible patterns of code and text manipulation that flashed across the screen.

“How did you do that?” you asked, incredulous.

The pithy, monosyllabic answer uttered in response changed your life forever: “Vim.” 1

Vim

  • hjkl

Vim vs Emacs

2

Vi vs Vim vs Neovim

  • Vi: An editor by Bill Joy (1979)
    • which derived from “ex”, or extended (1976)
    • which derived from “em”, or editor for mortals (1976)
    • which derived from “ed”, or editor (1971)
    • which derived from “QED”, or quick editor (1965). 3
    • Wasn’t freely available until 2002. (Hence, the creation of Vim)
    • FTR, you aren’t running Vi with the vi command in Ubuntu – that’s vim.tiny
  • Vim *: Charityware by Bram Moolenaar (1991).
    • Vi IMitation 1.0 (1988) -> Vi IMproved 2.0 (1993)
    • Currently v8.0.0823.
  • Neovim: Community driven project (2015).
    • Built-in :terminal이 편하고 ycm, jedi-vim 등의 plugin이 안 멈춘다는 주변 증언이 있음.
    • Better codebase and community than Vim (which don’t affect the enduser)
    • 그 외에는 딱히 이점이 있을지…? Go for it if you’re an early adaptor.
    • Currently v0.2.0.

My current choices throughout these slides are marked with an asterisk (*).

Getting started with vim

$ vimtutor

Basic usage

Prerequisites

If you’ve went through vimtutor, your hands probably know this:

Yanking, cut/pasting, jumping to a particular character etc.

Frequently used commands (1/3)

Select current word:

*

Jump to matching bracket:

%

Jump to line 42:

:42

Jump to the third next slash:

3f/

Frequently used commands (2/3)

새로고침:

:e

처음 vim을 열었던 디렉토리의 파일들 보기:

:e .

현재 디렉토리 파일들 보기:

:Ex[plore]
      :Vex
      :Sex

Generate a number sequence:

:put =range(1,3)

Frequently used commands (3/3)

Delete blank lines:

:g/^$/d

Delete two paragraphs:

{2d}

Replace highlight:

y                   # first, yank to put into register
      :%s//new-string/g   # nothing in the first field, uses the las searched pattern

Show whole path of file:

1                   # get first buffer
      ctrl + g            # show file name, etc.

A conversation

# 2017-07-28
      16:04 L 그건 그렇고 ㅋ 혹시 vim 관련 자료 추천해줄만한거 있어?
      16:04 L vim 이제 막 익히기 시작한 사람들한테 추천해줄만한거 ㅋ
      16:05 S Vimtutor?
      16:05 L ...를 끝낸 사람들
      16:05 S Groking vim?

Groking vim

  • Q. I’ve heard a lot about Vim, both pros and cons. (..) What is the way you use Vim that makes you more productive than with a contemporary editor?
  • A. Your problem with Vim is that you don’t grok vi. 4
  • Vim is a “language”.
  • Examples:
    • dd
      • d (verb): “delete”
      • _ (subject): “this line”
      • == d_
    • yy
      • y (verb): “yank”
      • == y_
      • == ddP: “delete line and paste back into place”
    • yw
      • == “yank word”
    • y'a
      • == “yank from here to the line containing the mark named ‘a’”

Frequently used commands (revisited)

Delete two paragraphs:

{2d}
  • { (subject): “beginning of paragraph”
  • 2 (prefix): “two”
  • d (verb): “delete”
  • { (subject): “end of paragraph”

Delete blank lines:

:g/^$/d
  • :g: “globally execute on lines which match a regex”
    • cf. :% (==:1,$), :v (conVerse, those do NOT match the regex)
    • Funfact: :g/re/p – globally paste some regex – grep!
  • d: “delete”

Marks, Registers and Macros

  • Marks: 여러 개의 location 마크.
    • Usage
      • ma: ’a’라는 이름의 마크를 만든다.
      • 'a: Go to mark ‘a’
    • Protip: Show marks with vim-signature plugin
  • Registers: 여러 개의 클립보드.
    • :reg: view registers
    • "0p: paste register 0
  • Macros: 연속 명령 반복 수행

Vimrc

See https://github.com/e9t/dotfiles/blob/master/.vimrc

Indentation:

set expandtab
      set tabstop=4       # how many columns a tab counts for
      set softtabstop=4   # how many columns vim uses when you hit Tab in insert mode
      set shiftwidth=4    # how many columns text is indented with the reindent operations (<< and >>)

Time stamping:

,t
      ,d

Tablines:

set showtabline=1

Using plugins

Vim plugin managers 5

Usage tips

Vimming FTW

Global vimming on Mac OSX

See https://github.com/e9t/dotfiles/blob/master/.hammerspoon/init.lua

...

      hs.hotkey.bind({"ctrl", "shift", "cmd"}, 'h', 'home', keyCode('home'), nil)
      hs.hotkey.bind({"ctrl", "shift", "cmd"}, 'j', 'pagedown', keyCode('pagedown'), nil)
      hs.hotkey.bind({"ctrl", "shift", "cmd"}, 'k', 'pageup', keyCode('pageup'), nil)
      hs.hotkey.bind({"ctrl", "shift", "cmd"}, 'l', 'end', keyCode('end'), nil)

      hs.hotkey.bind({"ctrl", "shift"}, 'h', keyCode('left'), keyCode('left'), nil)
      hs.hotkey.bind({"ctrl", "shift"}, 'j', keyCode('down'), keyCode('down'), nil)
      hs.hotkey.bind({"ctrl", "shift"}, 'k', keyCode('up'), keyCode('up'), nil)
      hs.hotkey.bind({"ctrl", "shift"}, 'l', keyCode('right'), keyCode('right'), nil)

Was Vim actually not the problem?

(Ba)sh:

Tmux:

:wq 7

References

  1. Vim Creep

  2. https://unix.stackexchange.com/a/988/23595

  3. https://github.com/mhinz/editor-history

  4. productivity - What is your most productive shortcut with Vim? - Stack Overflow

  5. What is the difference between the vim plugin managers? - Vi and Vim Stack Exchange

  6. Oil and vinegar - split windows and the project drawer

  7. Stack Overflow: Helping One Million Developers Exit Vim - Stack Overflow Blog