nvim 으로 python 코드를 작성하다가 format string 형식에 syntax highlighting 이 제대로 되지 않는 현상을 겪었다. string 안에 넣은 {} 는 string 이 아닌 코드로서 하이라이팅이 되어야하는데, 일반 string처럼 보이고 있었다.
print(f"n! = {result}")
서치해보니, vim 의 python syntax 설정을 일부 변경 해줘야 한다는데.. 많은 사람들이 Treesitter 를 사용 하라고 말 하고 있었다.
Tree-sitter|Introduction
tree-sitter.github.io
https://github.com/nvim-treesitter/nvim-treesitter
GitHub - nvim-treesitter/nvim-treesitter: Nvim Treesitter configurations and abstraction layer
Nvim Treesitter configurations and abstraction layer - GitHub - nvim-treesitter/nvim-treesitter: Nvim Treesitter configurations and abstraction layer
github.com
Treesitter - Neovim docs
Treesitter Nvim :help pages, generated from source using the tree-sitter-vimdoc parser. Treesitter integration WARNING: Treesitter support is still experimental and subject to frequent changes. This documentation may also not fully reflect the latest chang
neovim.io
Treesitter는 파서 생성 도구이자 증분 파싱 라이브러리로서 다음과 같은 목표를 가진다고 한다.
- 모든 프로그래밍 언어를 구문 분석할 수 있을 정도로 일반적이다.
- 텍스트 편집기의 모든 키 입력을 구문 분석할 수 있을 정도로 빠르다.
- 구문 오류가 있는 경우에도 유용한 결과를 제공할 수 있을 정도로 강력하다.
- (순수 C로 작성된) 런타임 라이브러리가 모든 응용 프로그램에 포함될 수 있도록 종속성이 없다.
Treesitter의 능력을 얼마나 느껴볼 수 있을 지 모르겠지만, 일단 사용 해보는게 이득이라 판단하고 우선 써보면서 느끼고 익혀보자는 마음으로 설치했다.
Installation
vim-plug 로 설치
~/.config/nvim/init.vim
call plug#begin('/.vim/plugged')
...
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
...
call plug#end()
"enable treesitter"
lua require('config/treesitter')
:PlugInstall command 로 설치
github treesitter repo의 README 참조, treesitter 설정
~/.config/nvim/lua/config/treesitter.lua
require'nvim-treesitter.configs'.setup {
-- A list of parser names, or "all" (the five listed parsers should always be installed)
ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "python" },
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
}
이후에 nvim에서 :checkhealth command로 현재 설치된 플러그인들과 설정이 잘 되어있는지, 정상 동작하는 상태인지 확인할 수 있고 에러가 있을 경우 어느정도 해결책도 알려준다.
이렇게 설정 하고 나니 비로소 format string의 highlighting이 적용되었다. 편안..
'utils' 카테고리의 다른 글
Vim 에 대한 간단한 소개와 사용법, 숙달하기 위한 연습방법 (1) | 2024.12.08 |
---|---|
fuzzy finder + ripgrep (0) | 2024.01.17 |
Vimspector (neovim으로 디버깅 하기) (1) | 2023.12.28 |
lazygit (1) | 2023.12.21 |
Neovim (0) | 2023.12.19 |