Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mastering Vim

You're reading from  Mastering Vim

Product type Book
Published in Nov 2018
Publisher Packt
ISBN-13 9781789341096
Pages 330 pages
Edition 1st Edition
Languages
Author (1):
Ruslan Osipov Ruslan Osipov
Profile icon Ruslan Osipov

Table of Contents (12) Chapters

Preface Getting Started Advanced Editing and Navigation Follow the Leader - Plugin Management Understanding the Text Build, Test, and Execute Refactoring Code with Regex and Macros Making Vim Your Own Transcending the Mundane with Vimscript Neovim Where to Go from Here Other Books You May Enjoy

Build, Test, and Execute

This chapter will focus on version control and the surrounding process, as well as building and testing code. You will learn to do the following:

  • Working with version control (and Git in particular) if you haven't already
  • Learning to productively use Git and Vim together
  • Comparing and merging files with vimdiff.Resolve Git conflicts using vimdiff
  • Using tmux, screen, or Vim terminal mode to multitask and execute shell commands
  • Using quickfix and location lists to capture warnings and errors
  • Building and testing code using the built-in :make command and plugins
  • Running syntax checkers manually and by using plugins

Technical requirements

Among other things, this chapter will cover working with version control. Git is the version control system of choice for this chapter; however, the lessons learned are applicable across different systems. A section is dedicated to a quick-and-dirty introduction but, if you want to get the most out of version control systems, you may want to read up on the version control system of your choice.

Throughout this chapter, we'll be making changes to our .vimrc file. You can make these changes as you go, or download them from GitHub at https://github.com/PacktPublishing/Mastering-Vim/tree/master/Chapter05. Git installation and configuration instructions are also included in the repository.

Working with version control

This section will illustrate working with version control systems (often abbreviated to VCS) by using Git as an example.

Git seems to be the most popular version control system as of the time of writing this book. Suggestions in this section can be applied to whichever version control system you choose to work with (or, more likely, whichever VCS you're locked into).

Modern development is nearly impossible without version control and, if you're working with code, it's more than likely you'll have to deal with it. This section gives the reader a refresher on how to use one of the most popular version control systems today—Git. We then cover how to work with Git from within Vim, to make Git commands more robust and interactive.

...

Resolving conflicts with vimdiff

Often, during the development, you'll find yourself needing to compare some files—be it comparing different output or versions of a file, or dealing with merge conflicts. Vim provides vimdiff, a standalone binary that excels at file comparison operations.

Comparing two files

tmux, screen, and Vim terminal mode

Software development often involves more than just writing code: executing your binaries, running tests, and using command-line tools to accomplish certain tasks. That's where session and window managers come in.

Modern desktop environments allow you to have multiple windows, but we'll focus on how you can manage the tasks you need to accomplish in a single Terminal session.

tmux

tmux is a Terminal multiplexer: it allows you to manage multiple Terminal windows in a single screen.

If you're on a Debian-based distribution, you can install tmux using sudo apt-get install tmux. You can also build tmux from source, which is available from GitHub: https://github.com/tmux/tmux.

You...

Building and testing

As you work on your code, you will have to compile (in compiled languages, which does not apply to Python) it and run accompanying tests.

Vim supports populating build and test failures through quickfix and location lists, which we will cover in this section.

Quickfix list

You've already had a brush with a quickfix window in Chapter 2, Advanced Editing and Navigation, but let's dig a bit deeper into it.

Vim has an additional mode that makes jumping to certain parts of files easier. Some Vim commands use it to navigate between positions in files, such as jumping to compile errors for :make or search terms for :grep or :vimgrep. Plugins such as linters (syntax checking) or test runners use the...

Summary

In this chapter, you learned (or got a refresher on) how to use Git, including a quick brush-up on core concepts and setting up and cloning existing projects, and a rundown of the most frequent commands. You learned about vim-fugitive, a Vim plugin that makes Git a lot more interactive from inside Vim.

We covered vimdiff, a separate tool packaged with Vim made for comparing files and moving changes between files. We learned how to compare and move changes between multiple files. Furthermore, we got some practice at resolving nasty Git merge conflicts, which will hopefully make them less intimidating.

This chapter covered multiple ways of running shell commands when working with Vim, be it through tmux, screen, or Vim terminal mode

We also learned about (global) quickfix and (local) location lists, which can be used to store pointers to certain lines in files. We combined...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Mastering Vim
Published in: Nov 2018 Publisher: Packt ISBN-13: 9781789341096
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}