Skip to content

Instantly share code, notes, and snippets.

@jbgo
Created October 28, 2015 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbgo/a520e8cabb77b729d59f to your computer and use it in GitHub Desktop.
Save jbgo/a520e8cabb77b729d59f to your computer and use it in GitHub Desktop.
Text editor shootout for KE LnL

Installation

brew install neovim

Then add the following to your ~/.bashrc

alias vi=neovim
alias vim=neovim

Opening Files

Open a single file via command line

vi file.rb

Open a single file from editor

:e file.rb

Open a directory via command line

vi dir

Open a directory from editor

:e dir

Or better yet, use the NERD Tree plugin: https://github.com/scrooloose/nerdtree

:NERDTree

Visualizations

Show/hide directory structure

Use :NERDTree to show the directory. You can also configure vim to open NERD Tree automatically when you open a directory.

Use :q in the NERD Tree window to hide the directory structure.

Increase/Decrease font-size

I use command +/- (provided by iTerm)

Navigate/Searching files

Open file from project by name

:e app/models/user.rb

Search files in project by name

The ctrlp plugin provides an awesome fuzzy file search. https://github.com/kien/ctrlp.vim

To open app/models/user.rb, you can type control-P, followed by modusr then hit enter.

Search files in project by contents

I use :Ggrep pattern, which is an incredibly convenient integration of the git grep command provided by the fugitive.vim plugin https://github.com/tpope/vim-fugitive

One handy thing about :Ggrep is it saves your search results in the quickfixlist, which you can open via :copen and then very quickly navigate through all of the search results.

When combined with the vim-qargs plugin, you can use :Qdo %s/search/replace/ge | update to perform a search and replace on the files matched by :Ggrep. https://github.com/nelstrom/vim-qargs

Navigating within file

  • Navigate to line in file: 123 gg
  • Navigate to start of line: 0 for column 0 or _ for first non-whitespace column in line
  • Navigate to end of line: $

Manipulating data within file

  • Delete line: dd
  • Delete word: dw
  • Insert line: o (insert below) or O (insert above)
  • Insert word: i word (insert before) or a word insert after
  • Save changes: :w
  • Close file and save changes: :wq
  • Close file and ignore changes: :q!

Manipulating multiple lines/words of data

This gets a little weird because you don't really highlight text in vim, but you can select it in visual mode.

Selecting next instance of highlighted text

  1. "yank" the highlighted text, y
  2. Start a new search /
  3. Use ctrl-R 0 to add the yanked test to the search and press Enter

Selecting all instances of highlighted text

Once you've performed a search, you can enable :set hlsearch or disable :set nohlsearch search term highlighting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment