Luc Mosser
Luc Mosser

Reputation: 53

Managing split and multiple files with Vim

I'm brand new in the Vim game, and I'm looking for the best tips and shorcuts to manage multiple files projects. I saw people on the internet having a window with all the directory they have in there projects, and I'm really interested to find how they do that.

So feel free to put all your tips here.

Thanks

Upvotes: 1

Views: 284

Answers (1)

SergioAraujo
SergioAraujo

Reputation: 11800

One tip I can give you on making changes in a bunch of files is (based on vimcasts):

Let' say you have many markdown files and want to substitute the word ISSUE for SOLVED...

vim *.md

At this point you have all markdown files as arguments...

:args

So you have the argdo command, but in order to use it you have to set the hidden option (it allows you to go to the next file without saving the current one)

:set hidden

Now

:argdo %s/ISSUE/SOLVED/ge

The g flag makes the substitution in all occurrences at each line the e flag makes vim ignore files where the pattern does not appear

Another good thing is avoiding messeges during substitution of each file, we can add silent at the beggining

:silent argdo %s/ISSUE/SOLVED/ge

If you realize you made a mistake

:silent argdo edit!

Because the command edit! with exclamation makes the file get back to its original state

If you are sure you made it all correct

:argdo update

There are tons of good tips about dealing with many files on vim, you can visit the vimcasts original tip here.

More about the arglist here.

Another great tool to combine with vim is FZF, you can see a good video about it here.

When you have a couple of files opened you can also use the buffer list easily with this mapping (on your ~/.vimrc or ~/.cofig/nvim/init.vim)

" list buffers and jump to a chosen one
nnoremap <Leader>b :buffers<CR>:b<Space>

A shortcut you can use to get back to the last edited file is Ctrl-6.

In order to open you vim on the last edited file add this alias to your ~/.bashrc or ~/.zshrc

alias lvim='vim -c "normal '\''0"'

Open a new terminal and run

lvim

Upvotes: 4

Related Questions