1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

「How to Do 90% of What Plugins Do (With Just Vim)」

1
Posted at

きっかけ

Vim Advent Calendarを見ていたら、ryicohさんのhttps://zenn.dev/vim_jp/articles/vim_noplugin の記事をお見かけして、私もhttps://www.youtube.com/watch?v=XA2WjJbmmoM 見てみたくなった。
(vimができることはvimにやらせたいと前から思っていた)

概要

上記動画を見ながら、個人的に重要だったことをメモする。

内容

BASIC SETUP

vimrcを書くときにいつも言われてはいたが、今になって動画で見るとそういうことかと気づく。

" BASIC SETUP:

" enter the current millenium
set nocompatible

" enable syntax and plugins (for netrw)
syntax enable
filetype plugin on

FINDING FILES

pathオプションとか使ったことなかった。

" FINDING FILES:

" Search down into subfolders
" Provides tab-completion for all file-related tasks
set path+=**

wildmenuは知っている。

:find ファイル名 で探し出してきてくれる。
:b fooでfooが部分的にでもマッチするファイル名のバッファーを開いてくれる(!)。もし唯一にならなければTab補完可能。

(:findはpathの中を探してくれて、:bはバッファー内を探してくれるイメージか)

:echo expand("%")

ここではしゃぐ。
expand面白いですよね、同意します。

TAG JUMPING

毎回、一度外に出てctagsしていたけれど、確かにこれで良いか。

" TAG JUMPING:

" Create the `tags` file (may need to install ctags first)
command! MakeTags !ctags -R .

" NOW WE CAN:
" - Use ^] to jump to tag under the cursor
" - Use g^] for ambiguous tags
' - Use ^t to jump back up the tag stack

(ちなみに、ctagsは--languages=pythonとすればPythonも使えるが、もしかしてデフォルトでやってくれる?)
(デフォルトでやってくれるんだ!!)

AUTOCOMPLETE

^x^f, ^n, ^pは使ったことはあったけれど、なるほど、^x^nを使えば現在のファイルのみに限定することができるのか。。

" AUTOCOMPLETE:

" HIGHLIGHTS:
" - ^x^n for JUST this file
" - ^x^f for filenames (works with our path trick!)
" - ^x^] for tags only
" - ^n for anything specified by the 'complete' option

https://vimhelp.org/insert.txt.html#ins-completion あ、なるほど

insert.txt
1. Whole lines                                          i_CTRL-X_CTRL-L
2. keywords in the current file                         i_CTRL-X_CTRL-N
3. keywords in 'dictionary'                             i_CTRL-X_CTRL-K
4. keywords in 'thesaurus', thesaurus-style             i_CTRL-X_CTRL-T
5. keywords in the current and included files           i_CTRL-X_CTRL-I
6. tags                                                 i_CTRL-X_CTRL-]
7. file names                                           i_CTRL-X_CTRL-F
8. definitions or macros                                i_CTRL-X_CTRL-D
9. Vim command-line                                     i_CTRL-X_CTRL-V
10. User defined completion                             i_CTRL-X_CTRL-U
11. omni completion                                     i_CTRL-X_CTRL-O
12. Spelling suggestions                                i_CTRL-X_s
13. keywords in 'complete'                              i_CTRL-N i_CTRL-P

FILE BROWSING

こうすればよかったのか。。すごい。

" FILE BROWSING:

" Tweaks for browsing
let g:netrw_banner=0           " disable annoying banner
let g:netrw_browse_split=4     " open in prior window
let g:netrw_altv=1             " open splits to the right
let g:netrw_liststyle=3        " tree view
let g:netrw_list_hide=netrw_gitignore#Hide()
let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+'

ここに使えるマップ書いてあったのか。
https://vimhelp.org/pi_netrw.txt.html#netrw-browse-maps

only

:only現在のwindowだけにする
:tabonly現在のタブだけにする

そういえば使ってなかったな。(そもそもTabはなんとなく使っていなかったけれど)

template

:0r ファイル名とかはよくやっていたけれど、こういうやり方もあるか。入力するだけでなくそのまま行きたい場所まで行けるのは確かにすごいメリットか。
,自体が消えるのは少しやりにくいけれど(;の逆)、バランスの問題か。

" Read an empty HTML template and move cursor to title
nnoremap ,html :-1read $HOME/.vim/.skeleton.html<CR>3jwf>a

BUILD INTEGRATION

私はrubyは滅多に使わないので、ニュアンスだけ。
set makeprg=:makeで走るプログラムを指定できる。
:cl to list errors
:cc# to jump to error by number
:cn and :cp to navigate forward and backward

いまだにPythonでmakeとquickfixを使う方法を知らないのはよくないよなあ。。
pluginなしでできないかなあ。

helpgrep

:helpgrep して、:cn, :cpはすごい便利!!
人生変わった。

感想

netrwとquickfix使いこなしたいなあ

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?