Mastering Vim
eBook - ePub

Mastering Vim

Build a software development environment with Vim and Neovim

Ruslan Osipov

Condividi libro
  1. 330 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Mastering Vim

Build a software development environment with Vim and Neovim

Ruslan Osipov

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

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.

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Mastering Vim è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Mastering Vim di Ruslan Osipov in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e Computer Science General. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
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 &...

Indice dei contenuti