Obsidian works with Vim Mode to enhance Chinese writing experience

Matrix homepage recommendation

Matrix is ​​a minority writing community. We advocate sharing real product experience, experience and thinking with practical value. From time to time, we will select the highest-quality articles from Matrix to show the most authentic experiences and opinions from users.

The article represents the author’s personal point of view, and the minority only makes minor changes to the title and layout.


In the past six months, I have seriously experienced the software Obsidian (obsidian). After using it for a period of time, I decisively unsubscribed from Ulysses and migrated all the documents to Obsidian. Due to the openness of its platform, Obsidian’s positioning is not only a note-taking software, but also a PKM tool.

There are countless articles and videos about the use of Obsidian. By reading these excellent experience sharing, I can quickly master the skills of using Obsidian. I saw an article ” VIM Mode – Quality of Life Improvements ” in the Obsidian official forum before, which introduced how to use Vim Mode efficiently in Obsidian, and one of the most important points that Obsidian attracted me is to support Vim Mode. I have been using Vim Mode in various IDEs in the past, and I am familiar with the operating habits and convenience of Vim Mode. I still remember that I used Haroopad for a while in the Markdown note-taking software that supports Vim Mode, but unfortunately the software has not been updated for a long time. Obsidian After more than 2 years of iterations and various Vim Mode peripheral plug-in support, the currently supported Vim Mode capabilities have been able to meet my daily note-taking and writing needs. This article summarizes how I currently configure and use Vim Mode in Obsidian and Improve its peripheral plug-ins.

Vim Mode peripheral plug-ins and configuration

1. Vimrc Support

If you want to use Vim Mode in depth, you must use the Vimrc Support plug-in, and cooperate with the custom .obsidian.vimrc file to achieve rich Vim Mode keyboard mapping management. After various explorations, my own configuration file is currently as follows: .obsidian.vimrc , and then expand to introduce the specific configuration inside.

Jump cursor by line

 " Have j and k navigate visual lines rather than logical ones nmap j gj nmap k gk " I like using H and L for beginning/end of line nmap H ^ nmap L $ " nmap J 5j " nmap K 5k

Jump cursor by paragraph

 " Moving to next/prev paragraph nmap [ { nmap ] }

Press Heading to jump cursor

 " Moving to next/prev heading exmap nextHeading jsfile .obsidian.markdown-helper.js {jumpHeading(true)} exmap prevHeading jsfile .obsidian.markdown-helper.js {jumpHeading(false)} nmap g] :nextHeading nmap g[ :prevHeading

Press Tab to jump cursor

 " Emulate Tab Switching https://vimhelp.org/tabpage.txt.html#gt " requires Pane Relief: https://github.com/pjeby/pane-relief exmap tabnext obcommand pane-relief:go-next nmap gt :tabnext exmap tabprev obcommand pane-relief:go-prev nmap gT :tabprev " Same as CMD+\ nmap g\ :tabnext

The cursor jumps to the last edited position

Another commonly used function is to quickly return the cursor to the last edited position. In the Obsidian official forum, some users also asked for ” Hotkey jump to previous caret position “, and found a very clever implementation, nmap g; u<Cr> , The limitation is that you can only go back one step, and it will fail after the Editing/Preview mode is switched. In addition, Vim Mode has built-in support for gi to jump to the last edited position and switch to insert mode.

zz keyboard mapping screen move position to 70%

By default, the zz keymap will move the current line of the document to the middle of the screen, but I am used to moving the current editing line to the upper position on the screen, and I can adjust the position of the zz screen slightly in combination with jsfile.

 exmap scrollToCenterTop70p jsfile .obsidian.markdown-helper.js {scrollToCursor(0.7)} nmap zz :scrollToCenterTop70p

Surround Text with surround

The Vimrc Support plug-in supports the surround feature. Further matching with the Admonition and code block from selections plug-ins, the admonition block can be directly created through the sa{x} command no matter in normal mode or visual mode.

 " Surround Admonition " https://github.com/esm7/obsidian-vimrc-support/discussions/146 exmap CodeBlockAdmonitionNote obcommand code-block-from-selection:17f30753-d5f4-4953-abed-5027a25ede58 map san :CodeBlockAdmonitionNote exmap CodeBlockSelectionAdmonitionNote jscommand { editor.setSelections([selection]); this.app.commands.commands['code-block-from-selection:17f30753-d5f4-4953-abed-5027a25ede58'].callback() } vmap san :CodeBlockSelectionAdmonitionNote

bf1e80938c7aee397571278a6b753dd1.gif Keymap san Create Admonition Block directly

With the Zoom plug-in, press Heading to perform Zoom In and Zoom Out

 " Zoom in/out exmap zoomIn obcommand obsidian-zoom:zoom-in exmap zoomOut obcommand obsidian-zoom:zoom-out nmap zi :zoomIn nmap zo :zoomOut nmap &a :zoomOut nmap &b :nextHeading nmap &c :zoomIn nmap &d :prevHeading nmap z] &a&b&c nmap z[ &a&d&c

24d8939ae33e42cbc2a61a80b937d11e.gif Keymap zi Press Heading for Zoom In

With the Stille plug-in, switch the Focus mode

 exmap toggleStille obcommand obsidian-stille:toggleStille nmap zs :toggleStille nmap ,s :toggleStille

922096645abad05f01ccd7c10b4164e7.gif Keymap zs switch to Focus mode

Open the .obsidiain.vimrc configuration file directly in the specified IDE

During the development process, the .obsidian.vimrc configuration file needs to be edited frequently. In order to quickly open the configuration file in Sublime Text, I found a workaround method, using the Shell commands plug-in configuration to register a command line /usr/local/bin/subl /.obsidian.vimrc command, you can directly evoke Sublime Text and open the .obsidian.vimrc file through the command.

