Mastering Vim
eBook - ePub

Mastering Vim

Build a software development environment with Vim and Neovim

Ruslan Osipov

Buch teilen
  1. 330 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Mastering Vim

Build a software development environment with Vim and Neovim

Ruslan Osipov

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Mastering Vim, reviewed by Bram Moolenaar, the creator of Vim, covers usage of Vim and Neovim, showcases relevant plugins, and teaches Vimscript

Key Features

  • Expert Vim and Vimscript techniques to work with Python and other development environment
  • Accomplish end-to-end software development tasks with Neovim and Vim plugins
  • Understand best practices for various facets of projects like version control, building, and testing

Book Description

Vim is a ubiquitous text editor that can be used for all programming languages. It has an extensive plugin system and integrates with many tools. Vim offers an extensible and customizable development environment for programmers, making it one of the most popular text editors in the world.

Mastering Vim begins with explaining how the Vim editor will help you build applications efficiently. With the fundamentals of Vim, you will be taken through the Vim philosophy. As you make your way through the chapters, you will learn about advanced movement, text operations, and how Vim can be used as a Python (or any other language for that matter) IDE. The book will then cover essential tasks, such as refactoring, debugging, building, testing, and working with a version control system, as well as plugin configuration and management. In the concluding chapters, you will be introduced to additional mindset guidelines, learn to personalize your Vim experience, and go above and beyond with Vimscript.

By the end of this book, you will be sufficiently confident to make Vim (or its fork, Neovim) your first choice when writing applications in Python and other programming languages.

What you will learn

  • Get the most recent Vim, GVim, and Neovim versions installed
  • Become efficient at navigating and editing text
  • Uncover niche Vim plugins and pick the best ones
  • Discover multiple ways of organizing plugins
  • Explore and tailor Vim UI to fit your needs
  • Organize and maintain Vim configuration across environments
  • Write scripts to complement your workflow using Vimscript

Who this book is for

Mastering Vim is written for beginner, intermediate, and expert developers.The book will teach you to effectively embed Vim in your daily workflow. No prior experience with Python or Vim is required.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Mastering Vim als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Mastering Vim von Ruslan Osipov im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Computer Science General. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2018
ISBN
9781789344530

Transcending the Mundane with Vimscript

This chapter will cover Vimscript in all its glory. We will go into quite a bit of detail, but since we only have so many pages the coverage will be somewhat spotty. Hopefully, this chapter will get you interested in Vimscript enough to start your own research, and maybe you can use it as a reference as you build your early plugins and scripts. In this chapter, we will look at the following:
  • The basic syntax, from declaring variables to using lambda expressions
  • Style guides, and how to keep sane when developing in Vimscript
  • A sample plugin from start to finish—from the first line to publishing it online

Technical requirements

This chapter walks you through learning Vimscript by using numerous examples. All the examples are available on GitHub: https://github.com/PacktPublishing/Mastering-Vim/tree/master/Chapter08. You can create the scripts on your own as we're working through this chapter, or download the files from the repository to play around with.

Why Vimscript?

You've already encountered Vimscript when you worked on your .vimrc. What you may not have known is that Vimscript is actually a Turing-complete scripting language—there's no limit to what you can do. So far, you've used it to set variables and perform a few comparison operations, but it can do so much more!
You will learn how Vimscript not only helps you understand Vim configuration better, but lets you solve text editing problems you encounter by writing functions and plugins.
It's pretty awesome.

How to execute Vimscript

Vimscript is made up of commands you run in command-line mode, and really is just a sequence of Vim commands in a file. You can always execute Vimscript by running each command in command mode (the one you prefix with :), or by executing the file with commands using a :source command. Historically, Vim scripts have a .vim extension.
As you're following along with this section, you may want to create *.vim files to experiment in. You can execute the files by running this:
:source <filename>
A much shorter version of that is this:
:so %
Here, :so is a short version of :source, and % refers to the currently open file.
For example, I just created a variables.vim file to play around with Vim's variables. I could execute its contents with :so %:
Alternatively, I could run each command in command mode. For example, if I wanted to print the contents of a variable, g:animal, I would run the following:
:echo g:animal
I will do just that, as in, print cat into our status line:
Normally, I run longer scripts with :so %, and perform debugging operations through command-line mode (:).
Additionally, if you're entering commands in command-line mode, you'll stay in command-line mode if you enter a function or a flow control operator (such as if, while, or for):
In this example, I did not have to type : on every line. Additionally, each line gets executed as you hit Enter (as you can see by this is probably unix being printed on the screen).

Learning the syntax

Let's take a lightning-fast deep dive into Vimscript's syntax.
This section assumes you're comfortable with at least one programming language, conditional statements and loops in particular. If that's not the case, you will most certainly be better off finding a more extensive tutorial. Vimscript deserves its own book, and Steve Losh wrote just that: Learn Vimscript the Hard Way is easily the best Vimscript tutorial available (and it's free on the web!).

Setting variables

You've already discovered some basics of Vimscript syntax. To set internal Vim options, you use the set keyword:
set background=dark
To assign a value to a non-internal variable, use the let keyword:
let animal_name = 'Miss Cattington'
Vimscript doesn't have explicit booleans, so 1 is treated as true and 0 as false:
let is_cat = 1
Since we're assigning variables, let's talk about scopes. Vim handles variable and function scopes with prefixes, like so:
let g:animal_name = 'Miss Cattington'
let w:is_cat=1
Each letter has a unique meaning, in particular the following:
  • g: global scope (default if scope is not specified)
  • v: global defined by Vim
  • l: local scope (default within a function if scope is not specified)
  • b: current buffer
  • w: current window
  • t: current tab
  • s: local to a :source'd Vim script
  • a: function argument
In this example, g:animal_name is a global variable (it could also be written as let animal_name='Miss Cattington', but explicit scope declarations are always better), and w:is_cat is a window scope variable.
As you might remember, you can also set registers with let. For example, if you wanted to set register a to hold cats are weird, you could do this:
let @a = 'cats are weird'
You can also access Vim options (the ones you can change with set) by prefixing the variable with &...

Inhaltsverzeichnis