Home

Awesome

Gkeep.nvim

[!CAUTION] I no longer use Google Keep for notes. The lack of an official API has finally caused me enough pain that I am retiring this plugin.

Neovim integration for Google Keep, built using gkeepapi

Screenshot from 2021-07-30 16-25-39

Requirements

Table of Contents

Installation

gkeep supports all the usual plugin managers

<details> <summary>lazy.nvim</summary>
{
  'stevearc/gkeep.nvim',
  build = "UpdateRemotePlugins",
  opts = {},
  -- Optional dependencies
  dependencies = { "nvim-tree/nvim-web-devicons" },
}
</details> <details> <summary>Packer</summary>
require('packer').startup(function()
    use {'stevearc/gkeep.nvim', run = ':UpdateRemotePlugins'}
end)
</details> <details> <summary>Paq</summary>
require "paq" {
    {'stevearc/gkeep.nvim', run = vim.fn['remote#host#UpdateRemotePlugins']};
}
</details> <details> <summary>vim-plug</summary>
Plug 'stevearc/gkeep.nvim', { 'do': ':UpdateRemotePlugins' }
</details> <details> <summary>dein</summary>
call dein#add('stevearc/gkeep.nvim')
</details> <details> <summary>Pathogen</summary>
git clone --depth=1 https://github.com/stevearc/gkeep.nvim.git ~/.vim/bundle/
</details> <details> <summary>Neovim native package</summary>
git clone --depth=1 https://github.com/stevearc/gkeep.nvim.git \
  "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/pack/gkeep/start/gkeep.nvim
</details>

Post-install, you will need to run :UpdateRemotePlugins if your installer hasn't done so automatically.