1

Vim Mode status bar displays abnormal bugfix

The 0.8.0 version of the Vimrc Support plugin has a problem that Vim Mode displays abnormally in the status bar after opening a new file. I submitted the first PR , and this bug was fixed in the latest version 0.9.0, and the Fixed Normal Mode Layout was also fixed incidentally. Features. After submitting the PR, I also started to try to answer some issues on GitHub.

2. Obsidian Vim Reading View Navigation

This plug-in implements cursor jump commands such as j/k/gg/G in Preview mode, but this plug-in has not been released to the Community plugins market and can only be installed manually. obsidian-vim-reading-view-navigation Allows navigating Obsidian’s Reading View with j, k, gg and G

3. Obsidian Vim Yank Highlighter

Highlight the yy copy line, which is also not released to the Community plugins market, and can only be installed manually. obsidian-vim-yank-highlight Highlights the current yank

Chinese editing experience optimization

The support for Chinese in common Vim Mode implementations is generally very poor. The article ” Vim’s Chinese support and solutions ” summarizes the problems and solutions for Chinese editing in Vim. Thanks to the openness of Obsidian’s plug-ins, it is possible to optimize the Chinese editing experience.

1. Automatic switching between Chinese and English input methods

When using Vim Mode to write in Chinese, the first bottleneck problem encountered is the switching of Chinese and English input methods. When switching to insert mode, it automatically switches to Chinese input method, and returns to normal mode to automatically switch to English input method. Currently, there is already a plug-in obsidian-vim-im-switch-plugin that implements this function, which needs to be used with the command line tool fcitx-remote-for-osx . I directly modified the source file main.m, replaced the default input method configuration (com.apple.keylayout.ABC and im.rime.inputmethod.Squirrel.Rime), and recompiled and installed it to use. However, there are bugs in this plug-in, and there are often problems with switching failures. A PR repair has been proposed, and it has not yet been merged into the trunk to release a new version.

178ea1cf7aa6e2a958289737949ed282.gif Insert/normal mode switching and input method switching are synchronized

2. Jump cursor according to Chinese word segmentation

Another bottleneck problem encountered during the use of Vim Mode is that the logic of Chinese word segmentation is different from that of English. The article ” Vim Chinese Support and Solution Ideas ” describes three possible solutions in detail. After searching in the Community plugins market, there is no ready-made solution, but I found that there is a plugin cm-chs-patch that realizes the functions of Chinese word segmentation and double-click selection, so it took a little time to implement Vim Mode on this basis. The ability to jump the cursor by Chinese word segmentation ( support Vim mode by jiyee · Pull Request 19 ). The latest version 1.10.0 already supports jump cursor by Chinese word segmentation. However, because the internal implementation of vim.js built in Obsidian cannot be directly modified, we can only fork the internal implementation of vim.js. Fortunately, the relevant implementation is a relatively stable part, and there should not be too much difficulty in subsequent upgrades and adaptations. .

ea13e099300da2ab2ad7377ad19209f9.gif Jump cursor according to Chinese word segmentation

3. Jump cursor according to Chinese punctuation

In addition, in the process of Chinese editing, it is often necessary to jump or edit according to sentence breaks. The development supports f<charactor> and t<charactor> keyboard mapping to input English punctuation and jump to the corresponding Chinese punctuation. f, will jump to the next one , or , I think this feature is quite practical, and the sentence granularity is completed between the word segmentation granularity and the paragraph granularity. Because the implementation is similar, it was also submitted to the cm-chs-patch plugin, but I think it is not the most appropriate to put it in this plugin, but it was brought together when the PR was raised.

cb8ba042a326c7fc843089c572344700.gif In the state of English input method, enter English punctuation and jump to the corresponding Chinese punctuation

Custom plugin development

In addition, according to my own habits in daily use, some features are not well supported. I am working on developing an Obsidian-VimEx plugin, which currently includes the following features:

File Rename Modal

Previously, the gr and <Cw>r keyboards were mapped to the file renaming function. After enabling the “Show inline title” option, the default Rename file behavior will be to jump to the title block at the head of the document, and the title text is all selected State, because title modification is a high-frequency behavior, a simple file renaming popup is implemented to ensure that the file renaming action will not interfere with the existing editing state.

 " rename file modal exmap renameFile obcommand Obsidian-VimEx:file-rename-modal nmap gr :renameFile

b41536059a4507008493203452b476c3.gif keymap gr file rename popup

Mark mark

I have rarely used the Mark function in Vim Mode before, the main reason is that I often forget the mark name of Mark. It would be much more convenient to jump back and forth across paragraphs if you could directly visualize the Mark tag name in the editor or have a list of Mark tag names. What has been implemented so far is that adding a custom Mark tag name to the right of the line number will link the m{x} keymap.

a9307292a158f8492b7e41ea9f4d44bf.gif Keymap m{x} Synchronously display the tag name

.obsidian.vimrc Visual configuration (planned)

In the process of configuring .obsidian.vimrc, I found that it is inconvenient to find a suitable reference configuration. The only way is to search through GitHub or forums. It will be more convenient if you can visualize the configuration, list all the features, directly configure the instructions, and even share the configuration with the community. This may be added as a feature in a plugin.


Finally, if there are other feature requirements or suggestions, please leave a message or raise an issue to improve the Obsidian + Vim Mode experience together.

related reading

> Download the Minority 2.0 client , follow the Minority official account, and unlock a new reading experience ?

> Practical and easy-to-use genuine software , presented to you by the minority ?

This article is transferred from: https://sspai.com/post/78030
This site is only for collection, and the copyright belongs to the original author.