How to Search in Vim

To search a file, type / (search forwards) or ? (search backwards) and enter the word. Normally, Vim will check for upper and lower letters. But you can set two different options in your configuration file (~/.vimrc or similar): set ignorecase or set smartcase Examples: pattern ‘ignorecase’ ‘smartcase’ matches ~ foo off - foo foo on - foo Foo FOO Foo on off foo Foo FOO Foo on on Foo \cfoo - - foo Foo FOO foo\C - - foo Other options:
Read more →

Vim Trick: Map CTRL+S to Save

Vim is very customizable. You can adjust key-bindings to your liking. For example, if you want to save a file, you’ll type :w or :up in command mode. But maybe you’re used to press CTRL+S to save a file? You could add a custom key-mapping to your configuration file (~/.vimrc or similar): nnoremap <silent><c-s> :<c-u>update<cr> The command works in normal mode. You can also bind CRL+S for other modes (visual mode and insert mode):
Read more →

Vim Undo And Redo

Today I learned about Vim undo and redo. Undo changes: in normal mode: u to undo latest change, U to undo all changes in Ex mode (command mode): :u to undo latest change Use :u {N} to undo a number of changes. For example, :undo 5 reverts the latest 5 changes. Redo changes: in normal mode: Ctrl+r in Ex mode: :re or :redo In Vim, undo is a tree:
Read more →

Pipe a Terminal Command to Vim

How can you run a command in your normal shell and then pipe it to Vim? A typical use case could be to run a find command and open the found file in Vim. Answer: You can use command substitution. vim $(find . -name example.txt) Here’s a useful command that I’m using now: nvim (fd | fzy) (I’m using fish as my interactive shell. Thus I don’t need to use $.
Read more →

Start Vim With Terminal Command

Today I learned that you can start Vim with a terminal command. Vim has the -c flag, which you can use for running an Ex command. The same is true for NeoVim, which also has an inbuilt terminal. So you can either start NeoVim inside the terminal like so: nvim +te or like that: nvim -c ‘:terminal’ The second option allows you to run another command afterwards. Example:
Read more →

Setup OCaml With NeoVim

How to use the NeoVim text editor as your Ocaml IDE I’ve always been interested in learning an ML language. But Haskell, the poster child of functional programming, has a high learning curve. OCaml and ReasonML (an alternative syntax for OCaml) are much more beginner-friendly. I started a free MOOC on functional programming with OCaml a few days ago. Thus, it’s the perfect time to set up my editor for OCaml development.
Read more →

Use A Lightweight Alternative to Vimwiki

As a Vim afficiando, you might use VimWiki as a solution for storing and organizing notes, to-do lists and journal entries. But VimWiki comes with some problems. It offers tons of features, but also heavily modifies your Vim installation. VimWiki overwrites common behavior, duplicates some functionalities, and can be hard to integrate with other plugins. Here are some alternatives to Vimwiki: Built-In Vim Joe Reynolds wrote an excellent article about managing notes and to-dos without plugins.
Read more →

Run Macro On Multiple Lines in Vim

Modern editors like VS Code or Sublime Text can use multiple cursors to edit code on more than one line. Vim doesn’t offer this functionality out of the box. But you may not need it. Today I learned how to run a macro to edit several lines in Vim. The method is useful when you have a similar structure on several lines, for example: <li class="link">About</li> <li class="link">Blog</li> <li class="link">Works</li> Add the script visual-at.
Read more →

Friday Picks 023

Read more →

Minimal Vim

Yesterday I trimmed down my vimrc - the configuration file for Vim. I admit that I can’t live without some plugins. So a “minimal Vim” is probably not possible for me. But if you’re interested, here is a good start: " Suggested Minimal Settings For Programming " Enabling filetype support provides filetype-specific indenting, " syntax highlighting, omni-completion and other useful settings. filetype plugin indent on syntax on " matchit.vim is built-in so let’s enable it!
Read more →