gkeep.nvim also depends on the gkeepapi and keyring python libraries. It will attempt to install those automatically, but if it fails you will need to find the python3 executable that neovim is using (if you're not sure, run :checkhealth provider) and run python3 -m pip install gkeepapi keyring. If you are NOT using python 3.8+, you will also need to pip install typing-extensions.

Run :checkhealth gkeep to confirm everything is set up properly

A note about keyring:
Keyring is required to store your Google auth token securely. In most cases it will work automatically, but if you see an error in your :checkhealth output, you may need to fiddle with the setup. See the keyring repo for details about the supported backends. Take note of the special instructions for running on headless systems or in a docker container if it applies to you. If you absolutely cannot get any of the supported backends working, you can pip install keyrings.alt to use an insecure backend, though this has negative security implications.

Setup

No configuration is necessary to get started, simply run :GkeepLogin. It will prompt you for an email and password (if you use 2-factor, you will need to provide an app password).

The API master token is stored using keyring so you don't have to enter your password again. To remove the stored credentials from your system, run :GkeepLogout.

Commands

CommandArgsDescription
:GkeepLogin[{email}]Login to Google Keep
:GkeepLogoutLog out and clear stored credentials
:GkeepOpen[right/left]Open the gkeep windows
:GkeepEnter[menu/list], [right/left]Open and enter the gkeep windows
:GkeepCloseClose the gkeep windows
:GkeepToggle[right/left]Open or close the gkeep windows
:GkeepNew[note/list/neorg], [{title}]Create a new note
:GkeepSyncSync changes with the server
:GkeepRefreshForce fetch latest notes from server
:GkeepGotoOpen the note link under the cursor (see links)
:GkeepBrowseOpen the note in your web browser
:GkeepPopupOpen a float window for the current note to perform edits (e.g. pin/archive/delete)
:GkeepYankCopy a document link to the current note (see links)
:GkeepUpdateLinksUpdates links in the note to match their titles
:GkeepCheckToggle the checkbox of the item under cursor (see list notes)
:GkeepSortCheckedSorts completed items to the bottom of the list
:GkeepClearCheckedDeletes completed items from the list

Additionally, there is the function GkeepStatus() which returns the current status message (usually about syncing notes). This can be used in your statusline if desired.

Configuration

Set the following global variables to configure gkeep.

VariableTypeDefaultDescription
g:gkeep_sync_dirstringnullThe directory to sync notes into (see file sync below)
g:gkeep_sync_archivedboolfalseIf true, will sync archived notes as well
g:gkeep_nerd_fontbooltrueWhen true, will use icons from your patched font
g:gkeep_iconsdictSee config.pyOverride the icons used
g:gkeep_widthint32Set the width of the sidebar
g:gkeep_log_levelsdict{'gkeep': 'warning', 'gkeepapi': 'warning'}Python log levels. See logging levels for a list of levels

Note that these variables must be set before gkeep is loaded in order for them to take effect.

Features

Menu

Screenshot from 2021-07-30 16-19-20

The Menu is the top window that displays your labels and searches. Use ? to view all the keymaps available. The main features include:

Note list

Screenshot from 2021-07-30 16-22-56

The Note list is the bottom window that displays the notes that match the currently-selected menu item (label, search, etc). Use ? to view all the keymaps available. The main features include:

Note editing

Notes will have the title, id, and labels at the top like so:

# My note

id: 1626733972853.1206798729
labels: First label, Another label

To change the note title, simply edit the file and :w. The same goes for labels. If the note doesn't have any labels yet, manually add the labels: line and they will be picked up when you save. Do not change the id: line.

There is an omnicomplete function (<C-x><C-o>) that will complete the labels for you

Note: if you are using file sync, renaming files will not rename the note. Changing the note title will rename the file.

Lists

Google Keep has a special type of note to represent lists, and gkeep customizes the editing environment heavily to enforce the proper format. You may wish to bind :GkeepCheck to a convenient keymap.

https://user-images.githubusercontent.com/506791/127721475-6bf500ac-e5e6-49b4-9886-1ece02cfead8.mp4

Links

You can embed links to other notes within a note. The format for a link is [visible text](note_id). You can quickly get a link to a note using the :GkeepYank command. To jump to a link under your cursor, use the :GkeepGoto command (bound to gf by default).

You can also use the ephemeral url format for links if you like (e.g. gkeep://{id}/{visible_text})

https://user-images.githubusercontent.com/506791/127722474-3157ef5c-3413-4675-992c-d317ed68ca48.mp4

Search

Searching notes is done from the Menu. Pressing / in the menu will pop open the search prompt. As you type, the Note list should live-update to show the search results.

https://user-images.githubusercontent.com/506791/127722820-b0c74d89-e844-4dc2-b81b-4917f22dd579.mp4

The search is case-insensitive, and will look for matches in the note title and text. Matching is exact, not fuzzy.

Flags

There is a special syntax to let you filter notes by type. Notes can be [p]inned, [a]rchived, or [t]rashed. You can use the following flags to specify the desired behavior:

╭─────────────╮
│🔍 -p        │  // Exclude pinned notes from the search
╰─────────────╯
╭─────────────╮
│🔍 =a        │  // Only search archived notes
╰─────────────╯
╭─────────────╮
│🔍 +at       │  // Search all notes, including archived and trashed
╰─────────────╯

The default query functions like -at, to filter out archived and trashed notes.

Flags can be added to any part of the query. Gkeep will search for any text that is not the flag.

╭─────────────╮
│🔍 +a vim +t │  // Search all notes (including archived and trashed) for 'vim'
╰─────────────╯

Labels and colors

You can search for notes with a specific label or color by using label:<label> and color:<color>. This can be abbreviated as l:<label> and c:<color>. To specify multiple labels or colors, separate them with a comma.

╭────────────────────────╮
│🔍 l:software,journal   │  // Search notes with either label
╰────────────────────────╯
╭────────────────────────╮
│🔍 c:red,blue           │  // Search red and blue notes
╰────────────────────────╯

If your label has whitespace or special characters, you can quote it. Note that you cannot comma-separate quoted labels, so to search multiple you will need to provide label: multiple times.

╭──────────────────────────────────────────╮
│🔍 l:"journal entries" l:"project ideas"  │
╰──────────────────────────────────────────╯

You do not need to specify the entire label in a query, only a unique prefix. For example, if you have the labels software, vim, and journal, you could search for the software label with l:s, since no other labels start with "s".

Examples

Some more query examples:

Ephemeral notes

The default operation for gkeep is to not save your files to disk. The note data will be cached locally in a json file (under neovim's cache directory), but no note files will exist directly. Notes are accessed by using a buffer name that looks like gkeep://{id}/{title}.keep. These buffers can be edited and saved like a normal file, and they will sync those changes to Google Keep.

File sync

If you set let g:gkeep_sync_dir = '~/notes' gkeep will write all your notes to that directory and attempt to keep them in sync. It will also scan that directory for new files and create notes in Google Keep for them. Note files must use the .keep extension to be detected (or .norg if using Neorg).

Merge conflicts

If the Google Keep servers and your local files disagree about the content of a note, the file on your computer will be renamed to <filename>.local and the original file will be updated to the server latest. When a .local file is present, the note will appear with a red "merge" icon in the list:

Screenshot from 2021-07-30 16-23-58

If you open the note, it will open in a vimdiff split. Resolve the merge conflict and then delete the .local file to get back to a good state.

Changing files outside of vim

You can make edits to the synced note files outside of vim, and the changes will be picked up and synced the next time you open vim (and start gkeep). To protect you from data loss, when gkeep detects changes that are made from outside of vim, a backup of the note will be made in Google Keep before uploading those changes. Backups will appear in your Trash (and thus will be deleted after 7 days), and will have [Backup] in the title.

Third-party integrations

Telescope

If you have telescope installed, you can use it to search and select your notes. There are two pickers that you can use:

Additionally, each of these pickers can be configured to use a different type of search. The two options are:

require("telescope").setup({
  -- You can optionally configure the search method for each of the pickers.
  -- Below are the default values.
  extensions = {
    gkeep = {
      find_method = "all_text",
      link_method = "title",
    },
  },
})
-- Load the extension
require('telescope').load_extension('gkeep')

Neorg

If you have neorg installed, gkeep will automatically enable support for it (check that it's working with :checkhealth gkeep). You will then be able to use the note list to create Neorg notes or change existing notes to be Neorg notes. Gkeep will interact minimally with the @document.meta tag, but otherwise it will simply function as a storage backend for your notes.

@document.meta
gkeep cares about three entries in the document meta:

Changing the title: and categories: will edit the note title and labels, just like for a normal note.

Highlight

The following highlight groups can be overridden

GroupDescription
GkeepStatusThe status string in the upper right of the menu
GKeepRedThe color of Red note icons
GKeepOrangeThe color of Orange note icons
GKeepYellowThe color of Yellow note icons
GKeepGreenThe color of Green note icons
GKeepTealThe color of Teal note icons
GKeepBlueThe color of Blue note icons
GKeepDarkBlueThe color of DarkBlue note icons
GKeepPurpleThe color of Purple note icons
GKeepPinkThe color of Pink note icons
GKeepBrownThe color of Brown note icons
GKeepGrayThe color of Gray note icons

FAQ

Q: Why Google Keep?

It has a good mobile UI. I like editing notes in vim on my desktop, but I also want to be able to access them on my phone.

Q: Why not use the official Google Keep API?

Google has recently released an official API for Google Keep. Since gkeep.nvim has roughly two different modes of operation, let's evaluate it for each:

If the API gets updated in the future to better support one or both of these workflows, I'll consider migrating to it.

Q: What Google Keep features are not supported?

These are Google Keep features that are currently unsupported by gkeep.

Troubleshooting

Trouble logging in

Symptom: When you try to :GkeepLogin a browser window is opened and hangs on "one moment please...".

Action: You are probably trying to log in with a password instead of an app password. Create an app password and use that instead. See #7 for details.