Guidelines for Partners: AL Tips and Tricks in Visual Studio Code

This article will explain various ways to make your work with AL in Visual Studio Code more efficient.

 

1. VS Code Shortcuts

One of the most effective ways to improve your coding efficiency is to learn shortcuts for actions consistently used in programmers’ day-to-day coding.

 

Here is a list of useful shortcuts:

File/Project Visual Studio Shortcuts

This section is dedicated to shortcuts that you can use to search through folders, files, and symbols.

  • F1 – Show all commands (Window to search all commands such as “AL: Go!”, “Git” commands…)
  • Ctrl + J – Toggle panel visibility (panel is the section where you can see debug console, output …)
  • Ctrl + R – Folder selection window (Select existing project folder)
  • Ctrl + P – File selection window (Shows the current project folder’s file selection). Below you can see how to control this window:
    • Click – opens the file, and the close selection window
    • UpArrow/DownArrow navigates through the files without closing the selection window
    • Right arrow – open the selected file without closing the selection window.
    • When the selection window and file are open via the right arrow, you can enter @. Then it becomes possible to search through file symbols, as shown in the picture below.

AL

  • Ctrl + Enter (On file Explorer sidebar) – Opens chosen file to another group (allows to view multiple files simultaneously).

Coding Shortcuts

These shortcuts enable faster creation and modification time of coding your files.

  • Ctrl + Space – opens IntelliSense, usually used to view your coding options. E.g.:

AL

 

  • Ctrl + Shift + Space – used to view tooltips for symbols. E.g.:

AL

 

  • Ctrl + / – Linearly comments out selected text block.  E.g.:

AL

 

  • Alt + Shift + A – Comments out selected text in a block way. E.g.:

AL

 

  • Ctrl + Enter – Inserts new line below cursor.
  • Ctrl + Shift + Enter – Inserts new line above cursor.
  • Alt + Up/Down arrow – Moves selected lines up / down.
  • Alt + Shift + Up/Down – Copies selected lines up / down.

 

Editor Control shortcuts

These shortcuts are for the editor and editor group controls. Editor group allows viewing several editors simultaneously, like in the picture below.

AL

 

  • Ctrl + PageUp/Pagedown – Open previous/next editor.
  • Alt + LeftArrow/RightArrow – Opens last/next editor you used.
  • Ctrl + Shift + T – Opens recently closed Editor.
  • Ctrl + Alt + Left/Right Move Editor into previous/next group. Groups allow you to view a few editors at the same time.
  • Double mouse click – When double-clicking on an editor, it leaves the editor open even after opening another one.
  • Ctrl + F4 – Closes the selected Editor.
  • Ctrl + [1-9] – Focus [1-9] editor group.
  • Ctrl + K then Ctrl + W – Close all Editors.
  • Ctrl + K + W – Close all Editors in the selected group.

 

Searching Shortcuts

Searching shortcuts enable accessing search faster. There are two types of searches: Local search within the opened file and global search to search throughout the entire solution.

  • Ctrl + F – Local search.
  • F3 / Shift + F3 – Previous search.
  • Ctrl + Shift + F – Global search.
  • Up/Down – Search history (Enable by clicking on the search window).

 

Multi cursor editing

Multi cursor editing is proper when you want to write/delete code in several places simultaneously. This section will provide you with some useful multi cursor editing shortcuts.

  • Alt + Click – Add another cursor to a place of code you click.
  • Ctrl + Alt + UpArrow/DownArrow – Add another cursor above/bellow.
  • Ctrl + Alt + Shift + Arrows – allows you to select text on all cursors.
  • Ctrl + D – Add cursor to similar occurrence in the file. E.g.:

ALAL

 

After using Ctrl + D you can use Ctrl + U to Undo the cursor and Esc to clear selection.

  • Ctrl + F2 – Selects all occurrences of a string in the current file.
  • F2 –Renames all currently marked entity references in the whole solution. Press F2 on the symbol, then enter a new Name. Shift + enter to preview changes and apply them to change entity references. E.g.:

AL

 

It’s important to know that you can customize and see commands and their Keybindings by pressing Ctrl + K and then Ctrl + S. You are provided with a window seen in the picture below.

Visual Studio Code Shortcuts Customization Page

Visual Studio Code Shortcuts Customization Page

 

 

2. Snippets

 

Snippet – is a template designed to facilitate the insertion of repetitive code. It’s a good practice to automate the insertion of repetitive code. Examples include creating snippets for loops, conditional statements, and more. To add a snippet, select File> Preferences> User Snippets and then choose to create a new Global or Local Snippets file.

Here is an example of our code documentation snippet:

AL

 

“prefix” – the prefix to use when selecting the snippet in intellisense

“body” – the snippet content. Use $1, ${1:defaultText} to define cursor positions, use $0 for the final cursor position; insert variable values with ${varName} and ${varName:defaultText}

“description” – the snippet description

“scope” – a list of language names applies to this snippet

Results:

If you press ctrl + space and scroll through choices, you will see suffixes for those snippets.

AL

 

After choosing them, you get these results:

AL

AL

 

 

3. Visual Studio Code useful extensions

 

Many useful VS code extensions are available, which can help programmers code more efficiently. There is AL Extension Pack is full of valuable extensions for AL programming. Here is the list of a few extensions that make programming easier.

  • Error Lens (Improves highlighting of errors, warnings, and other language diagnostics).

AL

 

  • Docs View (Automatically displays documentation for the symbol at the current cursor position).

AL

 

  • Git Lens (Helps to understand code better. Quickly glimpse into whom, why, and when a line or code block was changed. Jump back through history to gain further insights into how and why the code evolved). It also adds additional options in the source control window, like the picture below.

AL

 

  • Git History (Allows to view git log, file history, compare branches or commits). Just open the file you want to view, then press F1 to write Git: View File History, then press enter, and you will be able to view the Git History of the file.

 


 

In conclusion, these are my favorite and most helpful tips and tricks while coding with AL programming language in VS Code. I hope they will help improve your daily programming efficiency and overall experience.